Lab · Distributed data
IDs: from auto-increment to UUIDs and Snowflake
Every row needs an ID that no other row has. Try the five main ways to make one, in the order they appeared, and measure what each costs: repeated IDs, order, trips over the network and the index.
- App server A — saves rows — healthy
- App server B — saves rows — healthy
- DB 1 — 31 rows · 1 page — healthy — last ID 31
- A row to save
Same ID on two rows
0
Healthy: every ID once
IDs out of time order
0%
smaller than the ID before
Index page fill
97%
1 page of 32 keys
Pages written
1
by the last 100 rows, of 1
Trips for IDs
0.0
per 100 rows: none needed
Bytes per ID
8bytes
64 bits
Numbers add up:31 saved + 0 failed + 0 in progress = 31 rows asked forThe lab checks this sum as it runs, so a counting mistake would show here.
Controls
The five ways side by side
| Way | Size | Shared counter? | In time order? | Safe across databases? | Can be guessed? |
|---|---|---|---|---|---|
| Auto-increment (running) | 8 bytes | Yes: the database | Yes | No: each database repeats 1, 2, 3 | Yes: the next is one more |
| Blocks from a ticket server | 8 bytes | Yes: one trip per block | Roughly | Yes | Mostly |
| UUID v4: random | 16 bytes | No | No | Yes | No: 122 random bits |
| UUID v7: time first | 16 bytes | No | Yes, if clocks agree | Yes | Partly: the time shows |
| Snowflake: 64 bits | 8 bytes | Only to hand out machine ids | Yes, if clocks agree | Yes | Partly: time and machine show |
The measures above come from the running model. This table states what each method gives by design.
What just happened
Nothing yet. Start traffic or run an experiment.
What this model simplifies
- An index page here holds 32 keys, so splits show sooner. Real pages hold hundreds, and the effect is the same.
- Only the leaf pages of the index are modelled. The pages above them are small and usually stay in memory.
- A row whose server has no numbers fails at once. A real server would wait for a timeout first.
- Changing how IDs are made, or splitting the rows, starts with empty tables, so each setup is measured from its start.