The Stale Cache
Something is wrong with the prices. Watch one copy age.
Lumen Market's shoppers keep paying old prices. Find out why, and stop it.
A cache keeps a copy of an answer close to the reader, so most reads skip the database. The copy starts ageing the moment it is stored.1
At Lumen Market, the price of a litre of oat milk changes every six minutes, and shoppers ask for it once a minute. The cache keeps each copy for its time to live, the TTL, and then deletes it.2 If the price changes before the copy expires, shoppers pay the old price.
Watch one copy age while the price moves.
From the references
- 1. The System Design Primer, Cache: When to update the cache (cache-aside, write-through). Donne Martin, CC BY 4.0, commit ae9bbd7. Read and rewritten in our words.
- 2. Valkey documentation, commands/expire.md: Keys with an expire; How Valkey reclaims expired keys. Valkey project, CC BY-SA 4.0, commit 3298309. Read and rewritten in our words.
Written for this lesson
Unnumbered explanations, the simulation and every number it shows were written for this lesson.
Minute 0. A shopper misses the cache, so the price comes from the database: 3.40. The cache keeps a copy.
When you have watched the copy go stale, open the live cache.