UUID v4 and UUID v7 both produce 128-bit universally unique identifiers in the familiar 8-4-4-4-12 hexadecimal format, but they differ fundamentally in how those bits are allocated. UUID v4, defined by RFC 4122, fills 122 of its 128 bits with cryptographically secure random data, producing identifiers with no inherent ordering or embedded information. UUID v7, introduced in RFC 9562 (published May 2024), dedicates the first 48 bits to a Unix-epoch millisecond timestamp and fills the remaining bits with random data, creating values that are naturally sorted by creation time while maintaining the same UUID format and size.
The practical impact of this difference is most visible in database performance. When UUID v4 values are used as primary keys in B-tree indexed tables, their randomness causes inserts to land at arbitrary positions in the index, leading to frequent page splits, poor cache utilization, and write amplification. UUID v7 values, being time-ordered, are inserted near the end of the index in roughly monotonic order, resulting in sequential writes, fewer page splits, and dramatically better insert throughput. Benchmarks consistently show 2x to 10x improvements in insert-heavy workloads when switching from UUID v4 to UUID v7.
From a compatibility standpoint, UUID v7 is a drop-in replacement for UUID v4 in almost every system. Both use the same 128-bit size, the same string format, and the same database column types. The version nibble changes from 4 to 7, but all compliant UUID parsers handle this gracefully. This makes UUID v7 one of the easiest performance upgrades available for systems that already use UUID v4 as their primary key strategy.
| Property | uuid | uuidv7 |
|---|---|---|
| Bit Length | 128 | 128 |
| Output Length | 36 | 36 |
| Encoding | hex (8-4-4-4-12) | hex (8-4-4-4-12) |
| Sortable | No | Yes |
| Timestamped | No | Yes |
| Monotonic | No | Yes |
| Crypto Random | Yes | Yes |
| Standard | RFC 4122 | RFC 9562 |
UUID v7 is the better choice for new projects in almost every scenario, offering the same format compatibility as UUID v4 with substantially better database performance and built-in chronological ordering. UUID v4 remains perfectly valid for existing systems that are working well, and for the specific case where embedding no timestamp information is a hard requirement for privacy reasons.
Yes. Both are valid 128-bit UUIDs and are stored identically in UUID-typed database columns. The version nibble differs (4 vs 7), but all compliant UUID parsers and databases handle multiple versions in the same column without issues.
Benchmarks typically show 2x to 10x improvement in insert throughput for B-tree indexed tables, depending on the database engine, table size, and workload pattern. The benefit is most pronounced in large tables with millions of rows where index fragmentation from UUID v4 becomes significant.
Not entirely. Auto-incrementing integers are still smaller (8 bytes vs 16 bytes), faster to compare, and simpler for human readability. However, UUID v7 closes the performance gap significantly and adds the benefits of decentralized generation and global uniqueness, making it a strong alternative for most distributed systems.
© 2024 Carova Labs. All rights reserved