The same answer, asked again
A popular item can be read thousands of times. Without a cache, every read repeats the same database work, and the database can slow for everyone.
Follow the requestScene 1 / 6
Without a cache, every read goes to the database, even when the key is the same.
Illustrative guided sequence, not a simulation or a benchmark.
01 / 06
Direct database reads
Four requests ask for the same item. Nothing is remembered, so each one travels to the database. Repeated at scale, this identical work queues up at the database.
What you will learn
- Trace the cache-aside steps for a hit and for a miss.
- Explain why a miss stores the value in the cache rather than only replying.
- Describe how time-to-live and invalidation limit stale reads.
- Explain how a cold cache and a thundering herd load the database.
- State when cache-aside is a poor fit.
Transcript
- Direct database reads. Four requests ask for the same item. Nothing is remembered, so each one travels to the database. Repeated at scale, this identical work queues up at the database.On screen: Without a cache, every read goes to the database, even when the key is the same.
- Miss: read, store, reply. The application asks the cache first. The key is absent, so it reads the database, writes the value into the cache with a time-to-live, and only then replies to the client.On screen: On a miss, read the database, write the value into the cache, then reply.
- Hit: the database stays idle. The next request for the same key finds the value already stored. The application replies from the cache, and the database sees no traffic at all.On screen: A cached copy answers this read, so the database receives nothing.
- Cold cache after a restart. After a restart or a flush the cache is empty. Early requests miss, so the database carries the full load until entries are filled. The timing is illustrative, and real systems use warm-up or request coalescing to soften this.On screen: A new, empty cache sends the first reads for two different items to the database, so it takes a burst of work.
- Write: update, then invalidate. The application updates the database first, then deletes the cache entry. This narrows the stale window but does not close it. Readers between the update and the delete still see the old value. A slow miss that began before the update can re-cache the old value, and if the delete fails, the old value stays until its TTL ends. Cache-aside gives no consistency guarantee.On screen: On an update, write the database first, then delete the cached copy. This narrows the stale window but does not close it.
- Stale until expiry. Another cached item's row changes in the database without an invalidation, so reads keep returning the old copy. It stays out of date until its time-to-live ends, it is evicted, or it is invalidated. Choose the TTL from how stale the data may safely be.On screen: The cached copy is out of date until it expires or is invalidated.
Sources
- Cache-Aside pattern (Microsoft Learn) accessed 2026-11-25
- Caching challenges and strategies (Amazon Builders' Library) accessed 2026-11-25
Under the hood
How an application checks a cache first, falls back to the database on a miss, and stores the result, with the staleness, cold-cache and invalidation trade-offs.
Trade-offs
- Repeated reads of the same key skip database work, which lowers database load and usually latency for hits.
- Entries can be stale until their TTL ends or an invalidation runs. The team decides how much staleness is acceptable.
- A miss costs more than a direct read: a cache lookup, a database read and a cache write.
- Every reader and writer must follow the same key, TTL and invalidation rules, or the copies drift apart.
When not to use it
- Data changes on almost every read, so the hit rate stays low and the extra lookup and write add cost.
- Readers must always see the latest write; cache-aside leaves a short stale window even with invalidation.
- The data is sensitive or per-user and must not sit in a shared cache.
Limitations of this lesson
- Concurrency is not animated: several misses for one key can read the database together, which is a thundering herd.
- Cache outages and eviction are not modelled. A failed cache sends reads back to the database.
- The race between a database update and a cache delete is explained in narration only and is not animated.
- Animation timing is instructional, not measured latency or hit rate.