Interview's MateSystem Design
Interview's Mate

System Design

Architecture & trade-offs

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
All topics/Distributed Locks & Unique IDs
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
Practice in AI HLD
Subtopics in Distributed Locks & Unique IDs (2)
OverviewLocks & FencingSnowflake & IDs

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
Previous subtopic
Distributed Locks & Fencing Tokens
Back to overview
Full Distributed Locks & Unique IDs Lesson