LESSON 02 · Design choices

Compare the simplest generators first

Central sequences, allocated ranges, UUIDs, and time-based IDs make different tradeoffs.

SYSTEM VIEW

The ID path

Diagram view
Allocator calls—
ID size—
Gap—

Watch one App server get its IDs from a ticket server, then in leased blocks, then as UUIDs with no call at all.

  1. The App server needs 500 IDs a second and asks the Ticket server for each. A ticket server is a small database that hands out the next number; Flickr ran two, one odd and one even. Simple, but every caller depends on it.

    Each ID
    one call
    Flickr
    2 servers: odd, even

    What changed

    • Ticket server, next number
    • 500 calls/s
  2. With a lease, the App server takes a block of 10,000 numbers, 10,001–20,000, and spends it locally. At 500 IDs a second the block lasts 20 seconds, so it calls the Ticket server every 20 seconds rather than 500 times a second.

    Block
    10,001–20,000
    Lasts
    20 s at 500/s

    What changed

    • Block 10,001–20,000
    • 1 call per 20 s, not 500/s
  3. The Ticket server goes down, and the App server keeps issuing from its block. Ten seconds in it has spent 5,000 numbers, and the next is 15,001. A block of 10,000 rides out an outage of up to 20 seconds.

    Spent
    10,001–15,000
    Covers
    up to 20 s

    What changed

    • Ticket server down
    • Next ID 15,001
  4. The Ticket server is back. The App server crashes with 15,001 next, restarts and leases a fresh block, 20,001–30,000. The unused 15,001–20,000 are discarded, a gap of 5,000 numbers. Fixed offsets like odd and even also get awkward as machines join or leave.

    Gap
    15,001–20,000
    New block
    20,001–30,000

    What changed

    • Ticket server back
    • App server crash, restart
    • Gap of 5,000 numbers
  5. Now the App server makes 128-bit UUIDs itself, with no allocator call. UUIDv4 is random apart from 6 fixed bits, so collisions are negligible, but three inserts land on scattered pages of the Orders index. Random keys slow inserts into a large B-tree.

    Size
    128 bits
    Random
    all but 6 bits
    Inserts
    scattered pages

    What changed

    • Ticket server
    • Orders index, a B-tree
    • UUIDv4, no call
  6. UUIDv7, standardized in RFC 9562, starts with a 48-bit Unix millisecond timestamp, then mostly random bits. It sorts roughly by creation time with no worker coordination, so all three inserts land on the Orders index’s last page. Postgres 18 can generate it natively.

    First 48 bits
    Unix ms timestamp
    Then
    mostly random
    Inserts
    the last page

    What changed

    • UUIDv4 → UUIDv7
    • Inserts at the end
  7. 64-bit, ordered: no UUID gives roughly time-ordered 64-bit integers; a Snowflake-style Worker does, at the cost of worker IDs and watching clocks. 128 bits fit: UUIDv7 is often easiest. 500/s, one DB: the Ticket server may be enough. Decentralization is not a virtue by itself.

    64-bit, ordered
    Snowflake-style
    128 bits fit
    UUIDv7
    500/s, one DB
    Ticket server

    What changed

    • The contract picks the generator
    The contract

Space plays · ← → step · Home resets

THE IDEA

How it works

A database sequence or ticket service gives straightforward unique numeric IDs. A ticket service is a small database whose only job is handing out the next number; Flickr described running two MySQL ticket servers, one issuing odd numbers and the other even. Every generator then depends on a central allocator unless it leases ranges. With a lease, a worker takes a block of, say, 10,000 numbers and spends it locally. At 500 IDs per second it calls the allocator every 20 seconds rather than 500 times a second, and it can ride out an allocator outage for up to that long. A crash discards the unused remainder, leaving gaps. Fixed offsets like odd and even become awkward as machines join or leave.

A UUID is a 128-bit identifier. UUIDv4 is random apart from 6 fixed bits, so machines generate it independently with negligible collision risk, but random values land on scattered B-tree pages and slow inserts into large indexes. UUIDv7, standardized in RFC 9562, starts with a 48-bit Unix millisecond timestamp followed mostly by random bits. It sorts roughly by creation time and needs no worker coordination, and Postgres 18 can generate it natively. If 128-bit keys fit your columns and clients, it is often the easiest choice.

Neither version meets this exercise’s 64-bit numeric contract. If compact, approximately time-ordered integers are required, a Snowflake-style layout is a useful candidate, at the cost of assigning worker IDs and watching clocks. Choose the simplest design that meets the actual contract; decentralization is not a virtue by itself.

DECISION POINT

A small internal tool needs only 500 IDs per second and already has one reliable database. Must it deploy a Snowflake service?

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

Keep in mind

  • A central allocator is simple until it becomes a latency or availability dependency.
  • UUIDv7 adds time order without coordination, but at 128 bits it answers a different contract from a 64-bit numeric ID.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
RecallQUESTION 01

What is a core weakness of one central ticket service?

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.