Modulo hash vs consistent hash

Modulo hashing picks a node with the key hash modulo the node count, so a new node moves most keys. Consistent hashing places keys and nodes on a ring, so a new node takes only its share. Going from 3 to 4 cache nodes moves 75 percent of keys with modulo hashing.

Play the level

Keys on a hash ringArrow keys add or remove a node. Tap to switch the hash.

Hash ring · 3 to 4 nodes · 8 of 36 keys move

Light across a planetDrag or use arrow keys to pick a path

Lasers in orbit, New York to London · 7,151 km · 24 ms one way

Case 1

Three cache nodes serve 90,000 reads/s and hold 12,000 keys. A fourth node joins. Fewer than 30 percent of the keys may move.

Case 1
Measure Goal Modulo hash Consistent hash
Moved keys under 30% 75.4% Fail 24.6% Pass
CPU use under 55% 45% Pass 45% Pass
Monthly cost 64 USD/mo 64 USD/mo
p99 latency 3.7 ms 3.7 ms
Error rate 0% 0%
HTTP/2HTTP/2HTTP/2UsersLoad balanc…8 vCPU · 8 GBRedis cache0.5 vCPU · 1 GBRedis cache0.5 vCPU · 1 GBRedis cache0.5 vCPU · 1 GBRedis cache0.5 vCPU · 1 GB
HTTP/2HTTP/2HTTP/2UsersLoad ba…Redis c…Redis c…Redis c…Redis c…
Modulo hash: misses a goal
HTTP/2HTTP/2HTTP/2UsersLoad balanc…8 vCPU · 8 GBRedis cache0.5 vCPU · 1 GBRedis cache0.5 vCPU · 1 GBRedis cache0.5 vCPU · 1 GBRedis cache0.5 vCPU · 1 GB
HTTP/2HTTP/2HTTP/2UsersLoad ba…Redis c…Redis c…Redis c…Redis c…
Consistent hash: meets the goals