Learn
Lesson · Partitioning and Load Balancing · Where the keys land

Virtual Nodes

A node's share of a ring is the total length of the arcs it owns, and with one token a node those arcs are nothing like equal — the largest node in an eight-node ring took 28.29% where an equal share is 12.50%. Giving each node V tokens averages V independent arcs together, and the relative spread falls like 1/√V. That is a real improvement and a slow one: a hundred times the tokens buys ten times the evenness.

a node's share = the total length of the arcs it owns successor ownership 8 nodes, 8 seeds max/mean relative spread 1/√V, stated V = 1 3.349 1.0370 1.0000 V = 10 1.520 0.3309 0.3162 V = 100 1.141 0.0959 0.1000 100× the tokens, 10× the evenness the rate is rounded and stated
What tokens buy, and at what rate

Core ideas

What this lesson establishes

One measurement and one rate. The measurement is the surprise; the rate is the thing that decides how many tokens a real fleet runs.

1

A ring does not balance by itself

With one token a node, the ring is cut at N uniformly random positions and each node owns the arc ending at its cut. Uniform cut points do not give equal arcs: across eight seeded rings of eight nodes, max/mean averaged 3.349, and on the drawn ring the largest node held 28.29% of the key space while the smallest held 2.95%. The property consistent hashing gives is stability under growth, not balance.

2

V tokens average V arcs together

Give each node V tokens and its share is the sum of V arcs drawn from the same distribution instead of one. Sums of independent draws concentrate: the relative spread of the shares falls, and it falls like 1/√V rather than like 1/V. The lab measures 1.0370, 0.3309 and 0.0959 at V = 1, 10, 100 against a stated 1.0000, 0.3162, 0.1000.

3

A square root is a slow purchase

To halve the spread you need four times the tokens; to get a tenth of it you need a hundred times. Tokens are not free — each one is a ring entry every router and every client caches, and the lookup structure grows with N · V — so V in a real system is a few hundred rather than a few thousand, and the spread it leaves is a cost that has to be planned for rather than eliminated.

The material

Arcs, tokens, and the rate the spread falls at

What a node's share actually is, how badly one token a node does, what V tokens buy, and the difference between a spread going to zero and a ratio going to one.

Definition · Virtual node

A virtual node, or token, is one position a physical node occupies on the ring. A node with V tokens owns the union of the V arcs ending at them, and its share is the total length of that union as a fraction of the ring. Keys are assigned by successor ownership: a key belongs to the first token at or after its position, clockwise, wrapping at the end.

The quantity to measure is the shares, and the two ways of describing how uneven they are answer different questions. max/mean is what the fullest node costs you, and it is the number a capacity plan needs. The relative spread — the root-mean-square deviation of the shares divided by the mean share — is what falls at a clean rate, and it is the number that tells you what another token is worth.

8 nodes, shares measured over 8 seeded rings V tokens on the ring max/mean spread 1/√V, stated 1 8 3.349 1.0370 1.0000 10 80 1.520 0.3309 0.3162 100 800 1.141 0.0959 0.1000 the drawn ring, seed 5, V = 1 largest node 28.29% of the ring = 2.263 × an equal share of 12.50% smallest node 2.95% = 0.236 × the mean the shares add to 1 — nothing is missing, they are simply not equal

The two numbers do not go to the same place

The spread goes to zero and max/mean goes to one, and reading the wrong one as the other makes V look either better or worse than it is. At V = 100 the spread is 0.0959 — about a tenth of what it was — while max/mean is 1.141, still 14% of extra capacity on the fullest node. A tenth of the spread is not a tenth of the imbalance, because max/mean has a floor of 1 that it approaches and never passes.

The 1/√V rate is stated on this page and measured in the lab, and the square roots printed beside the measurements are rounded — 1/√10 = 0.3162… is irrational, and the lab labels it as rounded where it prints it. Measurement and statement sit in adjacent columns on purpose: 0.3309 against 0.3162 is agreement to about five per cent on eight seeds, which is what a rate claim is entitled to, and it is not the same as an identity.

Example · What one token a node costs a real fleet

An eight-node ring at V = 1 gave a largest share of 28.29%. If that ring were serving 100 000 requests a second, the busiest node would take 28 290 /s against a fair 12 500 /s, so every node has to be built for well over twice its share or one of them saturates. At V = 100 the same fleet's worst node averages 1.141 times the mean, which is a 14% margin rather than a 126% one. The tokens did not change the number of machines; they changed how much of each machine is reachable.

What a token costs

Every token is a row in the ring that routers, clients and the membership protocol all carry, and the ownership lookup is over N · V entries rather than N. At N = 8 and V = 100 that is 800 rows, which is nothing; at N = 1 000 and V = 1 000 it is a million, which is a data structure with its own operational behaviour. The square-root rate is what makes this a real trade: since the next halving of the spread costs four times the tokens, there is always a point where buying evenness stops being worth the ring.

Two things this lesson does not change. Tokens do not affect what moves when a node joins — that is still the arcs the newcomer took, as in “Rehashing When N Changes”, and it is still roughly 1/(N+1) of the keys. And tokens do not help at all against a single key that is hot, because that key sits in exactly one arc however finely the ring is cut. “Hot Keys and Salting” is where that is priced.

Interactive

Consistent hashing and virtual nodes

A node's share is the arc it owns, and V tokens shrink the spread like 1/√V

A node owns an arc, not a shareone token a node is a ring that does not balance; V tokens shrink the spread like 1/√V
a node's arcsthe largest sharean equal share

Method

Measuring a ring and choosing V

Measure before you tune. The first two steps say how bad it is; the last two say what fixing it costs.

1

Measure the shares at the V you actually run

A node's share is the total arc it owns. Take max/mean and the relative spread, and take both over several seeds — a ring is one draw of N · V positions, and one draw is no more representative here than one placement was in “Hash Partitioning and Imbalance”.

2

Read max/mean as capacity and the spread as a rate

max/mean is the multiple of the mean your fullest node must be built for. The spread is the quantity that falls like 1/√V, and it is the one to watch when deciding whether another token is worth buying.

3

Price the next factor of two

Halving the spread costs four times the tokens. Write down the ring size that implies — N · V entries — and whether the membership and routing layers carry it comfortably. This is where the decision actually gets made.

4

Check what V has not fixed

Tokens do not reduce what moves when a node joins, and they do nothing about a hot key. If the imbalance you measured is one shard far above the others rather than a spread across all of them, more tokens is the wrong tool and the next two lessons have the right ones.

Arcs, tokens and rates

Score 0 / 0

Eight nodes at V = 1, 10 and 100

One ring measured, then the same ring with more tokens, then the rate checked against what was stated.

8 nodes, equal share = 1/8 = 12.50% V = 1, seed 5, the drawn ring largest 28.29% = 2.263 × mean smallest 2.95% = 0.236 × mean shares sum to 1 averaged over 8 seeds V = 1 max/mean 3.349 spread 1.0370 1/√V = 1.0000 V = 10 max/mean 1.520 spread 0.3309 1/√V = 0.3162 V = 100 max/mean 1.141 spread 0.0959 1/√V = 0.1000 the rate, as a ratio against V = 1 measured 1.000 0.319 0.093 stated 1.000 0.316 0.100 agreement to about 5%

The two right-hand columns are the lesson. The measured ratios track the stated 1/√V closely enough to believe the rate and not closely enough to call it an identity, which is exactly the standing a rate claim should have when it has been measured on eight seeds rather than proved.

For a faded rehearsal, stay at eight nodes and take V to 25. The supplied first move is the stated rate, 1/√25 = 0.2000. Predict the relative spread the lab will report, then read it, then say how far off your prediction was as a percentage — and separately predict whether max/mean at V = 25 will be nearer to 1.520 or to 1.141, and why that question has a different answer from the first one.

Common mistakes

1
Believing a ring balances because the shares sum to oneThey always sum to one; that is what makes them shares. The question is whether they are equal, and at one token a node they are not remotely — 28.29% against 2.95% on the drawn ring. Summing to one is a check that nothing was lost, not evidence of balance.
2
Expecting V tokens to divide the spread by VThe rate is 1/√V, measured at 1.0370, 0.3309 and 0.0959 for V = 1, 10, 100. Budgeting for a linear improvement makes every token-count decision look ten times cheaper than it is and leads to a ring sized for an evenness it will not deliver.
3
Reading a falling spread as a falling max/meanThe spread goes to zero and max/mean goes to 1. At V = 100 the spread is about a tenth of what it was and the fullest node is still 14% above the mean. Capacity is bought against max/mean, so quoting the spread in a capacity conversation understates what the fleet needs.

Check your understanding

✓
Finish when you can say what a token buys and what it costs, in the same sentence.

You should be able to compute a node's share from its arcs, measure max/mean and the relative spread over several seeds, state the rate at which the spread falls and that it is stated rather than proved, and say what V does not fix.

Note: Everything so far has assumed the partitioning function scatters the keys. A range partition deliberately does not, because ordered keys make scans cheap — and that choice has a cost that no number of tokens touches. “Range Partitioning and Hot Ranges” measures it.

Kept in this browser only, for you. Nothing is sent anywhere and nothing checks it. Carry it to another device.

Feedback and recommendations

Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.

No recommendations yet for this lesson.