Database: Cache Invalidation Done Right
You add a Redis cache in front of a database, and now users see stale data. Explain the invalidation strategy that fixes it.
Technical Reference & Key Concepts
The Challenge: Stale Cache
An API reads frequently from Redis and falls through to Postgres on miss. After edits, users still see the old value. Data consistency matters (it's a product catalog with prices).
Core questions to address:
- Why does a TTL-only approach still serve stale data, and what's the worst case?
- What invalidation strategy would you use — and what are its failure modes?
- How do you handle the read-path races (concurrent miss + write)?