Side-by-side
| Dimension | UUID v4 | UUID v7 |
|---|---|---|
| Random bits | 122 | 74 |
| Time-sortable | No | Yes, to the millisecond |
| Index locality | Random inserts | Append-like inserts |
| Creation time leaked | No | Yes |
| Standard | RFC 4122 | RFC 9562 |
| Library support | Universal | Growing but not universal |
| Same-ms ordering | Not applicable | By random suffix, not strict |
Database keys: v7 usually wins
Random keys are the worst case for a B-tree index: every insert touches a different leaf page, and the index grows faster because pages split at random fill levels. Time-ordered keys append near the right edge, matching how an auto-increment key behaves while still being unguessable.
The advantage is workload-dependent. For a table with thousands of rows, either works. For millions of inserts per day, the difference in write amplification and cache efficiency is measurable.
Privacy and predictability
v7 leaks creation time to the millisecond. For a public post ID or a share link, that may reveal more than you want — when the record was created, how active the system is, and roughly how many records exist between two IDs. v4 leaks nothing.
Conversely, v4 is fully random, which makes it a better fit for capability tokens and public identifiers. Neither is a substitute for a cryptographically random secret of appropriate length.
Operational considerations
- Check library support: many older ORMs and databases understand v4 but treat v7 as an opaque string, which is fine if the column is
uuidorvarchar. - Some databases have native
uuidtypes that validate version nibbles; confirm v7 is accepted before migrating. - If you need strict monotonicity within a millisecond, use a ULID implementation with a monotonic counter, or add a sequence column.
- Migration is one-way in practice: once v7 IDs exist, do not expect all consumers to parse them as v4.
A common compromise: v7 for internal primary keys, v4 for public-facing tokens. Both are UUIDs, so the same column type can hold them, but document which version is allowed where.