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 ringWhat moved when cache-02 went down
measured over 1,200 keysWith 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| Server | Virtual nodes | Keys before | Share before | Keys after | Share after |
|---|---|---|---|---|---|
| cache-01 | 40 | 249 | 20.8% | 350 | 29.2% |
| cache-02down | 0 | 274 | 22.8% | 0 | 0.0% |
| cache-03 | 40 | 392 | 32.7% | 451 | 37.6% |
| cache-04 | 40 | 285 | 23.8% | 399 | 33.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.