Algocraft
/
System Design
/
Caching
← All Designs
⚡
Caching
Dramatically reduce latency by storing frequently accessed data in fast memory
Low Latency
Read Scaling
Redis / Memcached
CDN
Cache Tier Simulation
● Stopped
💻
Client
Last Key
—
⚡ Cache (RAM)
0
/
8
1ms access time
🗄️
Database
100ms access time
Queries
0
Idle
RECENT REQUESTS
0
Total Requests
0
Evictions
0ms
Avg Latency
0ms
Time Saved
Key Concepts
🎯 When to Use
Read-heavy workloads (>80% reads)
Expensive DB queries that repeat
Session data and user profiles
Static assets and computed results
⚖️ Trade-offs
Cache invalidation is hard
Stale data if TTL too long
Cache stampede on cold start
Memory is expensive vs disk
🎓 Interview Tips
Write-through vs write-back vs write-around
Cache stampede: probabilistic expiry, locks
L1/L2/L3 CPU cache = same concept
CDN is a cache at the network edge