UUID v7 vs v4: Time-Ordered IDs Explained
Universally unique identifiers have been the workhorse of distributed systems for two decades, and version 4 — pure randomness — was the default almost everywhere. In May 2024, RFC 9562 standardized a new version that keeps the randomness but adds something v4 never had: time ordering. This guide explains what UUID v7 is, why database engineers care, where native support already exists, and when the old v4 is still the right call.
What is UUID v7?
A UUID is 128 bits, usually written as 32 hex digits in five groups (8-4-4-4-12). In v7, the first 48 bits are the current Unix timestamp in milliseconds, the next 4 bits mark the version (0111, i.e. 7), then 12 bits of sub-millisecond randomness, 2 variant bits, and 62 more random bits. The result looks like any other UUID — 01976f2e-8c3a-7b1d-9e4f-2a5c6d7e8f90 — but the leading digits march forward with time, so the IDs sort in creation order.
Version 4, by contrast, is 122 random bits with no time component at all. Two v4 IDs tell you nothing about which came first. That was fine for uniqueness, but it wastes an opportunity: many systems sort by ID as a proxy for creation order, and v4 simply cannot do that.
Why v7 wins for database primary keys
The killer argument for v7 is index behavior. Database primary keys usually sit on a B-tree index, and B-trees love ordered inserts: each new key appends to the rightmost leaf and the tree grows cleanly. Random v4 keys land on random leaves, forcing constant page splits and leaving fragmented, half-empty pages behind. On write-heavy tables this slows inserts and bloats the index — a cost teams used to accept as the price of distributed ID generation.
UUID v7 gives you both: globally unique IDs minted independently on any server, with the insert pattern of a well-behaved sequential key. Benchmarks from the database community consistently show v7 inserts outperforming v4 on large tables, with measurably smaller indexes. It is the rare upgrade that is strictly better for the database-primary-key use case.
Native support is here
- PostgreSQL 18 added built-in UUID v7 generation, so you can default a primary key column to time-ordered IDs directly in SQL.
- Python 3.14 ships uuid.uuid7(), making v7 a one-liner in the world's most popular backend language.
- Java, Go, and Rust ecosystems have mature v7 libraries, and most ORMs are adding first-class support.
- Browser generation works via the Web Crypto API — try it live with ToolsOfWeb's UUID v7 Generator, which produces up to 1,000 IDs per batch with formatting options.
When to still use v4
UUID v7 is not a universal replacement. The embedded timestamp is visible to anyone holding the ID — if the creation time of a record is sensitive (public-facing tokens, invitation links, anything where timing leaks information), v4's pure randomness is the safer choice. v4 is also the conservative option in ecosystems without v7 libraries, and there is no reason to migrate existing working v4 keys: the benefit applies to new inserts, so adopt v7 for new tables and services and leave the rest alone.
One more consideration: v7's monotonicity is only as good as your system clock. In environments with clock skew across servers, two machines can mint IDs whose timestamps disagree — uniqueness is never at risk (the 74 random bits protect that), but strict global ordering can wobble. For most applications this is a non-issue; for systems that need guaranteed ordering across data centers, pair v7 with a clock-discipline strategy or use a dedicated ID service.
Generating v7 IDs in bulk
For seed data, test fixtures, or one-off batches, open the UUID v7 Generator: pick v7 (or v4), choose a count up to 1,000, and select hyphenated or compact formatting with optional uppercase. Every ID is generated with the Web Crypto API in your browser — nothing is uploaded. The built-in inspector can decode any UUID's version, variant, and embedded timestamp, which is handy for auditing IDs you find in the wild.
FAQs
Is UUID v7 officially standardized?+
Yes. RFC 9562, published in May 2024, defines UUID versions 6, 7, and 8. Version 7 is the recommended time-ordered format, and native support is landing across major platforms.
Does UUID v7 sort in creation order?+
Yes — the first 48 bits are a millisecond Unix timestamp, so sorting UUID v7 values lexicographically is the same as sorting by creation time (for IDs generated within the timestamp range).
Should I migrate existing v4 primary keys to v7?+
For most tables it is not worth a migration: the benefit comes from ordered inserts going forward. Use v7 for new tables and services; leave working v4 keys alone.
Can I generate UUID v7 in the database itself?+
PostgreSQL 18 added native UUID v7 generation. Older databases can use extensions or generate IDs in the application layer — for example with the free UUID v7 generator linked in this guide.
Is UUID v7 safe to expose in public URLs?+
Mostly yes, but remember the creation time is encoded in the ID. If the timing of record creation is sensitive, prefer v4 for public-facing identifiers.
For more developer utilities, see ToolsOfWeb's Regex Tester and JSON Formatter.
