Skip to content
StackDecode
System Design
7. Caching ArchitectureAnimated

Cache Invalidation

Removing or updating cached data when the source changes.

The idea

One of the hard problems in computing. Options: delete on write, update on write, or expire with TTL.

Watch it work

Press play, pause, or step through. Some animations have settings you can change.

RequestL1 in-processL2 RedisDatabase
  • client
  • gateway / proxy
  • service
  • cache
  • data store
  • queue / stream

Check the in-process cache: nanoseconds.

step:
1/4
at:
Request
1/10

The green dot is a request moving through the system.

Step by step

  1. 1Data changes at the source
  2. 2Delete or update the cache entry
  3. 3Next read reloads fresh data
  4. 4Optionally broadcast to other caches

Where it is used

Keeping caches correct.

Watch out for

Race conditions can reinsert stale data.

Related