UUID Versions Explained
- UUID v4 (Random) — 122 bits of randomness. Most common version. Use when you need uniqueness without any ordering.
- UUID v7 (Time-ordered) — Newer standard. First 48 bits are a Unix timestamp, rest is random. Better for database primary keys because they sort by creation time, improving index locality.
- Short ID (base62) — Not a real UUID, but a 22-character random ID using A-Z, a-z, 0-9. Useful for short URLs and human-friendly identifiers.
- Nil UUID — All zeros. Used as a placeholder or default value.
How Unique Are UUIDs?
UUID v4 has 2^122 possible values. To have a 1% chance of collision, you'd need to generate ~10^18 UUIDs. For practical purposes, you can treat them as universally unique.