UUID v7 Generator — Time-Ordered UUIDs for Database Primary Keys
Generate UUID v7 identifiers online (RFC 9562). The first 48 bits encode a Unix millisecond timestamp, so v7 UUIDs sort lexicographically by creation time — dramatically better as a database primary key than v4. Bulk generate up to 1000 and inspect the embedded timestamp for each. 100% local.
Last updated:
CommentsClick Generate to produce time-ordered UUIDv7 identifiers. Each ID embeds a millisecond timestamp in its first 48 bits so IDs sort chronologically — ideal as database primary keys. Runs entirely in your browser via crypto.getRandomValues.
UUID v7 (RFC 9562, published May 2024) embeds a millisecond Unix timestamp in the first 48 bits, followed by 74 random bits. Values sort lexicographically by creation time — making them a much better fit for database primary keys than UUID v4. Need pure-random UUIDs instead? Use the UUID Generator.
| UUID v7 | Embedded timestamp | |
|---|---|---|
| 01a0b3ee-7263-76a6-a00b-3573f823e351 | 2026-09-18 09:52:23Z | |
| 01a0b3ee-7263-757e-b982-490d5769942e | 2026-09-18 09:52:23Z | |
| 01a0b3ee-7264-7045-96a7-eda3efdc385e | 2026-09-18 09:52:23Z | |
| 01a0b3ee-7264-7fe3-a1f5-a70b520cc02e | 2026-09-18 09:52:23Z | |
| 01a0b3ee-7264-7374-86eb-febf508f8afe | 2026-09-18 09:52:23Z |
What is UUID v7 Generator?
UUIDv7 is the modern replacement for UUIDv4 as a database primary key. It looks like a normal UUID but its first 48 bits encode the current Unix time in milliseconds, followed by 74 bits of cryptographic randomness. The result: globally unique identifiers that also sort by creation time — no more random-IO index thrashing, and no more scanning `created_at` to figure out row order.
How to generate UUIDv7
- 1Click Generate to create a single UUIDv7 with the current timestamp.
- 2For batch generation, increase the count (up to 10,000 at once) — each ID is unique and monotonically increasing within the batch.
- 3Copy any single ID with one click, or copy the whole list as JSON, CSV, or one-per-line.
- 4The tool also shows the embedded timestamp and remaining random bits — useful for verifying implementation correctness.
Use Cases
Primary keys for new tables
Postgres, MySQL, and SQL Server all benefit from time-ordered primary keys — B-tree inserts happen at the tail of the index instead of scattering across pages. UUIDv7 gets you the ordering of a sequence with the distributed-safe uniqueness of a UUID.
Distributed event IDs
Assign IDs to events on the client (offline-first apps, mobile clients, edge functions) without coordinating with a central sequence — and still have them sort chronologically when they eventually sync.
Log correlation IDs
Attach a UUIDv7 to every request as it enters your gateway. It flows through microservices as a trace ID, and log-aggregation tools can order events by ID without needing a separate timestamp field.
Migrate from UUIDv4
New rows go to v7, old rows stay v4. Both are valid 128-bit UUIDs and share the same schema type, so migration is additive — no schema change required.
Code Examples
Generate in Node.js (uuid v9+)
import { v7 as uuidv7 } from "uuid";
const id = uuidv7();
// 01924567-89ab-7cde-8f01-234567890abcGenerate in Python
# Python 3.13+ (uuid.uuid7)
import uuid
id = uuid.uuid7()
# Earlier Python: pip install uuid7
from uuid7 import uuid7
id = uuid7()Generate in Go
import "github.com/google/uuid"
id, err := uuid.NewV7()
fmt.Println(id.String())PostgreSQL 17+
-- Native uuidv7() function
SELECT uuidv7();
-- Column default
CREATE TABLE events (
id uuid PRIMARY KEY DEFAULT uuidv7(),
payload jsonb NOT NULL,
created_at timestamptz DEFAULT now()
);Key Concepts
- UUIDv7 layout
- 128 bits total: 48 bits unix-time-ms | 4 bits version (0111) | 12 bits sub-ms random | 2 bits variant (10) | 62 bits random. That's 74 bits of randomness — 2⁷⁴ ≈ 1.9×10²² possible IDs per millisecond. Collisions are effectively impossible.
- Why not just UUIDv4 + created_at?
- Two problems: (1) v4's random primary keys wreck B-tree performance because inserts scatter across pages. (2) Ordering by `created_at` needs a separate index. UUIDv7 solves both — it's naturally ordered *and* unique.
- ULID vs UUIDv7
- ULIDs predate UUIDv7 and solve the same problem. ULIDs use Crockford Base32 (26 chars), UUIDv7 uses hex (32 chars + dashes). ULIDs are shorter and more URL-friendly; UUIDv7 is an IETF standard (RFC 9562, 2024) with native database support arriving fast.
- Monotonicity within a millisecond
- Multiple IDs generated in the same millisecond need a tiebreaker to stay ordered. Common approach: use the sub-ms field as a counter that increments (with random start), overflowing into the next millisecond if it exhausts. This tool implements that so batch-generated IDs are strictly monotonically increasing.
Tips & Best Practices
- ▸Store UUIDv7 as `uuid` in Postgres and `BINARY(16)` in MySQL. Never store as string — you'll double the size and lose the sort benefit.
- ▸For public-facing IDs (URLs, API endpoints), keep using something opaque (nanoid, short hash). UUIDv7 leaks creation time — sometimes that's fine, sometimes it's a subtle privacy issue.
- ▸If you index UUIDv7 in Elasticsearch or OpenSearch, keep it as `keyword` and set `doc_values: true`. Range queries on the ID range become time-range queries — very efficient.
- ▸Never generate UUIDv7s across servers with unsynchronized clocks. NTP drift of even 100ms breaks the ordering guarantee. In production, run NTP + monitor drift.
Frequently Asked Questions
What makes UUID v7 different from v4?
UUID v4 is fully random — its 122 bits of entropy are great for uniqueness but terrible for database indexes. Every INSERT lands at a random spot in the B-tree, causing page splits and cache misses. UUID v7 (RFC 9562) puts a 48-bit Unix millisecond timestamp in the first bits, followed by 74 random bits. Result: values generated close in time are close in the sort order too — the index stays hot, INSERTs stay cheap.
Is UUID v7 a real standard?
Yes. UUID v7 was standardized in RFC 9562 (May 2024), which superseded RFC 4122 and introduced v6 / v7 / v8. Before that, teams used various homegrown formats (KSUID, ULID, Twitter Snowflake) to get the same time-ordering benefits. v7 is now the interoperable, standards-track answer.
Should I use v7 instead of v4 in Postgres / MySQL / SQL Server?
Almost always yes, if UUID v7 support exists in your driver. Postgres 18 has native uuidv7(); before that, most driver libraries (uuid npm, uuid-utils in Python, uuidgen in Java) generate v7 already. In MySQL and SQL Server, use v7 UUIDs and store them BINARY(16) for locality. The write throughput / index bloat improvements over v4 are dramatic on large tables.
Can I recover the timestamp from a v7 UUID?
Yes — this tool does it in the table above. Take the first 12 hex chars (48 bits) of the UUID, parse as an integer, treat as Unix milliseconds. In code: `new Date(parseInt(uuid.replaceAll('-','').slice(0,12), 16))`. That's when the UUID was minted, useful for debugging and time-range queries without extra columns.
Are v7 UUIDs cryptographically secure?
The random bits (74 of them) come from crypto.getRandomValues, a cryptographically secure PRNG. But you should NOT use UUID v7 as a security token — the timestamp is guessable and 74 bits of entropy is less than v4's 122. Use them for IDs you're happy publishing, not for password reset tokens or session cookies.
Try Next
NanoID
Generate NanoID strings online — 21 characters, URL-safe alphabet (a-Z, 0-9, -, _), same collision safety as UUID v4 in 40% less space. Bulk generate up to 1000 with custom length. 100% local.
Related Tools
Password Generator
Generate strong, random passwords with customizable length and character sets. Free, no signup — cryptographically secure via crypto.getRandomValues, runs entirely in your browser.
QR Code
Generate QR codes online for URLs, text, WiFi credentials, and more. Download as PNG or SVG. Everything runs locally.
UUID Generator
Generate random UUIDs (v4) and time-ordered UUIDs (v7) online. Bulk generate up to 1000 at once and copy with one click.
Lorem Ipsum
Generate placeholder Lorem Ipsum text by words, sentences, or paragraphs for mockups, wireframes, and design drafts. Free, no signup, runs entirely in your browser.
Gitignore Generator
Generate a .gitignore file by selecting your tech stack — Node.js, Python, Go, Rust, Java, macOS, Windows, VS Code, JetBrains, Docker, and Next.js. Combine multiple templates. Copy or download instantly.
UUID Decoder
Decode any UUID to see its version, variant, and structure. Shows whether it's time-based (v1), random (v4), or time-ordered (v7). Extracts the node identifier. 100% local.