100% Client-Side Computation • Zero Server Logs • Instant Execution
Curious TechieDev Toolbox
← All Guides/Identifiers•8 min read

What is a UUID? Versions, Entropy & RFC 9562

How distributed systems generate 128-bit keys without coordination: UUID v4 randomness vs time-ordered UUID v7 indexing.

ⓘKey Takeaways
  • A UUID is a 128-bit label standardized by RFC 9562 (superseding RFC 4122).
  • UUID v4 relies on 122 bits of cryptographically secure random entropy, minimizing collision risk to near-zero.
  • UUID v7 incorporates a 48-bit Unix timestamp prefix, delivering natural B-tree index locality for high-write databases.
  • UUIDs allow distributed microservices to generate unique primary keys without database round-trips.

Distributed databases and microservices architectures require distributed primary keys that can be generated independently on separate servers without a central coordinating bottleneck. That standard is the Universally Unique Identifier (UUID / GUID).

1. The 128-Bit UUID Structure

Standardized by RFC 9562, a UUID consists of 16 octets (128 bits) represented as 32 hexadecimal characters grouped into five hyphen-separated blocks:

xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
M = Version number (e.g. 4 or 7) | N = Variant (typically 8, 9, a, or b)

2. Collision Mathematics & Safety

With 122 bits of pure randomness in UUID v4 (2^122 ≈ 5.3 × 10^36 possible IDs), you would need to generate 1 billion UUIDs every second for 85 years before having a 50% chance of a single collision.

3. UUID v4 (Random) vs UUID v7 (Time-Ordered)

While UUID v4 is completely random, the new standard UUID v7 places a 48-bit Unix millisecond timestamp in the most significant bits, followed by 74 bits of randomness. This guarantees that IDs naturally sort chronologically.

4. Database Indexing & B-Tree Fragmentation

Inserting random UUID v4 keys into primary key B-Trees causes random page splits and heavy cache eviction. UUID v7 inserts sequentially at the end of the index like an auto-incrementing integer, resulting in up to 10x faster insert performance in PostgreSQL, MySQL, and SQLite.