UUID v4 vs UUID v7
Random UUIDs versus time-ordered UUIDs—trade-offs for databases, APIs, and uniqueness.
Overview
UUID version 4 has been the default random identifier for years: 122 bits of randomness, no coordination, and support everywhere. UUID version 7 embeds a Unix timestamp so IDs roughly sort by creation time, which can reduce index fragmentation in databases that insert heavily. The trade-off is intentional: v7 leaks coarse timing information and needs libraries that implement the newer layout. Choose based on storage patterns and whether creation time in the ID is acceptable.
UUID v4
Open UUID GeneratorPros
- Widely supported and familiar
- No timestamp leakage in the identifier
- Excellent uniqueness for general use
Cons
- Random order hurts B-tree index locality
- Harder to sort chronologically
- No embedded creation time
UUID v7
Open UUID GeneratorPros
- Time-ordered for better index locality
- Sortable approximate creation order
- Modern choice for many new databases
Cons
- Exposes coarse creation time
- Newer—confirm library support
- Not ideal when timestamps are sensitive
Comparison table
| Aspect | UUID v4 | UUID v7 |
|---|---|---|
| Ordering | Random | Time-ordered |
| DB index friendliness | Weaker for sequential inserts | Stronger locality on insert |
| Time privacy | No embedded timestamp | Coarse timestamp visible |
| Ecosystem maturity | Universal | Growing, still catching up |
| Best fit | General IDs, public tokens | High-insert primary keys |
Recommendation
Use UUID v4 when maximum compatibility and time privacy matter. Prefer UUID v7 for new systems where database insert locality is a measured pain and exposing approximate creation time is acceptable. Generate either version locally with the UUID Generator.
Related tools
Related articles
Related comparisons
Frequently asked questions
- Are UUID v7 values sortable by creation time?
- They are designed to sort roughly by creation time because the timestamp occupies the most significant bits. Clock skew and generation details can still affect exact ordering.
- Is UUID v4 insecure because it is random?
- v4 uniqueness comes from randomness, not secrecy. Do not treat UUIDs as authentication secrets unless your threat model and entropy handling are explicit.
- Can I mix v4 and v7 in one system?
- Yes, but document which fields use which version. Mixing without a convention makes operational debugging harder.
- Does ToolHub generate both versions?
- UUID Generator supports common versions including v4 and v7 where implemented—check the tool’s version selector for the current options.
- Should I use ULIDs instead?
- ULIDs are another time-sortable option. Pick one convention per system; this page focuses on UUID versions specifically.