LESSON 07 · Operations

Prove the service remains unique

Test concurrency, restarts, rollover, lease loss, and clocks as first-class failure cases.

SYSTEM VIEW

The ID path

Diagram view
Faults hit—
Rejected rows—

Watch a staging run break four workers on purpose while a unique index hunts for repeats, then follow one ID to a browser.

  1. Worker A and Worker B load millions of IDs into the ID table; its unique index rejects none. Monitoring tracks IDs per second, exhaustion, clock rollback, skew, lease failures, latency and allocation failures. A finite clean run is no proof: it never triggers a fault.

    Rejected rows
    0, but no proof
    Uniqueness rests on
    unique live worker IDs
    And on
    time · sequence never repeating

    What changed

    • Millions of IDs loaded
    • Unique index checks repeats
    • 0 rows rejected
  2. In staging, inject the faults on purpose. Worker A’s clock steps back 5 seconds: it stops issuing, and Monitoring raises a rollback alert. Worker B is killed mid-millisecond and restarts under the same ID: it waits past its last millisecond. Still 0 rows rejected.

    Clock back 5 s
    stop and alert
    Restart, same ID
    wait past last ms
    Rejected rows
    0

    What changed

    • Worker A’s clock back 5 s
    • Worker B killed, restarted
    • Rollback alert
    • Still 0 rejected
  3. Worker C is blocked from the registry until its lease expires: it stops issuing. Worker D is pushed past 4,096 IDs in one millisecond: the 4,097th waits for the next. All four faults hit and 0 rows are rejected: now the clean result means something.

    Faults hit
    4 of 4
    Rejected rows
    0
    Skip the faults
    a billion IDs prove nothing

    What changed

    • Worker A and Worker B
    • Worker C’s lease expires
    • Worker D past 4,096 in 1 ms
    • 4 of 4 faults, 0 rejected
  4. Worker A’s epoch moves from the start of 2024 to the start of 2025: new timestamps shrink, so new IDs sort below old ones. Millisecond 1,000, same worker and sequence, repeats 4,194,725,893; the unique index rejects it. Version the layout or use a new namespace.

    2024 epoch, ms 1,000
    4,194,725,893
    2025 epoch, ms 1,000
    4,194,725,893
    Same fields
    dc 3 · machine 7 · seq 5

    What changed

    • Worker C and Worker D
    • Epoch 2024 → 2025
    • 4,194,725,893 again
    • 1 row rejected
  5. Check every hop end to end: the ID table’s signed 64-bit key, the App server’s JSON, the Browser’s JavaScript. Pick JSON number: the Browser shows 419430400000421900. Pick JSON string: it keeps 419430400000421893. Discord’s API returns its IDs as strings for this reason.

    As a Number
    419430400000421900
    As a string
    419430400000421893

    What changed

    • Monitoring and Worker A
    • App server and Browser
    Send the ID as
  6. The App server asks Worker A for a new order’s ID, but Worker A is down. The App server answers 503 rather than silently reuse an ID; an approved fallback namespace is the other choice. Document what public IDs reveal, and authorize separately.

    Generator down
    fail clearly, or fallback
    Never
    silently reuse an ID
    Public IDs
    not authorization

    What changed

    • ID table
    • Worker A down
    • 503: no ID, none reused

Space plays · ← → step · Home resets

THE IDEA

How it works

Track generated IDs per second, sequence exhaustion, clock rollback, skew, lease failures, generator latency, and allocation failures. Test millions of concurrent generations across many workers, but do not treat a finite no-collision test as a mathematical proof. Uniqueness rests on unique live worker identities and a non-repeating timestamp and sequence state machine under defined fault assumptions.

So test the faults directly, because a clean load test never triggers them. In a staging run, step one worker’s clock back 5 seconds, kill another mid-millisecond and restart it under the same ID, block a third from the registry until its lease expires, and push a fourth past 4,096 IDs in a millisecond. Load every issued ID into a table with a unique index and look for rejected rows. A run that skipped those events could issue a billion IDs with no duplicates and still say nothing about them.

A migration to a new epoch or layout needs versioning or a separate namespace and a clear decoder. Moving the epoch forward makes every new timestamp value smaller, so new IDs sort below old ones and can repeat them. Check database signedness, API serialization, and browser precision end to end; Discord’s API returns its 64-bit IDs as strings for this reason. If the generator becomes unavailable, an API that needs a durable record should fail clearly or use an approved fallback namespace; it must not silently reuse IDs. Document what can be inferred from public IDs and use authorization independently.

DECISION POINT

Tests show no collisions, but a browser displays two large IDs as the same number. What failed?

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

Keep in mind

  • Validate the invariants behind uniqueness, not only sample outputs.
  • Serialization and future layout migration are part of the system design.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
RecallQUESTION 01

Which signal should alert on clock safety?

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

0 of 3 checkpoints answered correctly to complete this lesson.