System Design: Caching Strategies
August 20, 2025
1 min read
0 views
There are only two hard things in Computer Science: Cache Invalidation and naming things.
Cache-Aside (Lazy Loading)
- App asks Cache for Key X.
- Cache says "Miss".
- App asks Database.
- App writes result to Cache.
- App returns result.
Pros: Only caches what is needed. Cons: Initial latency (Cache Miss).
Write-Through
- App writes to Cache AND Database at the same time.
Pros: Cache is always fresh. Cons: Slow writes.
TTL (Time To Live)
When do you delete the cache? Set a TTL (e.g., 5 minutes). After 5 minutes, Redis deletes it automatically. This leads to "Eventually Consistent" data.
Conclusion
Start with Cache-Aside + TTL. It solves 90% of performance problems.
Similar Posts
Security: JWT vs Sessions
Oct 22, 2025
API Design: Idempotency
May 07, 2025
System Design: Load Balancers
Mar 28, 2025