Skip to content
Optimal Lab

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

41 bits time: 1000 ms10 bits machine: 712 bits sequence: 0

id = 4194332672

Ids made by three servers, sorted

idmsmachineseq
4194316288100030
4194316289100031
4194332672100070
4198526976100170
41985474561001120
4202704896100230
4202704897100231
42069360641003120

Time 1000 ms, machine 7, sequence 0 → 4194332672

  1. 1

  2. 2

  3. 3

  4. 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.