UUID format
A UUID is 128 bits written as 32 hex digits in groups 8-4-4-4-12, e.g. 550e8400-e29b-41d4-a716-446655440000. The first digit of the third group is the version; the first digit of the fourth group (8, 9, a or b) marks the RFC 9562 variant.
| Version | Built from | Use |
|---|---|---|
| v1 | Timestamp + MAC address | Legacy; leaks the machine address |
| v4 | 122 random bits | General-purpose IDs |
| v5 | SHA-1 of namespace + name | Deterministic IDs |
| v7 | 48-bit Unix ms + 74 random bits | Database primary keys (index-friendly) |
Collision odds
With 122 random bits, you would need to generate about 2.7 × 1018 v4 UUIDs to reach a 50% chance of a single duplicate (birthday bound: √(2122) × 1.18).
Why v7 for databases?
Random v4 keys land all over a B-tree index, causing page splits. v7 keys increase over time, so inserts append near the end of the index, similar to an auto-increment integer.