For years, UUID v4 — the fully random version — was the default answer to "I need a unique ID." It works, but it has a quiet cost: random IDs scatter database writes, fragment indexes, and carry no information about when they were created. UUID v7, standardized in RFC 9562 in May 2024, keeps the global uniqueness of v4 while fixing those problems. It is now the version most new projects should reach for.
This guide explains how UUID v7 is structured, why v4 became a problem at scale, what v7 fixes, and the cases where v4 is still the right choice.
How UUID v7 is structured
A UUID is 128 bits, usually written as 36 characters of hex with dashes. In v7, the first 48 bits are a Unix timestamp in milliseconds — the number of milliseconds since January 1, 1970. The next 4 bits are the version nibble, set to 7. The remaining 74 bits are random, generated from a cryptographic random source. Because the timestamp comes first, UUIDs sort in the order they were created: sorting v7 IDs lexicographically is the same as sorting them chronologically.
A v7 ID looks like this: 0196a3f2-4b1c-7d8e-9f01-23456789abcd. The leading digits encode the creation time; the 7 at the start of the third group marks the version. The 74 random bits still give an enormous collision space — about 2^74 possible values per millisecond — so uniqueness in practice is as strong as v4's.
One subtlety: within the same millisecond, ordering between IDs is random, not sequential. The standard allows an optional monotonic counter for strict ordering inside a millisecond, but plain random fill is the common case, and it is enough for nearly every application.
Why v4 became a problem
UUID v4 is 122 bits of pure randomness. That is great for unpredictability and terrible for databases. Most databases store rows in a B-tree index ordered by primary key. Inserting random keys means every insert lands at a random position in the tree: pages split, the index fragments, and write throughput drops as the table grows. This is known as the random-insert penalty, and it is the main reason teams historically chose auto-incrementing integers despite their drawbacks.
Random IDs have a second cost: they carry no ordering information. To list "the ten most recent orders" with v4 keys you need a separate created_at column and an index on it. With v7, the ID itself is the timeline — ordering by ID is ordering by creation time, and the newest rows are simply the largest IDs.
What v7 fixes
Because v7 IDs increase over time, new inserts land at the end of the index instead of at random positions — close to the append-friendly behavior of auto-incrementing integers, but without a central counter. That means less index fragmentation, fewer page splits, and better write performance, while keeping the key benefit of UUIDs: any server, anywhere, can generate an ID without coordinating with anyone else.
Time-ordering also makes debugging and operations easier. You can look at an ID and know roughly when the record was created, sort logs or exports by ID to get chronological order, and partition or archive old data by ID range. None of that is possible with v4.
v7 vs v4 vs ULID vs NanoID
UUID v7 is not the only modern identifier. ULID is also time-ordered, but uses Crockford base32 encoding (26 characters, no dashes) and a 48-bit timestamp with 80 random bits — similar properties, different format, and not an official UUID. NanoID is a compact, URL-safe random string with no timestamp and no standard layout, best for short public-facing IDs like invite codes.
| UUID v7 | UUID v4 | ULID | NanoID | |
|---|---|---|---|---|
| Sortable by time | Yes | No | Yes | No |
| Standard | RFC 9562 | RFC 9562 | Community spec | None |
| Format | 36-char hex + dashes | 36-char hex + dashes | 26-char base32 | 21-char URL-safe |
| Timestamp embedded | Yes (ms) | No | Yes (ms) | No |
| Best for | Database primary keys | Opaque IDs | Sortable string IDs | Short public IDs |
When NOT to use v7
The timestamp in a v7 ID is visible to anyone who sees the ID. If your IDs appear in public URLs and you do not want people to infer when a record was created — or to enumerate records by guessing nearby IDs — v4's opacity is a feature, not a bug. Similarly, if your system already uses v4 everywhere and has no performance problem, there is no urgent reason to migrate.
Also remember that v7's timestamp has millisecond precision. If your application creates many IDs in the same millisecond and needs strict creation order between them, you need the monotonic variant or a separate sequence — plain v7 only guarantees ordering across different milliseconds.
Migrating to v7
For new tables, use v7 as the primary key from day one — it stores in the same uuid column type as v4 in Postgres, MySQL, and SQL Server, so there is no schema cost. For existing tables, the pragmatic path is to leave old v4 rows alone and generate v7 only for new rows; the two versions coexist in the same column, though you cannot rely on ordering across the boundary between old and new rows. A full backfill is rarely worth it.
You can generate v7 IDs, ULIDs, and NanoIDs side by side with the UUID v7 Generator, and compare them with classic random IDs from the UUID Generator.
Try it yourself
Frequently asked questions
Is UUID v7 random?
Partly. The first 48 bits are a millisecond timestamp, and the remaining 74 bits are random. That gives about 2^74 possible values per millisecond — far more than enough for uniqueness — while keeping IDs time-ordered.
Can I use UUID v7 as a database primary key?
Yes — that is its main use case. Time-ordered inserts land at the end of the B-tree index instead of at random positions, which reduces fragmentation and improves write performance compared to v4. It stores in the same uuid column type as v4.
Does UUID v7 reveal when the ID was created?
Yes. The first 48 bits are the creation time in Unix milliseconds, and anyone who sees the ID can decode it. If that is a privacy concern — for example IDs in public URLs — use UUID v4 instead, which carries no timestamp.
Is UUID v7 part of an official standard?
Yes. UUID v7 was standardized in RFC 9562, published in May 2024, which also standardized versions 6 and 8 and updated the older versions. It is supported by the major UUID libraries in most languages.
UUID v7 vs ULID — which should I choose?
Both are time-ordered with similar properties. Choose v7 if you want an official standard, a native uuid column type in your database, and compatibility with existing UUID tooling. Choose ULID if you prefer a shorter, URL-safe string format and do not need UUID compatibility.