Consistent hashing vs. modulo
Add virtual nodes and change cluster size to see how many cached keys relocate.
Sample workload: 1,000 keys evenly distributed across hash space 0 to 360 degrees. Clockwise lookup picks the next node on the ring.
- Consistent hashing keys moved
- 20%
- Naive hash(key) % N moved
- 80%
- Peak-to-average node load skew
- 1.15×
Predict before you scale
Suppose a 4-node Redis cluster uses hash(key) % 4 and you scale up to 5 nodes. Roughly what fraction of cached keys map to a different node under modulo vs. consistent hashing?
Reveal the worked example
Modulo shifts N / (N + 1) = 4/5 = 80% of keys all at once, triggering a database thundering herd. Consistent hashing moves only 1 / (N + 1) = 1/5 ≈ 20% (only keys whose ring arc lands on the new node).