System Design
Cache Invalidation at Scale: Versioned Keys, Purges, and Bounded Staleness
- Panel 1 - Bound the promise:
- Name the stale-data window
- Name the failures you tolerate
- TTL limits age; it is not instant
- Freshness is a stated guarantee
- Panel 2 - Fast purge, fragile path:
- Purge is fast when events arrive
- One lost event leaves stale data
- Write then delete can race
- Delete then write can race too
- Panel 3 - Version the namespace:
- Publish v2; readers stop asking for v1
- Old v1 keys become unreachable
- Distribute the version reliably
- Garbage-collect old keys later
- Coalescing stops load, not staleness
- Panel 4 - Falsify the guarantee:
- Drop one invalidation event
- Reorder the DB write and delete
- Read through every cache layer
- Measure age of the stale response
- Fail if it exceeds the promised window