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.
Hash ring · 3 to 4 nodes · 8 of 36 keys move
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.
| 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% |