·
Igor Ilic
UUID generation: understanding UUID versions and when to use each
What is a UUID?
A universally unique identifier (UUID) is a 128-bit label standardized by RFC 4122. The canonical format is 32 hexadecimal digits displayed in five groups:
550e8400-e29b-41d4-a716-446655440000UUIDs are designed to be unique across space and time without requiring a central registry.
UUID versions compared
| Version | Generation method | Best for |
|---|---|---|
| v4 | Random | General-purpose primary keys, tokens |
| v7 | Time-ordered + random | Database indexes, time-sorted IDs |
| v1 | MAC address + timestamp | Legacy systems (privacy concerns) |
| v5 | Namespace + SHA-1 | Deterministic IDs from names |
Why UUID v7 is gaining popularity
UUID v4 values are randomly distributed, which causes index fragmentation in databases like MySQL and PostgreSQL. UUID v7 embeds a millisecond timestamp prefix, so new IDs are sequential. This reduces page splits in B-tree indexes and improves insert performance.
Many modern frameworks and databases are adopting v7 as the default UUID format.
Generate UUIDs online
The UUID generator creates v4 and v7 UUIDs instantly. It also supports bulk generation and multiple output formats.