SD System Design In Depth
0%
lesson system-designidentifiersdata-modeling

UUID, ObjectId, and Snowflake

Module 2.2: NoSQL Architectures, Partitioning & IDs Updated Sep 17, 2026
📄 Cheat Sheet
The effect of Random UUID on database performance
Hussein Nasser The effect of Random UUID on database performance Watch on YouTube ↗

Explains, at the page and buffer-pool level, why random 128-bit keys hurt B-tree inserts and what time-ordered IDs fix: the core trade-off in this unit's comparison table.

0:00 / --:--

Byte-Level Anatomical Breakdown of Distributed IDs

Comparing distributed identifier standards requires examining their exact binary memory footprints and bitwise layout:

1. UUID Family (RFC 9562, which obsoletes RFC 4122) — 128 Bits (16 Bytes)

  • UUIDv4: 122 random bits (RFC 9562 recommends a CSPRNG, but actual quality depends on the implementation), 4 bits of version (0100), and 2 bits of variant (10). Total combinations: 2122 ≈ 5.3 × 1036. Collision probability is negligible, but randomness creates chaotic memory layouts.
  • UUIDv7 (Modern Standard): Solves UUIDv4's B-Tree problem by encoding a 48-bit Unix millisecond timestamp at the highest-order bits, followed by version and 74 random bits. Highly index-friendly while maintaining 128-bit global uniqueness.

2. MongoDB ObjectId — 96 Bits (12 Bytes)

Consists of 12 bytes formatted as 24 hexadecimal characters:

  • 4 Bytes: Unix timestamp in seconds.
  • 5 Bytes: Process unique value (generated once per machine/process).
  • 3 Bytes: Monotonically incrementing counter initialized to a random value.

3. Twitter Snowflake — 64 Bits (8 Bytes)

flowchart LR S1["1 Bit: Sign (Always 0)"] --- S2["41 Bits: Millisecond Timestamp (69 Years)"] S2 --- S3["10 Bits: Machine / Datacenter ID (1,024 Nodes)"] S3 --- S4["12 Bits: Sequence Counter (4,096 IDs/ms)"]

Bitwise Memory & Index Performance Comparison

IdentifierSize (Bytes)B-Tree LocalityTime Sortable?Throughput per Node
UUIDv416 bytes (128 bits)Poor (random inserts; worst for clustered indexes such as InnoDB and SQL Server, milder for PostgreSQL heap tables where only the index suffers)NoPractically unlimited (local PRNG)
UUIDv716 bytes (128 bits)Excellent (append-only)Yes (millisecond)Practically unlimited
ObjectId12 bytes (96 bits)GoodYes (second)16.7M IDs / sec per process (224 counter)
Snowflake8 bytes (64 bits)Optimal (fits in BIGINT)Yes (millisecond)4,096,000 IDs / sec
Check yourself Question 1 of 3
Why UUIDv7 indexes well recall
From: Byte-Level Anatomical Breakdown of Distributed IDs

What makes UUIDv7 index-friendly compared with UUIDv4, while keeping the same 128-bit size?

Snowflake ID: 1 + 41 + 10 + 12 bits

A Snowflake ID packs a sign bit (always 0), 41 bits of milliseconds since a custom epoch, a 10-bit worker ID and a 12-bit per-millisecond sequence into one signed 64-bit integer. IDs from one worker are strictly increasing, and IDs from all workers sort roughly by time.

Paste an ID (or click one in the log) to decode it with the current epoch.
Event log (click an ID to decode it)

Key Takeaways

UUIDv4 wastes storage (16 bytes) and causes random B-tree page splits; UUIDv7 solves this with a 48-bit timestamp prefix.
MongoDB ObjectId packs 12 bytes: 4s timestamp + 5-byte process unique + 3-byte counter.
Snowflake IDs fit into standard 64-bit integers, providing natural chronological sorting and high memory compactness.
Was this lesson helpful? Spot an issue or have a suggestion? Let us know on GitHub.
Report an issue