UUID v7 combines a millisecond timestamp with additional uniqueness fields in a standardized 128-bit identifier. It is useful when applications need distributed ID generation with time-oriented sorting. Generate identifiers for development and testing, then choose a maintained implementation and database representation for production use.
How to Use the UUID v7 Generator
Generate a batch or inspect the time embedded in an existing UUID v7.
- Set Count to a number from 1 through 1000.
- Enable Uppercase or Remove hyphens when the receiving format requires it.
- Select Generate to create the UUID v7 values.
- Select Copy all to copy the complete batch.
- Paste a value into Decode UUID v7 to show its embedded timestamp as a date.
Understanding UUIDs: Why Distributed Systems Avoid Sequential IDs
A single database can allocate sequential identifiers efficiently. Distributed systems introduce additional coordination questions: multiple services, regions, or offline clients may need to create records before contacting the same database.
UUIDs offer a large standardized identifier space that can support independent generation. They can simplify merging records from separate sources and reduce dependence on one central sequence allocator.
That benefit comes with trade-offs. A UUID occupies more storage than a 64-bit integer, and its representation affects indexes, network payloads, and debugging. Sequential IDs remain a reasonable choice for many applications with a centralized write path.
Choose an identifier strategy based on where records originate, how they are stored, and whether independent generation matters. An identifier also is not an authorization check: knowing or guessing a record ID should never be sufficient to access another user's data.
UUID v4 vs. UUID v7: The Advantage of Time-Ordered Sorting
UUID v4 is primarily random. UUID v7 places a 48-bit Unix timestamp in milliseconds at the start, followed by version, variant, and additional uniqueness fields. That timestamp prefix gives UUID v7 a time-oriented order when values are compared in a compatible representation.
| Property | UUID v4 | UUID v7 |
|---|---|---|
| Main ordering characteristic | Random | Timestamp-oriented |
| Embedded creation-time information | No standard timestamp field | Millisecond timestamp prefix |
| Typical selection reason | Broadly supported random IDs | Distributed IDs with time locality |
UUID v7 does not automatically provide strict creation order within the same millisecond. Implementations can add monotonic behavior, but that is a generator property rather than a universal cross-system guarantee. Clock differences also affect ordering between machines.
If the application needs an authoritative event sequence, store explicit ordering information. Use UUID ordering as a useful property of the identifier, not as a replacement for a complete event-ordering design.
Why UUID v7 is the New Standard for Database Primary Keys
UUID v7 is a standardized option for primary keys, rather than a mandatory replacement for every existing strategy. Its timestamp-oriented layout can improve insertion locality compared with random UUID v4 values in some B-tree indexes.
The actual benefit depends on the database engine, UUID comparison rules, storage representation, write concurrency, and workload. An application with modest traffic may see little practical difference. Another system may still prefer integer keys for compact indexes or a separate internal and external identifier strategy.
Benchmark representative writes and reads before migrating a large table. Include secondary-index overhead, foreign keys, replication, and query patterns in the assessment.
UUID v7 also reveals approximate generation time. Consider whether exposing that information is acceptable for public identifiers. A useful implementation decision explains both the operational benefit and the information the identifier carries.
How Cryptographic Randomness Prevents Identifier Collisions
Cryptographically secure random generation reduces collision probability and makes random fields difficult to predict. It does not make collisions mathematically impossible. Production systems should still enforce uniqueness where duplicate identifiers would violate data integrity.
For browser generation, use a maintained UUID v7 implementation backed by a cryptographically secure source such as crypto.getRandomValues(). Do not substitute Math.random() or label a native crypto.randomUUID() result as v7: that browser method generates UUID v4.
A compliant generator must set the timestamp, version, and variant correctly and handle any chosen counter strategy safely. Check how it behaves during clock rollback, rapid generation within one millisecond, and process restarts.
Treat generated UUIDs as identifiers rather than access tokens. For API credentials or secret reset links, use a token design with appropriate entropy, storage, expiration, and verification instead of reusing a sortable record ID.
Frequently Asked Questions
What is a UUID v7?
UUID v7 is a 128-bit identifier format whose most significant 48 bits contain a Unix timestamp in milliseconds. The remaining fields include the version, variant, and random or implementation-managed bits. This layout gives UUID v7 values useful time-oriented ordering while retaining a large space for uniqueness across independently generating systems.
What is the difference between UUID v4 and UUID v7?
UUID v4 is based primarily on random bits and has no creation time encoded in it. UUID v7 places a millisecond timestamp near the beginning and combines it with additional uniqueness bits. That can improve chronological sorting and some database insertion patterns, but the better choice still depends on privacy, indexing, and system requirements.
Can two UUID v7 values ever be the same?
Collisions are possible in principle because the identifier space is finite, but a correct implementation with strong randomness and suitable same-millisecond handling makes them extremely unlikely for ordinary workloads. Do not replace database uniqueness constraints with probability assumptions. High-volume or regulated systems should use a maintained implementation and test its collision and monotonicity behavior.
Does UUID v7 reveal when it was created?
It reveals an embedded Unix timestamp with millisecond precision, which usually approximates generation time. Anyone who receives the identifier can decode that value. Do not use UUID v7 when exposing timing information creates a privacy or business risk. The timestamp also depends on the generator’s system clock and is not proof of when an event actually occurred.
Can I remove hyphens or use uppercase UUIDs?
Uppercase hexadecimal and hyphen-free text can represent the same 128 bits, but they are not the standard UUID string form. Some parsers, validators, database types, and APIs expect lowercase hexadecimal with hyphens in the usual positions. Use formatting options only when the receiving system documents that representation, and preserve canonical form for interoperability.
References: RFC 9562: UUIDs and UUID v7 · MDN: crypto.randomUUID() · MDN: crypto.getRandomValues().