Create globally unique identifiers for databases, APIs, and distributed systems
UUIDs (Universally Unique Identifiers) are 128-bit numbers used to uniquely identify information in computer systems. Also known as GUIDs (Globally Unique Identifiers), they are essential for distributed systems where coordination is impossible.
A UUID is 128 bits long, represented as 32 hexadecimal digits displayed in five groups separated by hyphens:8-4-4-4-12 = 32 characters (36 with hyphens)The probability of generating duplicate UUIDs is astronomically low. For v4 UUIDs, you would need to generate 1 billion UUIDs per second for about 85 years to have a 50% chance of a single collision!
| Version | Method | Use Case | Example |
|---|---|---|---|
| v1 | Timestamp + MAC address | Distributed databases, logging | 123e4567-e89b-12d3-a456-426614174000 |
| v4 | Random numbers | Web APIs, session IDs, primary keys | 550e8400-e29b-41d4-a716-446655440000 |
UUIDs make excellent primary keys because they are globally unique, eliminating ID conflicts when merging databases or working with distributed systems.
Use UUIDs instead of sequential IDs in REST APIs to prevent enumeration attacks and hide resource counts from users.
If every grain of sand on Earth (approximately 7.5 ร 10ยนโธ grains) had its own UUID, you could generate a unique UUID for each grain 2.2 trillion times over before reaching 50% collision probability!