Skip to content

Cache Invalidation

One-Liner

The process of removing or updating stale data in a cache.

What It Is

Mechanisms for ensuring cached data does not diverge from the source of truth beyond acceptable bounds.

Why It Exists

Caching without invalidation inevitably serves incorrect data.

How It Works

  • TTL-based expiration
  • Explicit invalidation on writes
  • Versioned keys
  • Event-based invalidation

Tradeoffs

Pros

  • Improves correctness

Cons

  • Increased system complexity
  • Risk of over- or under-invalidation

Failure Modes

  • Stale data served indefinitely
  • Over-invalidation causing cache thrash
  • Missed invalidation events

Interview Traps

  • Saying “just set a TTL”
  • Ignoring consistency requirements

Real-World Usage

Most large systems use multiple invalidation strategies simultaneously.

Anti-Patterns

  • Global cache flushes
  • TTLs without correctness analysis
  • Write-through cache
  • Event-driven systems