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.
- 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
- 1App server hashes the key
- 2Picks the cache node
- 3Reads or writes there
- 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.