Caching interview question
After adding a Redis cache, users sometimes see stale or wrong data. How do you investigate and fix it?
Scenario Asked in Backend Engineer · Full Stack Engineer interviews
Summary
Find how entries become stale: writes that don't invalidate the cache, a race between a slow read repopulating the cache with old data after an update, keys that don't include everything the result depends on (user, locale, permissions), or TTLs longer than the data can tolerate. Fix with invalidation on write, correct keys, shorter TTLs or versioned keys.
Keep reading with a membership
The full answer with examples, key points and comparisons is part of the membership, along with every other interview answer, progress tracking and Daily Review. Most-asked answers stay free to read.
More Caching questions
- How does HTTP caching work (Cache-Control, ETag, CDNs)?
- What is a cache stampede (thundering herd) and how do you prevent it?
- In cache-aside, why can a value be stale even though you delete the key on every write?
- How can a CDN leak one user's data to another, and how do you prevent it?
- Explain the main caching patterns: cache-aside, read-through, write-through and write-behind.
- Why is cache invalidation hard, and what strategies help?
- Explain the difference between cache penetration, cache breakdown and cache avalanche.
- What are the risks of caching personalized or authorized data?