Redis & Caching (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What are the common Caching Patterns: Cache-Aside vs Write-Through vs Write-Behind?
junior LevelMost AskedSystem Design
In Simple Words:
- Cache-Aside (Lazy Loading - Most Common):
- Application checks Redis. If hit -> return data.
- If miss -> read from PostgreSQL/MySQL, store in Redis with TTL, return data.
- Write-Through: Application writes data to the cache, and the cache synchronously writes to the database before acknowledging success. High consistency, higher write latency.
- Write-Behind (Write-Back): Application writes data only to Redis. An asynchronous worker batches writes and commits them to the database later. Blazing fast, but risk of data loss if Redis crashes before flushing.