Developer Guides

UUID v4 vs v7: Choose IDs, Not Access Secrets

By MayreDukaan Editorial TeamPublished 4 min read
Two identifier cards share a 128-cell outline; one contains scattered dots, the other a clock leading into dots, with a separate locked permission gate.
Original AI-generated illustration by MayreDukaan; conceptual, not a product screenshot.

UUID versions solve different identifier problems. This guide explains random and time-ordered layouts, database trade-offs, collision handling and why every protected request still needs authorization.

Start with the job your identifier must do

A UUID identifies a record; it does not decide who may read that record. Choose a version for your storage, interoperability and privacy needs, then design authorization separately. A difficult-to-guess invoice address can still expose an invoice if the server never checks the requesting account.

Both UUID v4 and v7 are 128-bit identifiers. The familiar hyphenated spelling represents the same underlying size; changing letter case or removing hyphens does not add randomness. RFC 9562 defines their layouts and replaces RFC 4122. Neither version promises that collisions are impossible.

What changes between v4 and v7

QuestionUUID v4UUID v7
Main layoutRandom or pseudorandom payloadUnix-millisecond timestamp followed by additional fields
Time visible in the layoutNo standardized creation timestampA 48-bit millisecond timestamp
Random capacity122 bits after version and variantUp to 74 bits after timestamp, version and variant
Typical reason to consider itDistributed random identifiersTime-oriented ordering and index locality

For v7, do not assume those remaining 74 bits are always independent random bits. RFC 9562 permits specified arrangements involving sub-millisecond fractions and counters to improve monotonicity. Read the generator's documentation rather than calculating collision probabilities from a layout label alone.

A v7 timestamp is not an authenticated event time. A client can have the wrong clock or deliberately construct an identifier with a chosen timestamp. Use a separately controlled audit timestamp when a business process requires authoritative timing.

Ordering is useful, but not a universal performance promise

Time-leading identifiers can improve locality in indexes compared with uniformly scattered random keys. That is a reason to benchmark v7, not a promise that every database will run faster. Storage engines, concurrency, index representation, key comparison rules and workload all matter.

Also distinguish time ordering from a guaranteed total generation order. Multiple processes can create IDs during the same millisecond. Clock rollback and the generator's counter policy affect results. If strict global ordering is a requirement, specify that requirement explicitly; do not infer it from the version number.

Before migration, check whether your database stores UUIDs as native values, binary bytes or strings, and whether its sorting behavior matches your expectation. Include existing records, replicas and client libraries in the test. Changing the generator alone does not migrate foreign keys or update every consumer.

Use the available generator accurately

The UUID generator calls the browser's crypto.randomUUID method. Source inspection confirms that it generates v4 values, not v7. It offers count, uppercase and hyphen controls; the count is clamped between 1 and 1,000. Those presentation controls do not change the UUID version.

MDN documents crypto.randomUUID as using a cryptographically secure random generator and requiring a secure context in supporting browsers. That API property is not a general security audit of an application using its output.

For an API prototype, put a generated ID into a small sample object and use the JSON formatter to inspect the record. When changing serialization conventions, use text comparison on synthetic examples to spot altered punctuation or case. Neither tool tests authorization or database performance.

Design the surrounding controls

  1. Keep a unique constraint and define how your service handles an unexpected conflict.
  2. Check ownership or permissions on every protected record request.
  3. Decide whether exposing approximate creation time through v7 is acceptable.
  4. Use purpose-built session and reset-token mechanisms rather than recycling record identifiers.
  5. Document the generator version and its behavior during clock changes.

For example, a public catalogue may benefit from stable, opaque-looking product IDs without needing to hide product creation times. A confidential case-management system has a different exposure problem: even a random identifier must not substitute for an authenticated permission check.

A practical decision rule

Choose v4 when you want a widely supported random UUID and have no demonstrated ordering requirement. Evaluate v7 when time-oriented keys address a real storage or operational need and timestamp exposure is acceptable. In either case, test collision handling, compatibility and authorization independently. The identifier is one field in the design, not the security boundary.

References

Frequently asked questions

Does this generator create UUID v7?

No. The inspected implementation calls crypto.randomUUID, which produces v4 UUIDs.

Can UUIDs collide?

Yes in principle. Use a suitable generator and a database uniqueness constraint; no UUID version is a zero-collision guarantee.

Does v7 reveal creation time?

Its layout includes a Unix-millisecond timestamp, but that value is not proof of the actual event time.

Are all 74 remaining v7 bits random?

Not necessarily. RFC 9562 allows defined counter and sub-millisecond arrangements within that space.

Is a UUID an access token?

A record UUID is not authorization. Protected requests still need authentication and permission checks.

Will v7 always speed up a database?

No. Time ordering may help index locality, but the actual workload and database must be benchmarked.

Useful on MayreDukaan

Sources

Facts last checked against these sources on 17 Nov 2026, 06:40 Pakistan time.

Images: Original AI-generated illustration by MayreDukaan; conceptual, not a product screenshot.

More trending articles