Skip to content
StackDecode
System Design
7. Caching ArchitectureAnimated

Distributed Caching

A cache shared across many servers.

The idea

A cluster such as Redis or Memcached stores data partitioned by key so all app servers share it.

Watch it work

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

N1N2N3N4N1: 6 keysN2: 11 keysN3: 11 keysN4: 2 keys
  • outlined = moved key

Nodes and keys are hashed onto the same ring. Each key belongs to the first node clockwise from it.

nodes:
4
keys:
30
moved:
0
1/2

Dots on the ring are keys; larger circles are servers.

Step by step

  1. 1App server hashes the key
  2. 2Picks the cache node
  3. 3Reads or writes there
  4. 4Falls back to the database

Where it is used

Large scale web apps.

Watch out for

Node failure loses data. Treat the cache as disposable.

Related