UUID v7 Generator — Sortable Time-Ordered UUID
Generate UUID version 7 (time-ordered) UUIDs. Millisecond-precision sortable identifiers.
About UUID v7 Generator — Sortable Time-Ordered UUID
UUID v7 Generator creates sortable, time-ordered UUIDs (UUID version 7) that combine a millisecond-precision Unix timestamp with random bits. UUID v7 is the modern recommended format for database primary keys.
How to Use
- 1Click "Generate" to create one or more UUID v7 strings.
- 2Copy the generated UUIDs and use them as primary keys in your database.
- 3Generate multiple UUIDs at once using the bulk generation option.
Features
- Monotonically increasing — UUIDs sort by creation time in standard string comparison
- Better database index performance than random UUID v4
- Millisecond-precision timestamp with random suffix for uniqueness
- RFC 9562 compliant — the modern UUID standard for databases
UUID v7 Structure and Design
UUID v7 is a modern UUID format defined in RFC 9562 (2024) that was specifically designed to address the database performance problems caused by random UUIDs. Its key innovation is placing a millisecond-precision Unix timestamp in the most significant bits.
Millisecond-Precision Timestamp in the High Bits
A UUID v7 is 128 bits divided into three main sections. The first 48 bits (12 hex characters) contain a Unix timestamp in milliseconds — the number of milliseconds since January 1, 1970 UTC. Because these bits are at the most significant end of the UUID, lexicographic sorting of UUID v7 strings produces chronological ordering. A UUID generated later is always lexicographically greater than one generated earlier (within the same millisecond, additional random bits maintain ordering via a monotonically increasing counter). The next 4 bits are the version field set to 7. The following 12 bits (plus 2 variant bits) form a sub-millisecond sequence counter, and the remaining 62 bits are random. This structure gives millisecond-level time resolution with strong uniqueness guarantees from the random suffix.
Monotonicity and Sequential Generation
A critical property of UUID v7 for database use is monotonic ordering within a single process. When multiple UUID v7 values are generated within the same millisecond, a counter in the sub-millisecond bits ensures they remain in increasing order. This means that a batch of UUID v7 values generated in rapid succession will still be globally ordered, not just ordered within the same millisecond boundary. RFC 9562 specifies a "Method 3" approach where 12 random bits are replaced by a 12-bit counter that increments with each generation within the same millisecond. This ensures that even at very high generation rates, UUID v7 values remain monotonically increasing within a single process, which is the property that delivers the database performance benefits.
UUID v7 for Database Primary Keys
UUID v7 was designed with database performance in mind. Understanding why random UUIDs hurt database performance and how v7 solves this helps you make informed choices for your primary key strategy.
Why Random UUIDs Cause Index Fragmentation
Most databases use B-tree indexes for primary keys. B-trees maintain sorted order, which means every insert must find the correct sorted position. With random UUID v4 primary keys, each new record is inserted at a random position in the index — statistically distributed across the entire tree. This causes frequent page splits (when a B-tree page is full and must be divided), poor write locality (each insert likely touches a different disk page), and high index fragmentation over time. In PostgreSQL, this manifests as bloated tables and indexes requiring frequent VACUUM operations. In MySQL/InnoDB, random UUIDs cause the clustered primary key index to become highly fragmented, significantly degrading range scan and insert performance.
UUID v7 vs ULID vs CUID for Primary Keys
UUID v7 is one of several sortable ID formats designed to solve the random UUID problem. ULID (Universally Unique Lexicographically Sortable Identifier) uses a 48-bit millisecond timestamp and 80 random bits, encoded in base32 (26 characters). CUID2 uses a 32-character base36 encoded identifier with a timestamp prefix. UUID v7 has the advantage of being a proper UUID format (8-4-4-4-12 hex), making it compatible with any system that accepts UUIDs including databases with native UUID columns. PostgreSQL 17 includes built-in support for generating UUID v7. If your stack already handles UUIDs (UUID columns in your database, UUID types in your ORM), UUID v7 is the upgrade path with zero format changes required — just swap the generation function.
FAQ
- Why use UUID v7 over UUID v4 for databases?
- UUID v7 is monotonically increasing, which means better B-tree index performance and sequential inserts. UUID v4 causes index fragmentation.
- Is UUID v7 an official standard?
- Yes. UUID v7 is defined in RFC 9562 (2024), which supersedes RFC 4122.
- Can UUID v7 reveal the creation time?
- Yes. UUID v7 embeds a millisecond-precision Unix timestamp. If privacy is a concern, use UUID v4 which is fully random.
- What makes UUID v7 better than UUID v4 for database primary keys?
- UUID v7 includes a millisecond timestamp in the first 48 bits, making generated UUIDs roughly sortable by creation time. This is a significant database performance advantage: B-tree indexes perform best when new values are inserted in sequential order. UUID v4 (fully random) causes index fragmentation and random page writes, degrading insert performance and increasing storage overhead. UUID v7 provides the same privacy and global uniqueness as v4 while adding time-ordering that improves database index efficiency by 2–5× in high-throughput insert scenarios.
- Which programming languages have built-in support for UUID v7?
- UUID v7 was formally standardized in RFC 9562 (published April 2024), which supersedes RFC 4122. The new RFC adds UUID formats v6, v7, and v8. UUID v7 is already supported in major programming language libraries: uuid (npm), uuid7 (PyPI), ramsey/uuid (PHP), and many others. It is safe to use in new projects. For existing systems using UUID v4, there is no technical need to migrate unless you specifically need time-ordered UUIDs.
Found a bug or something not working as expected?
Report a bug →