Try
↑ ↓ move↵ openesc close

Consistent hashing lab

Place nodes and virtual nodes on a hash ring, add and remove nodes, and compare how many keys move against the naive hash mod N rule.

or remove one with its Remove button below.
5 nodes40 points

Each tick is one virtual node. Keys are placed and settled: 20000 of 20000.

Keys per node

  • node 03019 / 4034
  • node 15282 / 3999
  • node 23796 / 4069
  • node 34829 / 3946
  • node 43074 / 3952

ring, keys on node hash mod N, keys on node

imbalance, ring
1.32max / mean
imbalance, mod N
1.02max / mean
mean keys per node
4000
nodes
5

Keys moved by the last change

Add or remove a node to see how many keys have to move.

What to try

Each one sets up a starting point. Then make the change it describes.

  1. Add one node

    Leave the defaults and press Add a node once. Read the two moved percentages.

    Look for. Hash mod N reshuffles most keys because almost every key changes remainder. The ring only moves the keys the new node takes over.

  2. One point per node

    Set virtual nodes to 1 and look at the imbalance and the keys-per-node bars.

    Look for. A few random points leave arcs of very different length, so some nodes own far more keys than others.

  3. Smooth it out with virtual nodes

    Slide virtual nodes up toward 256 and watch the imbalance number.

    Look for. More points per node average out the arc lengths, so the max over mean ratio drops toward 1.

  4. Remove a node

    Press Remove next to any node. Compare the keys moved.

    Look for. The ring only moves the keys that node owned, spread across the survivors. Hash mod N reshuffles again.

  5. Grow the cluster

    Press Add a node four times in a row and watch the ring percentage after each.

    Look for. The share of keys that must move on each join shrinks as the cluster grows, because the new node takes a smaller slice.

New to the idea? Read the lesson first. Every number here comes from a seeded simulator, so the same seed gives the same run.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms