Consistent hashing, measured: how many keys move when you add a node
Adding an 11th node to a hash(key) % N cluster moved 90.7% of 100,000 keys in our test; a consistent-hash ring moved about 9%. What virtual nodes change, and what they cost.
Prakhar
Backend engineer · PressentifyPublished

Spreading keys over servers with hash(key) % N works until the day you add a server. Then N changes, nearly every key gets a new home, and a cache cluster goes cold or a sharded database has to move almost everything. Consistent hashing exists to avoid that. We wanted to see the size of the difference, so we measured it.
Why modulo moves almost everything
A key keeps its server only if hash % 10 and hash % 11 happen to give the same number. For two nearby moduli that is about one key in eleven. So adding the eleventh node should move roughly ten keys in eleven, which is 90.9%. The ideal is different: a new node should take its fair share of the data, one eleventh or 9.1%, and nothing else should move.
For a cache that is a stampede of misses. For a sharded database it is a rebalance of nearly the whole data set, so people avoid growing the cluster at all and pay for it later.
The ring in one paragraph
Consistent hashing, introduced by Karger and colleagues in 1997, hashes both the servers and the keys onto the same circle. A key belongs to the first server point you meet going clockwise from it. Add a server and it only takes over the stretch of the circle just before its own points. Keys elsewhere do not notice. Amazon’s Dynamo paper (2007) added a refinement now called virtual nodes: each physical server owns many points on the ring, not one.
The test
We hashed 100,000 made-up keys (user:0 to user:99999) with MD5, placed 10 nodes, then added an 11th and counted the keys whose owner changed. We tried the modulo scheme and rings with 1, 10, 100, 200 and 1,000 points per node. The code is short enough to read in full:
import hashlib, bisect
def h(s):
return int.from_bytes(hashlib.md5(s.encode()).digest()[:8], "big")
KEYS = [f"user:{i}" for i in range(100_000)]
def mod_owner(nodes):
return {k: h(k) % nodes for k in KEYS}
def ring(nodes, vnodes):
points = sorted((h(f"node{n}#{v}"), n) for n in range(nodes) for v in range(vnodes))
hashes = [p[0] for p in points]
def owner(k):
i = bisect.bisect(hashes, h(k)) % len(points) # first point clockwise from the key
return points[i][1]
return {k: owner(k) for k in KEYS}
def moved(a, b):
return sum(1 for k in KEYS if a[k] != b[k]) / len(KEYS)Output from one run (no random seed is involved; the hash is deterministic):
mod N: moved 90.7%, ideal 9.1%
ring, 1 vnodes: moved 22.3%, max load / mean (10 nodes) = 3.38
ring, 10 vnodes: moved 7.8%, max load / mean (10 nodes) = 1.43
ring, 100 vnodes: moved 9.1%, max load / mean (10 nodes) = 1.17
ring, 200 vnodes: moved 8.4%, max load / mean (10 nodes) = 1.17
ring, 1000 vnodes: moved 9.0%, max load / mean (10 nodes) = 1.03
What the numbers say
- Modulo: 90.7% moved. It matches the 10-in-11 estimate. This is the case consistent hashing was invented for.
- Ring, one point per node: 22.3% moved. Far better, but more than twice the ideal. With one point each, the arcs are very uneven, and the new node happened to land in a wide one.
- Ring, 100 to 1,000 points: 8.4% to 9.1% moved. Close to the ideal 9.1%. The wobble between 8.4% and 9.1% is where the points happened to land, not a trend.
The 10-point row (7.8%) is below the ideal. That is not a free win: the new node got less than its fair share of keys, which means it will be under-used while the others stay loaded. Moving fewer keys is not the goal; moving exactly the new node’s share is.
The second reason for virtual nodes: balance
The same experiment shows why one point per node is not enough, even before you add anything. With 10 nodes and one point each, the busiest node held 3.38 times the average share of keys. At 10 points it was 1.43, at 100 points 1.17, and at 1,000 points 1.03.

What it costs
Points are not free. A ring with 10 nodes and 1,000 points each has 10,000 entries to keep sorted and look up (a binary search per key, as in the code above). That is small for a client library. It matters more when every node in a large cluster must hold the ring and keep it consistent as nodes join and leave. A few hundred points per node is the usual compromise; give bigger servers proportionally more points so they take proportionally more keys.
What this test does not show
A checklist before you pick a scheme
- Will the number of nodes ever change while the system is live? If never, modulo is fine and simpler.
- What does a moved key cost you: a cache miss, or a database row copy? That sets how much movement you can tolerate.
- Are the servers the same size? If not, give each a number of points in proportion to its capacity.
- Do you need the lookup in a client library or a proxy? Either must stay in step with the ring membership.
- Measure your own key names with your own hash before trusting any rule of thumb. It takes a minute.
Sources & Credits
- David Karger et al., “Consistent Hashing and Random Trees: Distributed Caching Protocols for Relieving Hot Spots on the World Wide Web,” STOC 1997: dl.acm.org
- Giuseppe DeCandia et al., “Dynamo: Amazon’s Highly Available Key-value Store,” SOSP 2007: dl.acm.org
- John Lamping and Eric Veach, “A Fast, Minimal Memory, Consistent Hash Algorithm,” 2014: arxiv.org
The experiment, the numbers and the charts are our own work (Python 3, MD5, run on 17 November 2026). The papers above are cited for the ideas, not for our numbers. Last verified 2026-11-17. Spotted a mistake? Tell us and we will correct it here with the date.
Share this article
Written by
Prakhar
Backend engineer · Pressentify
Backend engineer building Pressentify — interactive cheatsheets, handbooks and a job-hunt workspace.
Get the next one in your inbox
One practical backend article at a time. No spam; unsubscribe in one click.
Keep reading

Retry backoff needs jitter: 1,000 clients against a limited server, simulated
In our simulation, 1,000 clients retrying against a server that takes 50 requests per tick sent 10,500 requests with plain exponential backoff and about 3,750 to 4,060 with jitter. The code, the results and where they stop applying.
17 Nov · 3 min

ChainDrop: how the self-propagating npm worm steals tokens and republishes itself
A Shai-Hulud-family worm turns one stolen npm token into poisoned releases of every package that publisher controls. What the advisories say, and what rotation and allowlisting limit.
· 6 min

Prompt caching break-even: it pays on the second request, if you stay inside the cache lifetime
Using the multipliers in Anthropic's prompt caching docs (read on 17 November 2026): a 5-minute cache write costs 1.25x, reads 0.1x or less. The arithmetic shows caching wins from request two, and loses 25% if the cache keeps expiring.
17 Nov · 3 min