What Is a UUID?
A UUID (Universally Unique Identifier) is a 128-bit value used to uniquely identify information in computer systems. Also known as a GUID (Globally Unique Identifier) in Microsoft ecosystems, UUIDs are formatted as 32 hexadecimal digits displayed in five groups separated by hyphens: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
UUID Versions
There are several UUID versions, each with a different generation method:
- Version 1: Based on the current timestamp and the MAC address of the computer. Guarantees uniqueness but reveals hardware and time information.
- Version 3: Generated by hashing a namespace and name with MD5. Deterministic: the same input always produces the same UUID.
- Version 4: Generated from random or pseudo-random numbers. This is the most commonly used version and what this tool generates. The probability of collision is astronomically low (about 1 in 5.3 x 10^36 for the first collision after generating 103 trillion UUIDs).
- Version 5: Like version 3 but uses SHA-1 instead of MD5. Preferred over v3 for new applications.
- Version 7: A newer format (RFC 9562) that combines a Unix timestamp with random data, making UUIDs sortable by creation time while maintaining uniqueness.
Common Use Cases for UUIDs
- Database primary keys: UUIDs allow generating unique IDs without coordinating with a central database, essential for distributed systems.
- API request tracking: Assign a UUID to each API request for logging and debugging across microservices.
- Session identifiers: Web applications use UUIDs to track user sessions securely.
- File naming: Prevent filename collisions when multiple users upload files simultaneously.
- Message queues: Ensure each message has a unique identifier for deduplication and tracking.
UUIDs vs. Auto-Increment IDs
Traditional auto-incrementing integer IDs (1, 2, 3...) are simple and compact, but they have limitations. They require a single authority to assign the next number, which creates a bottleneck in distributed systems. They also leak information: if your user ID is 1547, an attacker knows there are at least 1,547 users and can enumerate other records. UUIDs solve both problems at the cost of being larger (128 bits vs. 32-64 bits) and less human-readable.