Lab · Distributed data
Consistent hashing
Which cache or database node should store a key? hash(key) % N is simple, but when N changes almost every key moves. Consistent hashing places servers and keys on a ring so a change only moves the keys next to it.
Try it
Server AServer BServer CMoved by the last change
Servers
3
Virtual nodes each
20
Busiest server vs fair share
1.25×
fairly even
Keys moved (ring)
—
change a server to see
Keys moved (hash % N)
—
Controls
Keys per server
The tick marks a perfectly fair share (20.0 keys each).
What moved
Add or remove a server to see exactly which keys change owner.
What this model simplifies
- Keys are equal in size and popularity. A single hot key still overloads its server no matter how the ring is built — that needs replication or key splitting.
- Each key lives on one server. Real systems (Cassandra, DynamoDB) store each key on the next R distinct servers clockwise for redundancy.
- Positions use a 32-bit hash (FNV-1a with a final mix). Production systems often use MurmurHash or xxHash; the idea is identical.