Consistent hashing vs. modulo

Add virtual nodes and change cluster size to see how many cached keys relocate.

Tune the hash ring

Sample workload: 1,000 keys evenly distributed across hash space 0 to 360 degrees. Clockwise lookup picks the next node on the ring.

Rebalance impact and load skew
Consistent hashing moves about 1/(N+1) keys when scaling out, avoiding a full cache miss storm.
Consistent hashing keys moved
20%
Naive hash(key) % N moved
80%
Peak-to-average node load skew
1.15×

Consistent hashing saves 60% of cached keys compared to modulo hashing.

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).

Read the full Consistent Hashing chapter