LESSON 02 · Data placement

Partition the key space

Give each key a predictable home while limiting movement when nodes change.

SYSTEM VIEW

The storage path

Diagram view
Key—
Owner—
Moved—

Watch keys find their node on a ring of six, then see how little moves when a seventh joins.

  1. Partitioning splits the key space so each node stores only part of the data. Six nodes hold 6 TB with two tokens each, virtual nodes that even out the shares. The dots are keys; each node owns 16 to 18%, about 1 TB.

    Nodes
    6 · 2 tokens each
    Data
    6 TB, about 1 TB each
    Each owns
    16–18% of the ring

    What changed

    • 12 tokens on 6 nodes
    • Keys spread by hash
  2. order:42 hashes to 58. Walking clockwise, the first token it meets is E2 at 61, so Node E owns the key, and every request for order:42 is routed there.

    hash(order:42)
    58
    Next token
    E2 at 61 · Node E

    What changed

    • order:42 on Node E
  3. Node G joins with tokens 43 and 93. It will take only 37 to 43 from F and 87 to 93 from C: 14% of the ring, about one seventh of the 6 TB, roughly 860 GB. Plain hash(key) mod N would reassign most keys.

    G takes
    14%, about one seventh
    Data to move
    about 860 GB of 6 TB
    hash(key) mod N
    most keys move

    What changed

    • Node G, tokens 43 and 93
    • 37–43 from F, 87–93 from C
  4. G copies the ranges, 860 GB, from F and C at 100 MB/s: about 2.4 hours of network and disk they also need. Then its tokens go live, 14% of the ring changes owner, and coordinators route by the new membership map.

    Copy
    860 GB at 100 MB/s
    Takes
    about 2.4 hours
    After
    C 11 · F 11 · G 14%

    What changed

    • G owns 37–43 and 87–93
    • C and F 18% → 11%
  5. Keys are spread evenly, yet one key at 66, on Node F, takes a third of all writes. More virtual nodes would only move it whole: it has one logical home. Caching and replication help reads; a write-hot key may need a different data model.

    Keys
    11–16% a node
    Writes
    ⅓ to one key on F
    More tokens
    move it whole

    What changed

    • Hot key at 66
    • Node F takes ⅓ of writes
  6. order:41, 42 and 43 hash to 12, 58 and 80, on Nodes C, E and B, so one scan asks three nodes. Range partitioning, as in Bigtable and HBase, keeps keys sorted for cheap scans, but sequential keys, such as timestamps, pile onto one node.

    order:41 · 42 · 43
    12 · 58 · 80
    Scan 41–43
    asks 3 nodes
    Range partitioning
    cheap scans, hot tail

    What changed

    • Hot key
    • order:41 on C, order:43 on B

Space plays · ← → step · Home resets

THE IDEA

How it works

Partitioning, also called sharding, splits the key space so each node stores only part of the data. Hash each key to a partition and route requests to its owner. Consistent hashing places keys and node positions on a ring; a key maps to the next owner clockwise. Virtual nodes, which are several ring positions for one machine, distribute ownership more evenly and let larger machines take more ranges. Clients or coordinators (nodes that handle a request on a client’s behalf) need a current membership map during changes.

When a node joins, only the ranges it takes need to move. In an example cluster of six nodes holding 6 TB, a seventh node takes about one seventh of the data, roughly 860 GB, where plain hash(key) mod N would reassign most keys. That transfer still costs network and disk capacity: at 100 MB/s, 860 GB takes about 2.4 hours.

Watch for hot keys: balanced key counts do not guarantee balanced request load. A popular key has one logical home however many virtual nodes exist. Replication and caching can help reads, but a write-hot key may require a different data model. Hash partitioning also gives up range scans, because neighboring keys land far apart. Range partitioning, as in Bigtable and HBase, keeps keys sorted so scans stay cheap, at the cost of hot spots when new keys arrive in sequence, such as timestamps.

DECISION POINT

One key receives a third of all writes, though key counts are evenly distributed. Will more virtual nodes solve it?

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

Keep in mind

  • Partitioning distributes data; it does not create a safety copy.
  • Virtual nodes balance ranges, while hot keys need workload-specific treatment.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 2
RecallQUESTION 01

What does partitioning primarily solve?

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

Next lesson

0 of 2 checkpoints answered correctly to complete this lesson.