UUID Basics: Versions and Variants
Universally Unique Identifiers (UUIDs) are 128-bit values used to create unique IDs without central coordination. They are widely adopted across databases, APIs, and distributed systems.
Structure
A UUID is typically represented as a 36-character string: 32 hex digits and 4 hyphens (8-4-4-4-12). Example: 123e4567-e89b-12d3-a456-426614174000.
Versions
- v1: Time-based; includes timestamp and node (often MAC) — can leak metadata.
- v3/v5: Name-based; derived from a namespace and name using hashing (MD5/SHA-1).
- v4: Random; simple, fast, and generally collision-resistant for most practical workloads.
Variants
Variants define the layout; the most common is the RFC 4122 variant used in modern systems.
Why v4?
Random UUIDs are usually the safest default: no metadata leakage, easy generation, and excellent uniqueness at typical scales.