LESSON 04 · Add and remove

Move only affected ranges

A new token takes the interval immediately before it; its successor otherwise keeps its keys.

SYSTEM VIEW

The placement map

Diagram view
Keys moved—
Expected—
A owns—

Watch a node join and another leave, and see which keys change owner each time.

  1. Forty keys are spread round the ring. A owns 81 to 20, the 40 positions back to C. B owns 21 to 50 and C owns 51 to 80, 30 each.

    A
    81–20 · 40%
    B
    21–50 · 30%
    C
    51–80 · 30%

    What changed

    • 40 keys
  2. Node D, a new node, hashes to 35, between A at 20 and B at 50. Once it joins it will own 21 to 35, which B owns today. Nothing has moved yet.

    What changed

    • Node D, not yet on the ring
  3. In a durable store, routing must not flip before D has the data. D streams 21 to 35 from B and takes new writes for it, but serves no reads until streaming finishes.

    What changed

    • B still serves 21–35
    • D holds a copy
  4. D’s token goes live. Only 21 to 35 changes owner, 15% of the ring, against the 25% an equal new node takes on average. A and C keep every key, and A still owns 40%.

    What changed

    • D owns 21–35
    • B keeps 36–50
    • A and C untouched
  5. When C leaves, 51 to 80 passes to the next token clockwise, A at 20 past the top. Nothing else moves, but A now owns 70%. Hashing only says where keys live: A needs C’s data, or a replica, first.

    What changed

    • Node C
    • A owns 51–20

Space plays · ← → step · Home resets

THE IDEA

How it works

When a node token joins between predecessor P and successor S, it becomes owner of keys in the interval (P, new token], meaning positions just after P up to and including the new token. Those keys move from S. Other intervals keep their owner. When a token leaves, its former interval moves to its successor.

Continue the 0 to 99 example with A at 20, B at 50, and C at 80. New node D joins at 35. It takes positions 21 to 35 from B, which keeps 36 to 50. A and C are untouched, so 15% of the ring moves. With evenly spread tokens, expected movement for one equally sized new node is roughly 1/(N+1) of keys, which would be 25% here; real layouts vary. Notice that D relieved only B, while A still owns 40 of the 100 positions. Virtual nodes, in the next lesson, address that.

Do not flip routing before the new owner has the data if the store is durable. Use a controlled transition: publish a membership version, copy the affected range, catch up concurrent writes, then switch ownership and verify. Cassandra follows this shape: a joining node streams its ranges and receives new writes for them, but serves no reads until streaming finishes. A cache may tolerate misses and refill instead. Node failure also requires replicas or fallback; hashing alone merely points to a new location.

DECISION POINT

A new durable-store node is announced before its range has been copied. What can go wrong?

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

Keep in mind

  • Join and leave affect local ring intervals rather than the entire keyspace.
  • Ownership transfer needs a data migration and cutover protocol.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
ApplyQUESTION 01

Tokens P and S sit at 10 and 60. A new token joins at 35. Which positions move, and from whom?

Choose an answer. You’ll see the explanation once you get it right.

Next lesson

0 of 3 checkpoints answered correctly to complete this lesson.