ReviseAlgo Logo
Intermediate10 min readPerformance & Scaling

Cache Fundamentals

Storing frequently accessed lookup results in memory blocks (RAM) to bypass slow disks.

What you'll learn

  • Cache Aside (Lazy Loading)
  • Write Through
  • Write Behind (Write Back)
  • Cache Eviction

TL;DR

Storing frequently accessed lookup results in memory blocks (RAM) to bypass slow disks.

Visual System Topology

Cache Aside Pattern

App Client
1. Query Cache: Return instantly if present (Cache Hit).
2. Query DB: If not in cache (Cache Miss), fetch from DB & sync.
Redis Cache (RAM)
PostgreSQL (Disk)

Concept Overview

Caching stores frequently accessed data in fast storage (usually memory) to avoid expensive operations like database queries or API calls. It's one of the most effective ways to improve performance and reduce load.

Different caching strategies (Cache Aside, Write Through, Write Behind) offer different trade-offs between consistency and performance.

Key Architectural Pillars

1

Cache Aside (Lazy Loading)

Application checks cache first. On miss, loads from database and updates cache. Most common pattern.

2

Write Through

Write to cache and database simultaneously. Slower writes but cache always up-to-date.

3

Write Behind (Write Back)

Write to cache immediately, database asynchronously. Fast writes but risk of data loss.

4

Cache Eviction

How to remove items when cache is full: LRU (Least Recently Used), LFU (Least Frequently Used), TTL (Time To Live).

AI Tutor

Ask about the topic

Sign in Required

Please sign in to use the AI tutor

Sign In
Cache Fundamentals - Module 4: Performance & Scaling | System Design | Revise Algo