UUID v4 vs UUID v7: Which Should You Use?
A UUID is a 128-bit identifier you can generate anywhere without coordinating with a central server. RFC 9562 defines several versions; two matter for most developers today: v4 and v7.
v4 — random
Version 4 is 122 random bits. It's the default for general-purpose unique IDs and is trivially available in the browser and Node:
crypto.randomUUID(); // "f47ac10b-58cc-4372-a567-0e02b2c3d479"
Collisions are astronomically unlikely at any normal scale. The one downside: v4 values are unordered, so using them as a database primary key scatters inserts across the index and can hurt write performance.
v7 — time-ordered
Version 7 puts a Unix millisecond timestamp in the high bits, followed by random bits. That makes IDs sortable by creation time while staying globally unique — ideal for primary keys, because new rows append to the end of the index instead of landing randomly.
0190e9a2-7c3f-7abc-9def-1234567890ab
^ time-based prefix (sorts in creation order)
Which to choose
| v4 | v7 | |
|---|---|---|
| Basis | Random | Timestamp + random |
| Sortable by time | No | Yes |
| Best for | General unique IDs, tokens | Database primary keys, ordered inserts |
Rule of thumb: v7 for database keys, v4 for everything else.
Generate them instantly
The UUID Generator creates v4 or v7 UUIDs in bulk and copies them in one click — all in your browser.
Sources
Ready to do it?
Open the UUID Generator