Your V7 UUID — Click to copy
UUID Anatomy
What is V7?
UUID v7 Generator — Complete Guide
UUID Version 7 is a new UUID format introduced in RFC 9562 (2024). It combines a Unix millisecond-precision timestamp in the most significant bits with cryptographically random data in the remaining bits. This means UUID v7 values are monotonically increasing — when sorted lexicographically or numerically, they are also sorted by creation time. RFC 9562 explicitly recommends UUID v7 over UUID v1 for new applications requiring time-ordered identifiers.
RFC 9562 Definition: The first 48 bits of UUID v7 are the Unix timestamp in milliseconds (ms_high: 32 bits, ms_low: 16 bits). Bits 49–52 are the version field (0111 = 7). Bits 53–64 are random. Bits 65–66 are the variant (10). The remaining 62 bits are random. This gives approximately 62 bits of randomness per millisecond while maintaining millisecond-precision time ordering.
When to Use V7
UUID v7 is the recommended choice for database primary keys in modern applications. Because UUIDs sort in creation order, they behave like auto-increment integers for B-tree index performance — avoiding the page splits and fragmentation that UUID v4 causes. UUID v7 is also excellent for event sourcing and log systems where chronological ordering matters, distributed systems that need time-ordered IDs without a central coordinator, and any system being built today that previously would have used UUID v1.
Advantages
- ✅ Time-ordered — ideal for DB primary keys
- ✅ No index fragmentation
- ✅ Timestamp extractable (Unix ms)
- ✅ RFC 9562 recommended for new systems
- ✅ No machine information exposed
- ✅ Fast B-tree index insertions
Considerations
- ⚠️ Newer — less legacy support than v4/v1
- ⚠️ Slight timestamp exposure (ms precision only)
- ⚠️ Requires UUID v7 capable library
UUID Structure
| Field | Bits | Description |
|---|---|---|
| unix_ts_ms | 48 bits (0–47) | Unix timestamp in milliseconds since epoch |
| version | 4 bits (48–51) | Fixed as 0111 (7) |
| rand_a | 12 bits (52–63) | Random or monotonic counter within ms |
| variant | 2 bits (64–65) | Fixed as 10 (RFC 9562) |
| rand_b | 62 bits (66–127) | Cryptographically random data |
Code Examples
JavaScript
// Node.js — using uuid library import { v7 } from 'uuid'; const uuid = v7(); console.log(uuid); // Extract timestamp const ts = parseInt(uuid.replace('-','').slice(0,12), 16); const date = new Date(ts);
Python
import uuid # Python 3.12+ has native UUID v7 my_uuid = uuid.uuid7() print(my_uuid) # Earlier Python: use uuid7 package # pip install uuid7 from uuid6 import uuid7 my_uuid = uuid7()
PostgreSQL
-- Install pg_uuidv7 extension CREATE EXTENSION pg_uuidv7; -- Use in table CREATE TABLE orders ( id uuid DEFAULT uuid_generate_v7() PRIMARY KEY, created_at timestamptz DEFAULT now() );
Go
// Using google/uuid import "github.com/google/uuid" uuid7, err := uuid.NewV7() if err != nil { panic(err) } fmt.Println(uuid7) // Extract timestamp ts, _ := uuid.TimestampFromV7(uuid7)
Frequently Asked Questions
Why is UUID v7 better than v4 for databases? ▾
UUID v4 is completely random, which causes new rows to be inserted at random positions in B-tree indexes (clustered indexes in MySQL InnoDB and SQL Server). This causes index fragmentation, frequent page splits, and poor cache utilisation. UUID v7 inserts at the end of the index because values are time-ordered, just like auto-increment integers.
Can I extract the creation timestamp from UUID v7? ▾
Yes. The first 48 bits (first 12 hex characters, ignoring the first hyphen) are the Unix timestamp in milliseconds. To extract: take the first 12 hex chars of the UUID (removing hyphens), convert to integer — that is the Unix timestamp in ms. Convert to a date using your language's date library.
Is UUID v7 widely supported? ▾
UUID v7 was formalised in RFC 9562 (May 2024). Support is growing rapidly — the uuid library for JavaScript/Node.js supports v7, Python 3.12+ has native support, and PostgreSQL has the pg_uuidv7 extension. It is becoming the new standard for time-ordered UUIDs.
What is the difference between UUID v1 and v7? ▾
Both are time-based, but UUID v7 is better in every way for modern use: it uses Unix timestamps (familiar and easy to work with), the timestamp is in the first bits (naturally sortable), it does not expose MAC address, and it is simpler to implement. RFC 9562 recommends v7 over v1 for all new systems.
Related Tools