What is a UUID?
A UUID (Universally Unique Identifier), standardized in RFC 4122, is a 128-bit number formatted as 32 hexadecimal digits displayed in five hyphen-separated groups:
f47ac10b-58cc-4372-a567-0e02b2c3d479
xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
In the template above, M represents the UUID version (1 through 8) and N specifies the variant (typically 8, 9, a, or b for RFC 4122).
UUID Version Comparison
| Version | Generation Method | Best For |
|---|---|---|
| UUID v1 | Timestamp + Host MAC Address | Time-ordered generation (reveals hardware MAC) |
| UUID v4 | Cryptographically secure pseudo-random bits | General-purpose distributed unique IDs |
| UUID v5 | SHA-1 hash of a namespace + string | Deterministic IDs derived from URLs or names |
| UUID v7 | Unix epoch timestamp (ms) + random bits | Database primary keys (B-tree index friendly) |
Generate High-Entropy UUIDs Online
Create single or bulk RFC-compliant UUIDv4 identifiers instantly with copy and lowercase/uppercase toggles.
The Database Primary Key Penalty of UUIDv4
While UUIDv4 is excellent for distributed systems, using it directly as a clustered primary key in MySQL InnoDB or PostgreSQL causes performance degradation over time:
- Index Fragmentation: Because UUIDv4 is completely random, new inserts are scattered randomly across disk pages, causing expensive B-tree rebalances.
- Larger Index Size: A 128-bit UUID stored as a 36-character string takes 36 bytes per row, compared to 8 bytes for a
BIGINT.
Frequently Asked Questions
crypto.randomUUID() to get a compliant RFC 4122 v4 UUID string instantly.