What is the cache-aside pattern vs write-through caching?
Answer
Cache-aside (lazy loading): the application checks Redis first; on a miss, it reads from the database and writes the result into Redis before returning it. The cache is populated on demand. Pros: only requested data is cached, cache is small. Cons: the first request always hits the database (cold start), and cache and database can be briefly inconsistent. Write-through: every write goes to the cache and the database simultaneously (or the cache proxies the database write). Pros: cache is always consistent with the database; no cold-start miss. Cons: every write is slower (two writes), and infrequently read data wastes cache space. Write-behind (write-back): writes go to the cache first and are asynchronously written to the database later — fastest writes but risk of data loss if the cache crashes before syncing. Cache-aside is by far the most common pattern in practice.
More Redis Questions
View all →- Intermediate What is Redis Cluster and how does it shard data?
- Intermediate What is the difference between Redis Sentinel and Redis Cluster?
- Intermediate How do MULTI and EXEC work in Redis transactions?
- Intermediate What is WATCH and optimistic locking in Redis?
- Intermediate What is Lua scripting in Redis and when should you use it?