UUID v4 vs UUID v7: Choosing Identifiers for Applications
UUID v4 and UUID v7 both create globally unique identifiers, but they optimize for different workflows. UUID v4 is random and widely supported. UUID v7 includes a time-ordered component, making it useful for sortable records, database indexes, and chronological logs.
Quick answers
What is UUID v4?
UUID v4 is a randomly generated identifier. It is a good default for test data, public IDs, and distributed systems when chronological ordering is not important and broad compatibility matters.
What is UUID v7?
UUID v7 is a time-ordered UUID format standardized in RFC 9562. It combines timestamp information with random bits so identifiers can remain unique while sorting more naturally by creation time.
Should I use UUID v4 or v7?
Use UUID v4 when you need a simple random identifier. Use UUID v7 when records are inserted frequently and chronological ordering can improve debugging, indexing, pagination, or log analysis.
UUID v4 is simple and widely compatible
UUID v4 is often the easiest choice because most languages, databases, and libraries support it. It works well for fixtures, API examples, distributed object IDs, and systems that do not need IDs to reveal ordering.
The tradeoff is that random UUIDs do not sort by creation time. In some databases, purely random inserts can also be less locality-friendly than ordered identifiers.
UUID v7 improves ordering while preserving uniqueness
UUID v7 is designed for modern systems that want UUID-style identifiers with better temporal ordering. That makes it easier to sort recent records, inspect logs, and keep batches of inserted records closer together.
UUID v7 is newer than UUID v4, so compatibility with every downstream system should be checked before adopting it broadly.
UUID v4 vs UUID v7
| Feature | UUID v4 | UUID v7 |
|---|---|---|
| Ordering | Random order | Time ordered |
| Compatibility | Very broad | Growing, but newer |
| Best fit | General IDs and fixtures | Database records, logs, sortable IDs |
Recommended workflow
- Choose UUID v4 for broad compatibility and random identifiers.
- Choose UUID v7 when sorting by creation time is useful.
- Validate that your database, API, and client libraries accept the chosen version.
- Keep generated IDs local when using them for unreleased systems or private data.