How To Choose Between Uuid Versions
📖 Bu rehber ToolPazar ekibi tarafından hazırlanmıştır. Tüm araçlarımız ücretsiz ve reklamsızdır.
The UUID format
UUIDs (Universally Unique Identifiers) are the most popular way to generate IDs without coordination. 128 bits, effectively guaranteed unique, no central authority needed. But “UUID” is not one thing — there are seven specified versions (v1 through v8) with very different properties. Picking the wrong one can tank database performance, leak timing information, or create predictable IDs in security-sensitive contexts. This guide covers what each version is for, which to use by default in 2026, the v4 vs. v7 debate for databases, and when UUIDs are the wrong choice entirely.
Version 4 — random (the default for years)
The version is encoded in the first digit of the third group (here, “4”). The variant is in the first digit of the fourth group (here, “a” → RFC variant).
Version 1 — MAC + timestamp
128 bits gives ~3.4×10^38 unique values. Collisions are effectively impossible for any practical purpose.
Version 3 and 5 — namespace-based (deterministic)
v4 UUIDs are 122 bits of random data + 6 fixed bits for version/variant. No information leakage, no timing, no MAC address. Just randomness.
Version 7 — time-ordered random (the new default for databases)
v1 encodes a 60-bit timestamp + 14-bit clock sequence + 48-bit node ID (often the MAC address of the generating machine).
Version 6 — reordered v1
v3 and v5 hash a name within a namespace (using MD5 or SHA-1). Same inputs always produce the same UUID.
Version 8 — custom
v7 was standardized in RFC 9562 (2024). First 48 bits are a Unix-millisecond timestamp; remaining 74 bits are random.
The v4 vs. v7 database decision
v6 is v1 with timestamp bits reordered so sorting works lexicographically. Rarely used; v7 superseded it in practice.
Performance gotchas to understand
v8 is the “do what you want” version for custom ID schemes that still want the UUID format. Useful when you need to embed specific data (tenant IDs, shard keys) while remaining UUID-compatible.
When UUIDs are the wrong answer
Need a primary key in a database? → v7.
Alternatives to UUID
Need a public-facing ID with zero metadata leakage? → v4.
Generation best practices
Need deterministic ID from some source data (URL, email)? → v5.
Quick decision tree
Need a short user-facing ID? → NanoID, not a UUID.
Run the numbers
Need a security token? → crypto.randomBytes, not a UUID.