UUID · 122
UUID v4
122 random bits — the default choice for identifiers that need no ordering.
Key facts
| Random bits | 122 |
|---|---|
| Fixed bits | 4 version + 2 variant |
| Source | Cryptographic RNG expected |
| Ordering | None |
| Collision bound | Birthday bound near 2^61 values |
| Standard | RFC 9562 |
Why 122 bits is enough
Four bits are fixed for the version and two for the variant, leaving 122 random bits. To reach a 50% chance of any collision you would need on the order of 2^61 identifiers. At a billion UUIDs per second that is still centuries of generation, so v4 is safe for distributed systems without coordination.
The indexing cost
Random values scatter across a B-tree index, which causes page splits and cache misses at high insert rates. That is the main reason time-ordered v7 exists. For low-volume tables v4 is fine; for append-heavy tables v7 usually wins on write performance.
Frequently asked questions
Can two v4 UUIDs collide?
Mathematically yes, practically no at any realistic scale. The probability is far below hardware failure rates.
Does v4 leak a timestamp?
No. It contains no time, host or sequence information.
Is v4 a good primary key?
It is correct but not index-friendly. Prefer v7 or a sequential key when insert volume is high.