What are the common cache invalidation strategies?
Cache invalidation is one of the hardest problems in distributed systems because you must balance consistency, availability, and performance simultaneously. The four primary strategies each fit different access patterns.
**TTL (Time-To-Live) expiration** is the simplest: every entry carries a max-age, and the cache discards it automatically. It requires no coordination with the source of truth but tolerates stale data for up to the TTL window. Use it when slight staleness is acceptable—CDN responses, DNS records, rate-limit counters.
**Event-driven (active) invalidation** purges or updates cache entries immediately when the underlying data changes. This is achieved via cache-aside updates on write, pub/sub events (e.g., Redis keyspace notifications), or explicit purge API calls. It minimizes stale reads but introduces coupling between the write path and cache management logic.
**Write-through** keeps the cache always in sync by writing to both the cache and the database synchronously on every mutation. Read latency stays low; write latency increases slightly. The cache is never stale, but every write pays the double-write cost even for data that is never re-read.
**Write-behind (write-back)** acknowledges the write to the client after updating the cache only, then flushes to the database asynchronously. This maximizes write throughput but risks data loss if the cache node dies before the flush. It is appropriate for high-throughput, loss-tolerant workloads like analytics counters.
**Cache-aside (lazy loading)** lets the application populate the cache on cache miss. On invalidation, the application simply deletes the key; the next read repopulates it. This avoids loading rarely-accessed data but can cause a thundering herd when many keys expire simultaneously—mitigated with jitter on TTLs or probabilistic early expiration.
In practice, production systems layer strategies: a short TTL provides a safety net, event-driven purges handle critical updates immediately, and write-through is reserved for hot, frequently-read data. The key engineering decision is choosing the acceptable staleness window and whether consistency must be strong, eventual, or bounded-staleness.
Names at least three strategies with a brief definition of each and one concrete trade-off (e.g., TTL tolerates staleness, write-through doubles write latency).
Explains all four strategies with trade-offs, discusses layering strategies, mentions thundering herd or cache stampede, and maps strategies to real use cases.
Reading the answer is step one. Explaining it unprompted — under interview pressure — is what actually matters. Get AI-graded feedback on your answer with follow-up probes on your weak points.
Get Graded — Free Assessment