UUID v4 (Universally Unique Identifier, version 4) is a 128-bit identifier generated from random bits with specific version and variant markers. The format is eight-four-four-four-twelve hex digits: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx. They are used as primary keys in distributed databases, session identifiers, file names for uploaded assets, and anywhere a globally unique identifier is needed without a central authority.
Sequential integer IDs (1, 2, 3…) expose row counts and require a central counter. UUID v4 is generated independently by each service or process without coordination. The collision probability is astronomically low — you would need to generate approximately 2.7 × 10¹⁸ UUIDs to have a 50% chance of a single collision. Trade-offs: UUID v4 is larger (36 characters) than integers, slightly reduces B-tree index efficiency due to random ordering, and is not human-memorable. UUID v7 (time-sortable) solves the ordering problem.
crypto.randomUUID()UUID v4 has 122 random bits (6 are version/variant markers). For a 50% collision probability among a set of UUIDs, you would need approximately 2.7 × 10¹⁸ UUIDs — generating 1 billion per second for 86 years. In practice, the probability is negligible.
v1: based on timestamp + MAC address — sortable but reveals machine and time info. v4: fully random — the most common choice. v7: timestamp-ordered random (RFC 9562) — combines the sortability of v1 with the privacy of v4. Ideal for database primary keys.
GUID (Globally Unique Identifier) is Microsoft's implementation of UUID. The format is identical; the terms are interchangeable. Windows/COM use "GUID"; web and cross-platform standards use "UUID".
Storing as binary (16 bytes) is more efficient than the 36-character string. MySQL/MariaDB have a BINARY(16) type for this. PostgreSQL has a native UUID type. Postgres is more storage-efficient than VARCHAR(36). Most ORMs handle both representations transparently.
See also the UUID v4 Generator (dedicated tool), the Random Number Generator, and Password Generator.
📖 Reference: RFC 4122 — A Universally Unique IDentifier (UUID) URN Namespace