Cache Invalidation
The problem of removing or refreshing cached data when the underlying source changes, and the reason caching is harder than it looks.
Three broad strategies, each with a different failure. TTL expiry is simple and bounded but guarantees a window of staleness and produces a thundering herd when many keys expire together. Explicit invalidation on write is precise but requires every writer to know every cache, which breaks the moment a second writer appears. Write-through keeps the cache correct at the cost of write latency and a cache that must be available for writes to succeed.
Two failure modes worth naming. A cache stampede is what happens when a hot key expires and a thousand concurrent requests all miss and all hit the database; the fix is request coalescing or probabilistic early refresh. A cache penetration is repeated lookups for a key that does not exist, passing straight through to the store every time; the fix is caching the negative result.