Distributed databases and microservices architectures require distributed primary keys that can be generated independently on separate servers without a central coordinating bottleneck. That standard is the Universally Unique Identifier (UUID / GUID).
1. The 128-Bit UUID Structure
Standardized by RFC 9562, a UUID consists of 16 octets (128 bits) represented as 32 hexadecimal characters grouped into five hyphen-separated blocks:
xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx2. Collision Mathematics & Safety
With 122 bits of pure randomness in UUID v4 (2^122 ≈ 5.3 × 10^36 possible IDs), you would need to generate 1 billion UUIDs every second for 85 years before having a 50% chance of a single collision.
3. UUID v4 (Random) vs UUID v7 (Time-Ordered)
While UUID v4 is completely random, the new standard UUID v7 places a 48-bit Unix millisecond timestamp in the most significant bits, followed by 74 bits of randomness. This guarantees that IDs naturally sort chronologically.
4. Database Indexing & B-Tree Fragmentation
Inserting random UUID v4 keys into primary key B-Trees causes random page splits and heavy cache eviction. UUID v7 inserts sequentially at the end of the index like an auto-incrementing integer, resulting in up to 10x faster insert performance in PostgreSQL, MySQL, and SQLite.