Guide
Choosing a UUID Version: v4 versus v7
When to use random UUID v4 and when a time-ordered UUID v7 is the better identifier.
A UUID is a 128-bit identifier. Version 4 fills nearly all of those bits with random data; version 7 starts with a Unix millisecond timestamp and fills the rest with random data. The choice is about ordering and index locality, not secrecy.
01How to choose
- Need an opaque identifier with no meaningful order: version 4.
- Need roughly time-sortable keys that index well: version 7.
- Need a deterministic identifier derived from a name: version 5 (SHA-1) or version 3 (MD5) with a namespace.
- Never use a UUID as a secret or as a password.
Randomness is not security
A version 4 UUID is unpredictable only if it comes from a cryptographically secure random generator; the format itself guarantees nothing.
02Limitations
Uniqueness is probabilistic. A collision is extraordinarily unlikely at ordinary volumes, but the assurance comes from the generator's entropy, not from the shape of the identifier.
Frequently asked questions
- Should primary keys be UUID v4 or v7?
- v7 if you want inserts to stay near the end of a B-tree index; v4 if ordering is irrelevant and you want maximum opacity.
Sources
- RFC 9562: Universally Unique IDentifiers (UUIDs) — IETF (accessed 2026-09-27)
Test this in your browser
The tool runs entirely in your browser; the input you use never leaves it.
About the author
Gampangin builds and maintains free, browser-based developer tools and the documentation that makes them trustworthy. The organization is accountable for every page published on this site.