LESSON 06 · Replication and hot keys

Separate ownership from redundancy

The primary mapping picks an owner; a replica policy decides where copies live.

SYSTEM VIEW

The placement map

Diagram view
Copies on—
Key 8 reads—

Watch a key pick the machines for its three copies, then see what one very busy key needs instead.

  1. Nodes A, B and C hold three tokens each, scattered round the ring. A key hashing to 8 walks clockwise and meets A1 at 12 first, so Node A owns it. Where its copies go is a separate choice.

    Owner of 8
    A1 at 12 · Node A
    Walk from 8
    A1, A2, B1, B2, C1

    What changed

    • Key 8 on Node A
  2. For three copies, take the next three tokens: A1, A2 and B1. They belong to Node A, Node A and Node B, so two copies share one machine. One failure there takes both, leaving a single copy.

    Next 3 tokens
    A1, A2, B1
    Machines
    A, A, B

    What changed

    • Copies on A, A and B
  3. Skip any token whose machine already holds a copy: A1, then B1, then C1, so Nodes A, B and C. Dynamo calls this the preference list; Cassandra’s NetworkTopologyStrategy walks similarly by rack. How reads and writes use the copies is the store’s consistency policy.

    Skip repeats
    A1, B1, C1
    Preference list
    A, B, C

    What changed

    • Copies on A, B and C
  4. Key 8 now gets 60,000 reads a second, and every one lands on its owner, Node A, which handles 20,000. Virtual nodes spread many keys, but they can’t split one key: more tokens would only move it whole.

    Key 8
    60,000 reads/s
    Each node
    20,000 reads/s

    What changed

    • 60,000 reads/s on key 8
    • Node A overloaded
  5. Each of the 200 app servers keeps key 8 for one second, so each sends Node A at most one read a second: 200 in all instead of 60,000. The price: a reader may see a value up to a second old.

    200 servers × 1/s
    ≤ 200 reads/s
    Staleness
    up to 1 s

    What changed

    • 1 s cache on each app server
    • Node A: ≤ 200 reads/s of key 8
  6. Writes need another tool. Split a counter such as likes:42 into 16 keys, which hash across the ring: 6 on Node A, 5 each on B and C. Each write adds to a random one; a read must sum all 16, so reads cost more. DynamoDB calls this write sharding.

    likes:42
    16 keys
    Write
    +1 to a random key
    Read
    sum all 16

    What changed

    • 16 keys for likes:42
    • Writes spread: A 6 · B 5 · C 5

Space plays · ← → step · Home resets

THE IDEA

How it works

For a replicated store, choose distinct physical nodes after the primary token, often with failure-domain rules so copies do not share one rack or region. Merely selecting the next few virtual tokens can accidentally place multiple copies on the same physical host. Suppose the walk from a key meets tokens A1, A2, B1, B2, C1. With three copies, the next three tokens give A, A, B, which is only two machines. Skipping repeats gives A, B, C. Dynamo calls the result a preference list, and Cassandra’s NetworkTopologyStrategy applies a similar walk by rack. Reads, writes, and repair then depend on the consistency policy of the storage system, not on hashing alone.

A single key that receives extreme traffic still maps to one primary range. Virtual nodes spread many keys, but cannot split that key’s load. Take an example key with 60,000 reads per second on nodes that each handle 20,000. A cache with a one-second lifetime on each of 200 app servers cuts store traffic for that key to at most 200 reads per second, in exchange for up to a second of staleness.

Writes need a different tool. Split a counter such as likes:42 into 16 keys, add to a random one, and sum all 16 on read, so reads get more expensive. DynamoDB’s documentation describes this kind of suffix as write sharding. Keep hot-key mitigation separate from general partition balance.

DECISION POINT

A celebrity profile key saturates its owner despite hundreds of virtual nodes. What would you try?

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

Keep in mind

  • Replica placement must select distinct physical failure domains.
  • Virtual nodes do not solve a single hot key.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
RecallQUESTION 01

Why should replica selection skip repeated tokens on one physical machine?

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.