LESSON 01 · Requirements

Define what an ID must guarantee

Uniqueness, size, ordering, opacity, and availability are separate properties.

SYSTEM VIEW

The ID path

Diagram view
Promise—
Calls per ID—
Orders—

Watch one shop’s order IDs priced promise by promise, then follow one ID into a browser.

  1. An example shop peaks at 12,000 orders a second, and Worker A and Worker B make the IDs. The contract: signed 64-bit, roughly time ordered, many machines, over 25,000 a second. Then ask: strict order? Gaps allowed? Unique for how long? Seen by users?

    Size
    signed 64-bit
    Order
    roughly by time
    Rate
    25,000+ IDs/s

    What changed

    • Orders at 12,000/s
    • The ID contract
    • Four questions to ask
  2. Say rough order is enough: two IDs made a few milliseconds apart may sort either way. Then Worker A and Worker B each build IDs from their own clock, with no network call, so an ID costs nothing beyond the worker itself.

    Network calls
    none
    IDs ms apart
    may sort either way

    What changed

    • IDs from each worker’s clock
    • 0 calls per ID
    • IDs ms apart may swap
  3. If a later ID must always sort higher, the workers coordinate through one shared Sequencer. Worker A gets N and Worker B gets N + 1. Every ID now costs a round trip, and the Sequencer is one more part that can fail.

    Later ID
    always sorts higher
    Each ID costs
    a round trip

    What changed

    • Sequencer, one shared counter
    • 1 round trip per ID
    • A part that can fail
  4. If finance wants invoice numbers with no gaps, the Orders DB assigns each one inside the committing transaction. Worker A’s commit takes 41; Worker B’s waits for it and takes 42, so those writes run one at a time. Drop any promise nobody needs.

    Invoices
    41 (A), then 42 (B)
    Writes
    one commit at a time

    What changed

    • Sequencer
    • Orders DB numbers invoices
    • B’s commit waits for A’s
  5. Back to rough-order IDs. Worker B returns an order ID that names one order. It is not a timestamp or a permission check, yet its bits can reveal when and on which machine it was made, so never treat it as a secret.

    Is
    an identity
    Reveals
    creation time, machine
    Is not
    a secret or a permission

    What changed

    • Orders DB
    • Back to rough order
    • The ID shows time and machine
  6. Worker B sends order 419430400000421893. A Shopper’s browser parses it as a JavaScript Number and gets 419430400000421900: Number loses integer precision above 2^53 − 1, about 9 quadrillion. Databases, APIs and clients must keep the full integer: send it as a string or use BigInt.

    As a Number
    419430400000421900
    As a string
    419430400000421893
    Exact up to
    2^53 − 1

    What changed

    • Order 419430400000421893
    • As a Number: …421900
    • Fix: a string or BigInt

Space plays · ← → step · Home resets

THE IDEA

How it works

This exercise assumes numeric IDs that fit in a signed 64-bit field, are roughly ordered by creation time, and can be generated by many machines above 25,000 IDs per second. Ask whether a strict global order is actually required, whether gaps are allowed, how long IDs must remain unique, and whether users can see them. Those choices change the design more than the requested throughput alone.

Each promise has a price. Take a shop creating 12,000 orders per second at peak (an example figure). If “ordered” means two IDs created a few milliseconds apart may sort either way, each machine can build IDs from its own clock with no network call. If it means a later ID always sorts higher, generators must coordinate, typically through one shared sequencer, which adds a round trip and a component that can fail. If finance wants invoice numbers with no gaps, the number has to be assigned inside the committing transaction, which serializes those writes. Drop any promise nobody needs: when nothing sorts by ID, ordering costs something and buys nothing.

An ID is an identity, not a timestamp or a permission check. A time-shaped value may reveal creation time and machine information, so do not treat it as secret. Databases, APIs, and JavaScript clients must represent the full integer exactly. JavaScript Number loses integer precision above 2^53−1, about 9 quadrillion, so use a string or BigInt at that boundary.

DECISION POINT

A product asks for “sortable IDs” but never defines what happens when two regions create records at once. What do you clarify?

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

Keep in mind

  • Write down the exact uniqueness and ordering promise.
  • Do not confuse an identifier with authorization or a precise clock.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
RecallQUESTION 01

Which property does an ID alone provide?

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.