Compare random UUID v4 with timestamp-ordered UUID v7 to optimize B-tree database indexing and eliminate page splits.
Universally Unique Identifiers (UUIDs) are 128-bit labels used to uniquely identify electronic information without relying on a centralized coordination authority. They are essential to distributed database architectures. However, not all UUIDs are generated utilizing the same logic; different versions serve very specific architectural goals.
UUID Version 1: Time and MAC Address
Version 1 UUIDs are generated based on the current timestamp and the MAC address of the computer generating them. This essentially guarantees uniqueness globally, but it also leaks privacy-sensitive information (identifying the specific hardware that minted the token). Furthermore, if multiple identifiers are generated rapidly in sequence on the same machine, their prefixes will be highly predictable.
UUID Version 4: Random Entropy
In modern web development, Version 4 is the overwhelmingly dominant standard. It relies entirely on cryptographically secure pseudo-random number generators (CSPRNG). Out of the 128 bits, 122 are completely random. This provides zero metadata context but maximizes unpredictability.
The Math of Collisions
A common fear among junior developers is the specter of a "collision"—generating the exact same Version 4 UUID twice, leading to a catastrophic database primary key violation. The total volume of mathematical space in a v4 UUID is 2122 (roughly 5.3 × 1036). To give this astronomical scale context: if you were to generate 1 billion UUIDs every second for 85 years, the probability of computing a single duplicate would still be merely 50%.