Back to all guides
Developer Tools7 min read

UUID v4 vs. UUID v7: The Evolution of Universally Unique Identifiers in Modern Databases

A technical analysis of UUID versions: RFC 9562 standards, v4 random entropy vs. v7 timestamp-ordered sortability, and B-tree index clustering.

A
Aakash Sharma
Creator of Softnag & Full-Stack Developer
Published: July 31, 2026Updated: August 16, 2026
UUID v4 vs. UUID v7: The Evolution of Universally Unique Identifiers in Modern Databases - Developer Tools Illustrated Guide
Developer Tools

Time-ordered monotonic UUIDv7 versus random UUIDv4 database index clustering

Share this guide

For decades, database architects faced a dilemma: use auto-incrementing sequential integers (`1, 2, 3...`) for blazing fast B-tree index inserts, or use 128-bit UUIDs for decentralized primary key generation across distributed microservices.

With the formal ratification of **RFC 9562**, the database community has a definitive solution: **UUID v7**.

Why Sequential Auto-Increment IDs Fail at Scale#

Sequential integers (`BIGINT`) introduce severe architectural bottlenecks:

  • Centralized Bottleneck: Only the primary database master can allocate the next ID, preventing offline creation.
  • Enumeration Vulnerabilities: Predictable IDs allow malicious scrapers to crawl `/user/1`, `/user/2`, etc.
  • Sharding Complexity: Merging tables from multiple database shards results in primary key collisions.

UUID v4: Pure Randomness and Collision Probabilities#

UUID v4 solved the decentralization problem by generating 122 bits of cryptographically secure pseudo-random entropy (e.g. `c7b8d4e0-3e28-4e1b-9f4a-8d1e2f3a4b5c`).

To generate a single collision with UUID v4, you would need to generate **1 billion UUIDs per second for approximately 85 years**.

The Hidden Cost of UUID v4: B-Tree Index Fragmentation#

Because UUID v4 is completely random, inserting new rows into a clustered B-Tree index (like PostgreSQL, MySQL InnoDB, or SQLite) requires inserting keys into random physical memory pages.

As tables grow beyond available RAM, this causes constant disk thrashing, page splits, and degraded write throughput.

UUID v7 (RFC 9562): Time-Ordered Sortable Entropy#

UUID v7 embeds a 48-bit Unix timestamp (millisecond precision) into the most significant bits, followed by 74 bits of cryptographically secure random entropy:

text
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                           unix_ts_ms                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|          unix_ts_ms           |  ver  |       rand_a          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|var|                        rand_b                             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                            rand_b                             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Database Benchmark: Insert Performance Comparison#

Because UUID v7 values are monotonically increasing over time, new database inserts are always appended to the rightmost leaf of the B-Tree index.

Database benchmarks in PostgreSQL demonstrate that **UUID v7 achieves up to 4x faster insert throughput** compared to UUID v4 on tables with over 50 million records.

Key Takeaways & Best Practices
  • UUID v4 is completely random and causes severe B-Tree index fragmentation at scale.
  • UUID v7 (RFC 9562) embeds a 48-bit timestamp for natural temporal ordering.
  • UUID v7 combines the performance of sequential IDs with the security of UUIDs.
  • Modern database designs should adopt UUID v7 as the primary key standard.

Final Thoughts

Generate single or batch UUID v4 and UUID v7 identifiers directly in your browser with Softnag’s UUID Generator.

Related Technical Guides

View all 40 guides →