DISTRIBUTED SYSTEMS & ARCHITECTURE · SUBTOPIC
Snowflake IDs, UUIDv7 & Ticket Servers
Generate billions of globally unique, time-sortable 64-bit IDs without central bottlenecks.
IntermediatePart of Distributed Locks & Unique IDs
Subtopics in Distributed Locks & Unique IDs (2)
In plain words
Instead of asking one central clerk for the next ticket number, every server stamps [current millisecond + my server number + counter] into one 64-bit number - fast, unique, and naturally sorted by time.
Think of it like…
Order receipts stamped 20261115-Cashier04-0012: unique everywhere and sorted chronologically.
Loading interactive diagram
Loading interactive exercise
Theory & how it works
Why random UUIDv4 hurts B-Tree indexes (and UUIDv7 fixes it)
Random UUIDv4 values scatter inserts across random pages of a B-Tree index, hurting cache hit rates and causing page splits. Snowflake IDs and newer UUIDv7 (timestamp-prefixed) stay roughly increasing, keeping B-Tree inserts clustered at the newest pages!
Key points & practical guide
Summary checklist
- Snowflake = 64 bits, B-Tree friendly, ~4,096 IDs/ms/node
- UUIDv4 = zero coordination, 128-bit, random B-Tree order
- UUIDv7 = 128-bit with leading timestamp for B-Tree friendliness
When to use it
- Sharded databases, tweets/posts/orders IDs, distributed tracing IDs
Watch out for
- NTP clock backward jumps in Snowflake - wait or use a clock-drift sequence bit instead of generating duplicates
Quick check
Loading quiz