All labs
Lab 38
Caching Strategies

TTL, Invalidation & Consistency

PriceMart drops prices in a flash sale. Watch a cached price go stale and a customer hit the old price at checkout โ€” then fix it with a short TTL, delete-on-write, or event-based invalidation. Live TTL countdown bars make 'caching is easy, invalidation is hard' obvious.

PriceMart starts a flash sale. Drop the price and watch the product page (reads cache) disagree with checkout(reads the database) โ€” then change the invalidation strategy and watch the gap shrink or vanish.
๐Ÿ›๏ธ Product page ยท reads cache
โ‚น4,999
TTL: 10s left
๐Ÿ’ณ Checkout ยท reads DB (truth)
โ‚น4,999
always the source of truth
โœ“ Page and checkout agree โ€” the cache is consistent with the source of truth.
Cache events
// drop the price to see what the cache does

With TTL 10s, drop the price and the page stays wrong for up to 10 seconds. Switch to event-based and the page corrects instantly โ€” that's the cost/freshness dial.

What just happened