backendsystem-design
How Twitter Generates Unique IDs at Scale — Snowflake ID
July 15, 2025
While diving deeper into system design, I came across Twitter's Snowflake ID generation strategy — and it's absolutely fascinating!
What is a Snowflake ID?
A 64-bit unique ID generated without needing any coordination (like a distributed cache or database).
- Time-ordered and roughly sortable
- Highly performant for write-heavy systems
- No central bottlenecks
Snowflake ID Structure
- 1 bit – Sign bit (always 0)
- 41 bits – Timestamp in milliseconds (~69 years of uniqueness)
- 10 bits – Machine/Data center ID (up to 1,024 nodes)
- 12 bits – Sequence number (ensures uniqueness within the same millisecond)
64-bitTwitter Snowflake ID — Bit Layout
1
41
10
12
0
TIMESTAMP
MACHINE ID
SEQUENCE
1 bit
41 bits
10 bits
12 bits
Sign Bit
›Always 0
›Ensures positive integers
Timestamp
›Milliseconds since custom epoch
›Range: ~69 years
Machine ID
›Unique per server node
›Up to 1024 machines
Sequence
›Increments per millisecond
›Max 4096 IDs/ms
total capacity: 263 unique IDstime-sortable by defaultno coordination required
What problem does it solve?
- Enables decentralized unique ID generation
- Avoids bottlenecks from shared databases or caches
- Ensures chronological ordering — perfect for feeds, logs, and timelines
Compared to other ID strategies
- Auto-increment IDs – not scalable in distributed systems
- UUIDs – globally unique but too long and not chronologically ordered