UUIDs (Universally Unique Identifiers) are 128-bit identifiers used to uniquely identify resources across distributed systems without a central authority. They are fundamental in databases, APIs, and microservices.
UUID Format
A UUID consists of 32 hexadecimal characters displayed in 5 groups separated by hyphens:
550e8400-e29b-41d4-a716-446655440000
Format: xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
Where M indicates the version and N indicates the variant.
UUID Versions
UUID v1 — Time-based
Generated from the current timestamp and the machine's MAC address. Guarantees uniqueness but reveals the creation time and hardware identity.
UUID v4 — Random
Generated from random or pseudo-random numbers. The most commonly used version in web development.
UUID v7 — Time-ordered Random (Newest)
Combines a Unix timestamp prefix with random data. Provides the benefits of both v1 and v4 — sortable AND random.
UUID vs Auto-Increment IDs
When to Use UUIDs
When to Use Auto-Increment
Collision Probability
For UUID v4, the probability of generating a duplicate is astronomically low. You'd need to generate about 2.71 quintillion UUIDs to have a 50% chance of a single collision. In practical terms, you could generate 1 billion UUIDs per second for 85 years before worrying.
Database Considerations
BINARY(16) instead of CHAR(36) for storage efficiency in MySQLuuid type that stores efficientlyGenerate UUIDs instantly with our UUID Generator.
