Back to roadmap
Module 8 · Caching, Queues, Async WorkDay 07125 min

Cache Invalidation

The hardest problem in computer science (only half-jokingly).

Day 071

Cache Invalidation

TTL
note
Event
note
Version
note
Memory hook

Cache Invalidation: the hardest problem in computer science (only half-jokingly)

Mental model

absorb bursts before they become outages

Design lens

Versioned keys cost memory transitionally.

Recall anchors
TTLEvent-drivenVersioned keys

Why it matters

Invalidation comes in three flavors: time-based (TTL), event-driven (publish to invalidate caches on writes), and explicit (key purge). The right approach depends on consistency needs and traffic patterns.

Deep dive

TTL is simple and forgiving but allows stale data within window.

Event-driven needs reliable delivery and can amplify writes.

Versioned keys: cache by hash; updates live in a new key, old expires.

Demo / scenario

Catalog price changes need to propagate fast.

  1. Use cache key product:{id}:v{etag}.
  2. On price change, bump etag in DB.
  3. Old keys expire by TTL; new key materialized on next read.
  4. No purge necessary.

Tradeoffs

  • Versioned keys cost memory transitionally.
  • Event-driven scales per-event but needs reliable delivery.
  • TTL is the cheapest backstop.

Diagram

TTL
Event
Version
Three invalidation strategies.

Mind map

Check yourself

Loading quiz…

Sources & further reading