Systems & Backend

Cache Invalidation

Keeping cached data correct as the underlying source changes — famously one of the hard problems.

Cache invalidation is deciding when a cached value is stale and must be refreshed or evicted. Strategies include TTLs, write-through/write-behind, and event-driven invalidation; getting it wrong serves users old data or stampedes the origin.

Worked example: a price cached with a 5-minute TTL stays stale for up to 5 minutes after you change it; write-through or explicit invalidation fixes that at the cost of complexity. Gotcha: the hard case is the thundering herd — a hot key expires and thousands of requests stampede the DB at once; single-flight locks or staggered TTLs prevent it.