System Design · interactive
Unique IDs at scale
An auto-increment id needs one database to hand out numbers. A random UUID needs no coordination but doesn't sort. Snowflake-style ids pack time, machine and a counter into 64 bits: any server makes them alone, and they still sort by time.
64 bits
0000000000000000000000000000000011111010000000000111000000000000
id = 4194332672
Ids made by three servers, sorted
| id | ms | machine | seq |
|---|---|---|---|
| 4194316288 | 1000 | 3 | 0 |
| 4194316289 | 1000 | 3 | 1 |
| 4194332672 | 1000 | 7 | 0 |
| 4198526976 | 1001 | 7 | 0 |
| 4198547456 | 1001 | 12 | 0 |
| 4202704896 | 1002 | 3 | 0 |
| 4202704897 | 1002 | 3 | 1 |
| 4206936064 | 1003 | 12 | 0 |
Time 1000 ms, machine 7, sequence 0 → 4194332672
1 2 3 4 Ids sort by millisecond. Within one millisecond, order between machines isn't real time. Clocks that jump backwards are the main risk.
Compared with UUIDv4: half the size, and indexes stay in insert order.
In production
Tools and technologies
Most large systems generate ids without a central counter.
Not tied to one language — use these names when you search docs or design a system.