Tech

UUID Generator

Generate Universally Unique Identifiers per RFC 4122. Version 4 (random) or version 7 (time-sortable). One at a time or in bulk.

What is a UUID?

A UUID (Universally Unique Identifier) is a 128-bit identifier specified in RFC 4122. It's represented as 32 hexadecimal characters split into five hyphen-separated groups: xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx, where M indicates the version and N the variant bits. Seven versions exist; v4 and v7 are the ones you'll see today.

The purpose is to generate unique identifiers in distributed systems without coordinating with a central server. If two machines generate UUIDs at the same time, the chance of collision is negligible.

UUID v4 vs UUID v7

UUID v4 is 122 bits of pure randomness, plus 6 fixed bits for version and variant. Great when you don't want to leak anything about creation order or frequency.

UUID v7 (standardized in RFC 9562, 2024) places a 48-bit Unix timestamp at the start, followed by 74 bits of randomness. The result is time-sortable UUIDs, which dramatically improves B-tree index performance in databases like PostgreSQL or MySQL. Insert millions of rows with v4 UUIDs and the index fragments; with v7, it doesn't.

When to use UUID instead of an auto-increment integer

  • Public APIs: UUIDs don't reveal how many records you have or how fast you grow.
  • Distributed systems: multiple nodes can mint IDs without coordinating.
  • Database mergers: IDs don't collide when consolidating datasets.
  • User-visible IDs: they avoid the "ID 1, ID 2..." pattern that invites enumeration.
  • Optimistic UI: the client can mint the UUID before the server confirms.

When to stick with auto-increment

UUIDs aren't free. They take 16 bytes vs 4-8 for an integer, are slower to compare and produce larger indexes. In internal tables with billions of rows and hot queries, a BIGINT auto-increment still wins. Hybrid strategies keep both: BIGINT as the internal PK, UUID as the public identifier.

Collision probability

Applying the birthday paradox, you'd need to generate 2.71 × 10^18 (2.71 quintillion) v4 UUIDs to have a 50% chance of one collision. At 1 billion per second, that's about 85 years of continuous compute. In practice, treat the UUID as unique without worry.

Validation and storage

The format is always 8-4-4-4-12 hex characters. PostgreSQL has a native uuid type that takes 16 bytes. MySQL doesn't, but you can use BINARY(16) with UUID_TO_BIN/BIN_TO_UUID. SQLite and MongoDB store it as a string.

Privacy and reproducibility

Genfy uses crypto.randomUUID() when available (every modern browser) and falls back to crypto.getRandomValues otherwise. Everything is client-side: nothing is logged or sent.

FAQ

What is a UUID and what is it for?

A 128-bit unique identifier (RFC 4122). Used as primary keys, IDs in APIs and distributed traces.

Difference between UUID v4 and v7?

v4 is 100% random. v7 includes a timestamp and is time-sortable, which improves database index performance.

Can two UUIDs collide?

Statistically no. You'd need to generate quintillions to hit a 50% collision chance.

UUID or ULID/CUID?

UUID is standardized and supported everywhere. ULID/CUID are shorter and sortable; useful when readability matters.