Skip to content

DeploymentInteractive lab

Consistent hashing ring

Remove a node and measure exactly how many keys move

Place servers on a hash ring, give each one virtual nodes, then drop one and see the real percentage of keys that had to move - next to the number a plain modulo would have given you.

What this teaches

  • Virtual nodes
  • Rebalance cost
  • Load skew

The cluster

4 servers × 40 virtual nodes = 160 points on the ring
Servers4

What moved when cache-02 went down

measured over 1,200 keys
22.8%
Keys moved · hash ring
77.5%
Keys moved · plain modulo
25.0%
Ideal (1/n)
1.13×
Load skew after

With cache-02 removed, 274 of 1200 keys changed owner on the hash ring, 22.8%. Plain modulo moved 930, 77.5%. The ideal is 25.0%. Load skew across the remaining servers is 1.13 times the mean.

Only the keys that belonged to the departing server should move - 25.0% of them, one server's share of 4. Plain modulo moves almost everything instead, because hash % 4 and hash % 3 disagree for nearly every key. Skew is the busiest surviving server measured against the average; drag virtual nodes down to 1 and watch it climb.

The ring

0 at the top, clockwise to 2³²
  • cache-0120.8%up
  • cache-0222.8%down
  • cache-0332.7%up
  • cache-0423.8%up

Each server's virtual nodes sit on their own band outside the ring, so identity is carried by position as well as by colour. The hatched arcs belong to the server that went down - those, and only those, are the key ranges that had to be re-homed. Every other boundary is exactly where it was.

Keys per server

before and after the removal
How many of the 1200 keys each server held before the removal and after it, with each server's share of the whole key set.
ServerVirtual nodesKeys beforeShare beforeKeys afterShare after
cache-014024920.8%35029.2%
cache-02down027422.8%00.0%
cache-034039232.7%45137.6%
cache-044028523.8%39933.3%

Hashing is FNV-1a 32-bit followed by MurmurHash3's finalizer, computed in this page. The finalizer earns its place: a ring reads its position from the top bits of the hash, and FNV-1a on its own scatters those badly for short similar strings like cache-03#17 - without it the load here stayed at 19/30/18/33 even at two thousand virtual nodes each. A production ring uses a stronger hash again: MD5 in the original Ketama, xxHash in most modern clients. Keys are key-0 through key-1199, so every number here is reproducible.

Everything on this page runs in your browser. Nothing you type is sent anywhere, there is no account, and it keeps working offline.