StreamHub generates IDs for streams, clips, chat messages, and payments — billions per month. Auto-increment IDs are simple but leak business metrics and fail across shards. Snowflake IDs give global uniqueness, time ordering, and no central coordinator.
Requirements
What a good ID generator provides
- Uniqueness: No collisions across all services and regions.
- Sortability (optional): Time-ordered IDs improve DB index locality and pagination.
- Generation speed: 10K+ IDs/sec per worker without DB round trip.
- No single point of failure: Decentralized generation preferred.
- Compact: 64-bit integer fits in BIGINT; UUID is 128-bit (16 bytes).
Approach comparison
| Approach | Pros | Cons |
|---|---|---|
| Auto-increment (DB) | Simple, sequential, index-friendly | Single-writer bottleneck; leaks count; sharding breaks it |
| UUID v4 (random) | No coordination; 122 bits of randomness | Not sortable; index fragmentation; 16 bytes |
| UUID v7 (time-ordered) | Sortable; no coordination | Still 16 bytes; newer standard |
| Snowflake (64-bit) | Sortable, compact, decentralized | Clock skew breaks ordering; needs worker ID assignment |
| DB sequence per shard | Simple within shard | Global uniqueness needs shard prefix; coordination on shard assign |
Auto-increment (DB)
ProsSimple, sequential, index-friendlyConsSingle-writer bottleneck; leaks count; sharding breaks itUUID v4 (random)
ProsNo coordination; 122 bits of randomnessConsNot sortable; index fragmentation; 16 bytesUUID v7 (time-ordered)
ProsSortable; no coordinationConsStill 16 bytes; newer standardSnowflake (64-bit)
ProsSortable, compact, decentralizedConsClock skew breaks ordering; needs worker ID assignmentDB sequence per shard
ProsSimple within shardConsGlobal uniqueness needs shard prefix; coordination on shard assign
64-bit Snowflake ID
41 bitstimestamp (ms)
5 bitsdatacenter ID
5 bitsworker ID
12 bitssequence
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 3 sections
- Snowflake layout
- Worker ID assignment
- StreamHub ID strategy
Test yourself
Answer these before moving on — recall is what makes it stick.