← Lessons

quiz vs the machine

Platinum1780

System Design

Cache Coherence Across Nodes

When many servers cache the same key, an update must invalidate every stale copy.

6 min read · advanced · beat Platinum to climb

The Problem of Many Copies

In a distributed system the same key may live in dozens of local caches. When the underlying value changes, every cached copy is suddenly wrong. Cache coherence is the discipline of keeping those copies consistent, or at least bounding how wrong they can be.

Strategies

  • TTL only lets copies expire on their own. It is simple but every node can be stale up to a full TTL.
  • Invalidation broadcast publishes a message on update so each node drops the key. It is fast but a missed message leaves a node stale.
  • Versioned keys embed a version in the key so a new value is a new key and old copies age out naturally.
  • Lease based schemes grant a node temporary ownership and require renewal before serving.

The Hard Part

Invalidation is a distributed delivery problem. A broadcast can be lost, reordered, or delayed, so most designs combine a short TTL with invalidation: the broadcast handles the common case quickly and the TTL is the backstop that bounds staleness when a message is missed.

Key idea

Coherence across nodes pairs invalidation broadcasts for speed with a short TTL as a backstop, since any single broadcast can be lost or delayed.

Check yourself

Answer to earn rating on the learn ladder.

1. Why do many systems combine invalidation broadcasts with a short TTL?

2. How do versioned keys help with coherence?

3. What is the main weakness of relying on TTL only for coherence?