The expectation almost everybody brings to this is that adding one node to a fleet of seven moves about a seventh of the keys — the share the new node will end up owning. Under mod N assignment that is wrong, and it is wrong by a factor of about N: the true figure at N = 7 is seven eighths, which is 6.13 times the one-seventh prediction.
Theorem · Keys moved by a mod-N rehashAssigning key k to shard h(k) mod N and then to h(k) mod (N+1) moves a fraction N/(N+1) of a complete cycle of hash values. At N = 7 that is 7/8; at N = 100 it is 100/101.
Take the hash values h = 0, 1, …, N(N+1) − 1, one complete cycle. A key stays exactly when h mod N = h mod (N+1). Write v for that common value; since v is a residue mod N it satisfies v ≤ N − 1, and every such v is also its own residue mod N + 1, so the pairs that agree are exactly (v, v) for v = 0, 1, …, N − 1.
Because N and N + 1 are consecutive integers their greatest common divisor is 1, so by the Chinese Remainder Theorem each of the N(N+1) possible residue pairs occurs exactly once as h runs over the cycle. The N agreeing pairs therefore correspond to exactly N values of h, and the remaining N(N+1) − N = N² values move.
The moved fraction is N²/(N(N+1)) = N/(N+1), with no sampling and no approximation anywhere in the argument. The lab performs this enumeration for the N you choose: at N = 7 it reports 49 of 56.
□
The Chinese Remainder Theorem step is the only piece of machinery here, and it is “The Chinese Remainder Theorem” on the Discrete Mathematics path; the residue arithmetic under it is “Modular Arithmetic” on the same path. Everything else is counting.
Definition · Consistent hashingUnder consistent hashing, nodes and keys are both placed on a ring of hash values. Each node holds one or more tokens on the ring, and a key belongs to the first token at or after the key's position, going clockwise and wrapping. Adding a node adds tokens; it changes no existing token's position, so the only keys that move are those in the arcs the new tokens claimed.
N = 7 shards, one more added
mod N moved = 7/8 = 87.50% enumerated over 56 hashes
ring moved = 1/8 = 12.50% in expectation
sum 7/8 + 1/8 = 1
a seeded sample of 600 keys
mod N 519 of 600 = 86.50% near 7/8, not equal to it
ring 82 of 600 = 13.67% the joining arc measured 12.89%
spared 437 of 600 by the ring
Why the sample and the enumeration disagree, and why both are printed
The 7/8 is a count over a complete cycle of hash values, so it is exact for that object. A real key set is a finite sample of hashes, and the 600 keys the lab draws moved 519 times — 86.50%, near 87.50% and not equal to it. Neither figure is a correction of the other. The lab prints both because a reader who has only seen the exact fraction will believe their own measurement is a bug.
The ring's numbers work the same way with one extra wrinkle: what moves is the arc the joining node actually took, which on this seed was 12.89% of the ring rather than the 12.50% its expectation predicts. The 82 keys that moved are the keys in that arc. The expectation is a property of the scheme; the arc is a property of the placement, and “Virtual Nodes” is about how far apart those two can be.
Example · Reading the identity as a design argument7/8 and 1/8 are not two independent measurements that happen to be different. They partition the same key set: every key either changes shard under mod N or does not, and the ones a ring leaves alone are precisely the complement. So the choice between the schemes is not a tuning decision, and a system that reshards regularly under mod N is copying its entire dataset every time it grows. The identity is verified by enumeration at eleven shard counts from 1 to 100 rather than asserted once.
One thing the ring does not fix is the imbalance of the previous lesson. It changes what moves when N changes; it does not make the arcs equal, and with one token a node they are wildly unequal. That is the next lesson.