UUID comparison
UUID v4 vs v5 vs v7
Choose the UUID version that matches your data model: random, deterministic, or time-ordered.
Quick answer
UUID version comparison
| Version | Best for | Stable for same input | Sorts by time | Main caveat |
|---|---|---|---|---|
| UUID v4 | Random IDs, public identifiers, general application records. | No | No | Random order can be less friendly for some database indexes. |
| UUID v5 | Repeatable IDs derived from a namespace and a name. | Yes | No | Input changes produce a different UUID. |
| UUID v7 | Time-ordered IDs, logs, events, and database records. | No | Yes | The timestamp portion reveals approximate creation time. |
Database storage notes
Store UUIDs in a native UUID column type when your database supports it. Native UUID columns are easier to validate and usually more compact than storing UUID strings.
Practical default
- Choose UUID v4 for broad compatibility.
- Choose UUID v7 when insert order and index locality matter.
- Choose UUID v5 only when deterministic mapping is required.