UUID Generator

Generate Universally Unique Identifiers (UUID). Create standard UUIDs for database keys, API tokens, session IDs, and more.
Version Info
v1 (Timestamp-based)
MAC address and timestamp based. Time-ordered.
v4 (Random)
Completely random. Most commonly used.
v7 (Timestamp-sortable)
Timestamp-based sortable. Latest standard.

Complete UUID Guide

1. What is UUID?

UUID (Universally Unique Identifier) is a 128-bit identifier that guarantees uniqueness without central coordination. Represented as hexadecimal in 8-4-4-4-12 format (e.g., 550e8400-e29b-41d4-a716-446655440000), the probability of duplication is extremely low when generated anywhere in the world. Used in database primary keys, session IDs, filenames, API tokens, and more. Also called GUID (Globally Unique Identifier), defined by RFC 4122 standard.

2. UUID Version Comparison

There are 5 UUID versions, each using different generation methods. v1 combines MAC address and timestamp to guarantee time ordering but has security risks from MAC address exposure. v4 is completely random, most widely used with high unpredictability. v7 is the latest version standardized in 2024, timestamp-based sortable and advantageous for database indexing. v2 is for DCE security, v3/v5 are namespace-based for special purposes.

3. UUID Use Cases

UUIDs are useful in various situations. In distributed systems, unique IDs can be generated without a central server, providing excellent scalability. In databases, using UUIDs as primary keys instead of auto-increment IDs avoids merge conflicts. In microservice architectures, used for tracking communication between services. Also widely used for preventing filename collisions during file uploads, temporary token generation, event tracking, and log correlation analysis.

4. Choosing v1 vs v4 vs v7

UUID version selection depends on requirements. Choose v1 if time ordering is important and MAC address exposure is acceptable. However, MAC addresses allow tracking of generation location, raising privacy concerns. v4 is the best choice if security is important and ordering is unnecessary. Completely random, unpredictable with no personal information exposure. v7 is recommended if you want both time sorting and security. Timestamp-based sorting provides good database performance and less index fragmentation.

5. UUID Uniqueness Guarantee

The collision probability of UUIDs is astronomically low. For v4, 122 bits are random, providing 2^122 = 5.3 x 10^36 possible combinations. Even generating 1 billion per second, it would take 85 years to reach a 50% collision probability. v1 guarantees time-based uniqueness with timestamp (60 bits) and clock sequence (14 bits), and space-based uniqueness with MAC address (48 bits). v7 combines Unix timestamp (48 bits) and random (74 bits) to satisfy both time ordering and uniqueness.

6. Using UUID in Databases

Using UUIDs as database primary keys has several advantages. In distributed environments, each node can independently create IDs without a central ID generator, providing excellent scalability. No ID conflicts during data merging, and sequential guessing is impossible when exposed in URLs, providing security advantages. However, there are drawbacks. At 16 bytes, larger than integers (4-8 bytes), and v4's randomness can degrade index performance. In such cases, using v7 with time-ordered sorting improves B-tree index performance.