What is a UUID?
A Universally Unique Identifier (UUID) is a 128-bit label used to uniquely identify identifying information in computer systems. They are defined by RFC 4122 and the newer RFC 9562.
UUIDs are so large (128 bits) that the probability of a collision (two distinct items having the same ID) is practically zero, even without a central authority to coordinate generation. This makes them perfect for distributed systems, databases keys, and session tokens.
Why use UUID v4?
Version 4 (Random) is the industry standard for most use cases. It relies on random numbers, ensuring high entropy and privacy. It reveals no information about the machine that generated it or the time it was created.
When to use UUID v7?
Version 7 (Time-based) is the new standard for database keys. It is time-sortable (monotonic), which significantly improves database index performance compared to random v4 UUIDs, while still maintaining high uniqueness.
Common Use Cases
- Database Primary Keys: Using UUIDs allows records to be created on different servers before being merged into a single database.
- Session IDs: Unique tokens for tracking user sessions in web applications.
- Asset Filenames: Preventing filename collisions when users upload files.
- API Resources: Secure, non-guessable IDs for public API endpoints.
UUID Format vs GUID
The term GUID (Globally Unique Identifier) is essentially a synonym for UUID, primarily used in the Microsoft ecosystem. Both adhere to the same 128-bit structure. A standard UUID string looks like this: