FreeAI.DevTools

UUID v7 Generator

What a UUID v7 is, when to use it, and a generator scoped to this version. Runs in your browser.

What is a UUID v7?

A UUID v7 is a time-ordered 128-bit identifier defined in RFC 9562, published in May 2024. Its first 48 bits hold a Unix timestamp in milliseconds, followed by the version and variant bits and 74 random bits. Because values sort by creation time, v7 keys keep B-tree indexes compact.

Version:

Why B-tree indexes love the timestamp prefix

The 48-bit millisecond timestamp sits at the front of the value, so every new v7 UUID is greater than every one minted in an earlier millisecond. Inserts therefore land on the rightmost leaf page of a B-tree primary-key index, the same access pattern as an auto-increment integer. The index stays dense, the hot pages stay in cache, and write amplification drops. On Postgres bulk-insert benchmarks we have run, swapping v4 primary keys for v7 recovers most of the gap to serial bigint keys. Within a single millisecond, ordering falls to the random bits; RFC 9562 describes optional monotonicity techniques, a dedicated counter or monotonic random increment, for generators that must guarantee strict ordering inside the same millisecond.

Migrating from v4, and one caveat

Migration is low-friction because v7 is format-compatible with v4: same 128 bits, same 8-4-4-4-12 text form, same uuid column type in Postgres and MySQL. You can switch the generator for new rows and leave existing v4 values in place, since the two versions coexist in one column without conflict. New inserts immediately stop fragmenting the index, and the benefit compounds as v7 rows come to dominate the table.

The caveat: the timestamp prefix reveals when each row was created to anyone who can read the ID. For most internal keys that is harmless, but if creation time is sensitive, keep exposing v4 at the API boundary and use v7 internally.

Frequently asked

Is UUID v7 better than v4 for Postgres?
For primary keys on write-heavy tables, yes. The 48-bit timestamp prefix makes inserts append to the rightmost B-tree page instead of scattering randomly, which keeps the index compact and the buffer cache effective. For IDs that never key an index, v4 and v7 perform identically.
Is UUID v7 an official standard?
Yes. UUID v7 is defined in RFC 9562, published in May 2024, which obsoletes RFC 4122. It is not a draft or a vendor extension. Native generators have landed across ecosystems, including PostgreSQL 18's uuidv7() function and libraries in every major language.
Can two UUID v7 values collide in the same millisecond?
Collisions remain practically impossible: after the 48 timestamp bits and 6 version and variant bits, 74 random bits remain, about 1.9 x 10^22 combinations per millisecond. What can happen is that same-millisecond values sort in random order, which RFC 9562 addresses with optional counter-based monotonicity for generators that need strict ordering.

More in this series

// The subscription desk

The Inference Report

The weekly briefing for AI engineers: model releases, pricing moves, benchmarks, and the news that changes what you should build with and what it costs. Every Tuesday, 5-minute read. No fluff.

Join AI engineers who stopped overpaying for tokens. Unsubscribe anytime.