Redis & Caching (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
Caching Strategies: Cache-Aside vs Write-Through vs Write-Behind.
senior LevelMost AskedSystem Design
In Simple Words:
- Cache-Aside (Lazy Loading): Application reads from Redis. On cache miss, it reads from DB, updates Redis, and returns. Simple and resilient.
- Write-Through: Application writes data to Redis; the cache synchronous layer writes to the database immediately before confirming. Guarantees consistency, but adds write latency.
- Write-Behind (Write-Back): Application writes to Redis immediately; an asynchronous background worker flushes batched writes to the DB. Maximum write performance, but risk of data loss if Redis crashes before flushing.