Try
↑ ↓ move↵ openesc close
In this lesson · topic 2 of 7
  1. 1. Why hash mod N hurts
  2. 2. The ring and virtual nodes
  3. 3. Add a node to the ring and to mod N
  4. 4. What the ring balances and what it leaves
  5. 5. How many virtual nodes is enough
  6. 6. Rendezvous hashing and Maglev tables
  7. 7. Check ownership, balance and hot keys

Topic 2

The ring and virtual nodes

4 min read

Put everything on a circle

Pick a hash function with a big range and bend that range into a circle, so the largest value is next to zero. Hash each node’s name onto the circle. Hash each key onto the same circle with the same function. A key belongs to the first node you meet walking clockwise from the key.

Step through it below. The ring is the real one the lab uses, with three nodes, two points per node, and twenty-four keys.

Placing and moving keys on a ring

Step 1 / 4
nodes
3
ring points
6
  1. Hash the nodes onto a ring

    Each node is hashed to points on a circle of hash values. Here every node gets two points, so there are six marks. Those extra points are virtual nodes.

Why a join moves so little

A new node puts its points on the circle. Each point takes over only the stretch between itself and the previous point. Keys outside those stretches are untouched. Every key that moves goes to the new node, and none move between existing nodes. Leaving works the same way in reverse: a node’s keys go to the next node clockwise and nothing else changes.

The problem with one point per node

With one point per node, the arcs between points are random lengths. Some nodes get long arcs and own a lot of keys. Some get short arcs and sit nearly idle. Random points on a circle are not evenly spaced.

The fix is virtual nodes. Each physical node places many points on the circle, scattered by hashing different names for the same node. Many small arcs average out, so each node’s total share is closer to its fair share. A node that leaves also spreads its keys over many neighbours instead of dumping them on one.

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