UUID v4 vs. UUID v7: Why Time-Ordered UUIDs Are Taking Over Databases
Why time-ordered UUID v7 has become the modern standard for distributed systems, eliminating B-tree database index fragmentation while preventing ID enumeration attacks.
Sarah Jenkins
Security Lead
For over two decades, UUID v4 (randomly generated 128-bit identifiers) has been the default standard for generating unique primary keys in distributed databases. However, at scale, completely random UUIDs severely degrade database write performance. In 2026, UUID v7 has officially taken over as the preferred database primary key standard.
The Hidden Cost of UUID v4: B-Tree Index Fragmentation
Relational databases like PostgreSQL, MySQL, and SQLite use B-tree index structures to maintain primary key indexes. Because UUID v4 values are entirely random, new insertions land at unpredictable, scattered locations throughout the index tree. This causes:
- Frequent Page Splits: Storage pages constantly split to accommodate random keys, doubling disk I/O.
- Index Cache Eviction: The working set of the index cannot fit in RAM, forcing constant reads from disk.
- Bloated Storage Footprints: Fragmented index trees consume up to 40% more disk storage than sequential keys.
The UUID v7 Solution: Time-Ordered Monotonicity
UUID v7 solves this architectural challenge by embedding a 48-bit millisecond Unix timestamp at the front of the identifier, followed by high-entropy cryptographic randomness. Because newly generated UUID v7 keys are naturally sequential, new database records append neatly to the end of the B-tree index without causing fragmentation.
Frequently Asked Questions
Does UUID v7 expose predictable sequence numbers like auto-increment IDs?
No. While the timestamp is chronological, the remaining 74 bits consist of cryptographic randomness, preventing attackers from predicting neighboring IDs or enumerating user records.
Can I generate UUID v7 directly in the client browser?
Yes. Using modern JavaScript's crypto.getRandomValues() and Date.now(), UUID v7 strings can be generated in sub-microsecond time inside the browser.
Conclusion
Switching to time-ordered UUIDs optimizes database query performance and simplifies distributed architecture. Generate instant v4 and v7 identifiers with our client-side UUID Generator and decode timestamps with our Epoch Converter.
Enjoyed this read?
Get monthly updates on privacy engineering and web performance straight to your inbox.