Interview › Databases & Caching
What is cache invalidation, and why is it hard?
Databases & Caching · Intermediate level
Answer
Cache invalidation is deciding when cached data is no longer correct and removing or refreshing it. It is hard because writes can come from many paths and caches can exist at multiple layers.
Technical explanation
TTL controls the trade-off between freshness and backend load.
Stampedes are prevented with request coalescing, locks, TTL jitter, stale-while-revalidate, and rate limits.
Invalidation is hard because writes can happen through many services; outbox events make invalidation more reliable after DB commit.
Hands-on example
Cache-aside with stampede protection:
1. GET product:v2:123.
2. On miss, acquire SET product:v2:123:lock 1 NX PX 5000.
3. Lock holder reads RDS and SETEX product:v2:123 300+jitter value.
4. Other callers return stale value or wait briefly.
5. After product update, commit DB then DEL product:v2:123 or publish invalidation via outbox.
Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.
More Databases & Caching interview questions
- How is Valkey wire-compatible with Redis, and what risks remain in a migration?
- How do you migrate from Redis to Valkey with minimal downtime?
- What is Redis, and what core data types does it support?
- What is the difference between ElastiCache Redis and Memcached?
- What is ElastiCache, and what does it manage?
- What is connection exhaustion, and how do you prevent it?
- What is schema migration, and how do you run migrations safely in production?
- What is AWS DMS, and when would you use it?