LESSON 06 · Coordination

Give each live generator a unique identity

The worker field prevents collisions only while worker IDs are leased and fenced correctly.

SYSTEM VIEW

The ID path

Diagram view
Holds ID 17—
A’s lease—
Issuing as 17—

Watch Worker A lose touch with the Registry while its lease on worker ID 17 runs out, then replay it with A fencing itself and a 10-second margin.

  1. Two workers sharing a worker ID can make the same timestamp and sequence, so each live worker leases its own from the Registry, a strongly consistent store, before issuing. Worker A holds ID 17 on a 30-second lease, renewed at t = 0.

    Worker A
    ID 17
    Lease
    30 s, renewed at t = 0

    What changed

    • A renews ID 17
    • Lease until t = 30
  2. Right after t = 0 the network cuts Worker A off. Its renewals at t = 10 and t = 20 never reach the Registry, and A keeps issuing IDs. At t = 20 its lease has 10 seconds left.

    Renewals lost
    t = 10, t = 20
    Lease ends
    t = 30

    What changed

    • Network cuts A off
    • Renewals at t = 10 and 20
  3. At t = 30 the Registry considers A’s lease expired and hands ID 17 to Worker B. Cut off, A never hears and keeps issuing. From t = 35 two live workers issue as 17, so both can produce identical IDs.

    Registry
    17 → Worker B
    Issuing as 17
    A and B

    What changed

    • A’s lease at t = 30
    • Worker B gets 17
    • Both issue as 17
  4. Replay it with fencing. A fencing token can’t help here: making an ID touches no server that could check one. So Worker A checks its own lease timer before each ID, and at t = 30, with no renewal, it stops.

    Fencing token
    no server to check it
    Worker A checks
    its lease timer

    What changed

    • Replay with fencing
    • A checks its timer
    • A stops at t = 30
  5. The Registry counts A’s lease expired at t = 30 but waits a 10-second margin, for clock drift and process pauses, before granting 17 to Worker B at t = 40. A stopped at 30, so only one worker issues as 17.

    Margin
    t = 30 to 40
    Covers
    clock drift, pauses
    After a crash
    past its last ID, or wait

    What changed

    • 10 s margin
    • Worker B gets 17 at t = 40
    • One worker issues as 17
  6. The 10-bit worker field holds 1,024 worker IDs. A rolling deploy that briefly runs 1,200 pods can’t give each live pod its own, so leave headroom. A small fixed fleet may manage with static configuration instead.

    Worker IDs
    1,024 (10 bits)
    Rolling deploy
    1,200 pods
    Small fixed fleet
    static config

    What changed

    • Rolling deploy of 1,200 pods
    • Only 1,024 worker IDs

Space plays · ← → step · Home resets

THE IDEA

How it works

Assign each generator a unique data-center and machine ID from a registry: a strongly consistent store such as etcd or ZooKeeper that records which process holds which ID. The claim is a lease, which lasts a fixed time and must be renewed. On startup, obtain the lease before issuing IDs. A duplicate configuration lets two workers generate the same timestamp and sequence combination.

Follow a partition with example timings. Worker A holds ID 17 on a 30-second lease and last renewed at t = 0, when the network cuts it off. At t = 30 the registry considers the lease expired and could hand 17 to Worker B. If A keeps issuing, both can produce identical IDs. Fencing means stopping an expired holder from acting. A classic fencing token, a rising number that a storage server uses to reject old holders, does not fit here because generating an ID touches no such server. So the worker fences itself: it checks its lease timer before each ID and stops when the lease runs out. The registry waits an extra margin, perhaps 10 seconds, before reassigning, to cover clock drift and process pauses.

Do not reuse a worker ID immediately after a crash unless the new process can prove its clock and sequence have moved past the old process’s last issued value, or it has waited out a safe interval. Leave headroom in the 10-bit worker namespace: a rolling deploy that briefly runs 1,200 pods cannot fit in 1,024 IDs. A small fixed fleet may manage with static configuration instead.

DECISION POINT

An autoscaler starts two pods with the same machine ID. Why can their IDs collide?

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

Keep in mind

  • Worker-ID uniqueness is a live operational invariant.
  • Lease expiry and restart need fencing or a safe reuse delay.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
RecallQUESTION 01

What must be unique among simultaneously active generators?

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.