UUID v7 Generator
UUID v7 is the modern, time-ordered UUID — a Unix millisecond timestamp followed by random bits. The right primary key for new tables.
Show all 0
Why v7 changed the game
For two decades, advice on UUIDs as primary keys went: "don't, they fragment your index." That was true for v4. v7 fixes it. The first 48 bits are a millisecond timestamp, so consecutive UUIDs cluster together in B-tree storage — the same access pattern as a bigint identity column.
Bit layout
┌─────────────────────────────────────────────────────────────────┐
│ 48-bit Unix ms timestamp │ ver │ 12-bit rand │ var │ 62-bit rand│
└─────────────────────────────────────────────────────────────────┘
most significant ──────────────────► least significant Real-world impact
A 100M-row PostgreSQL table with v4 primary keys typically inserts ~2–5× slower than the same table with v7 keys, because each insert has to read and write a different B-tree leaf page. v7's locality reduces that to near-sequential I/O.
Code
// JavaScript / TypeScript
import { v7 } from "uuid";
v7(); // "01928a47-3b30-7c5e-9d1a-f0b8c4a7e923"
// PostgreSQL 18+
SELECT uuidv7();
// Python (uuid-utils)
from uuid_utils import uuid7
uuid7() When NOT to use v7
- When the timestamp must not be visible (privacy-sensitive IDs).
- When you need strict monotonic ordering across processes — v7 only guarantees per-process order; clock skew between hosts can interleave UUIDs.
FAQ
What is a UUID v7?
UUID v7 (RFC 9562, 2024) is a time-ordered UUID. The first 48 bits are a Unix timestamp in milliseconds; the remaining 74 bits (after version/variant) are random. Lexicographic sort matches chronological sort.
Why is v7 better than v4 for primary keys?
Random UUIDs (v4) used as B-tree primary keys cause page splits all over the index — every insert touches a different page. v7's monotonically-increasing prefix means new rows append to the rightmost index page, dramatically improving insert throughput in PostgreSQL, MySQL/InnoDB, and most other databases.
Does v7 leak time information?
Yes. The first 48 bits encode the millisecond when the UUID was generated, so anyone with a v7 UUID can recover its creation time. If that's sensitive, use v4 instead.
Is v7 supported in databases yet?
It's just a UUID — every database that stores UUIDs handles it fine. PostgreSQL added a built-in uuidv7() in v18. For older versions, generate v7 in your application code (this tool, or any modern UUID library).
v6 vs v7 vs ULID?
v6 reorders v1's bits to be sortable; v7 throws away v1 entirely and uses a clean Unix-millisecond layout. v7 is the modern choice. ULID is a separate spec with similar goals but a different alphabet (Crockford base32). For interop with anything that accepts UUIDs, v7 wins.