← All guides

UUID v4 vs v7 vs ULID: Which Unique ID Should You Use?

A practical guide to choosing between random UUID v4, time-ordered UUID v7 and ULID for database keys and distributed systems.

Unique identifiers let distributed systems create keys without a central authority. The three most common choices today are UUID v4, UUID v7 and ULID — and the right pick depends on how your database indexes them.

UUID v4 — pure randomness

UUID v4 is 122 bits of randomness. It is the safe default for primary keys, session ids and transaction tracking because collisions are practically impossible.

The downside: because v4 is random, consecutive inserts scatter across a database B-tree index, causing page splits and slower writes at scale.

UUID v7 — time-ordered

UUID v7 places a 48-bit millisecond timestamp in the leading bits, so ids generated later sort after earlier ones. This keeps inserts sequential and indexes compact, while still carrying 74 bits of randomness for uniqueness.

> If you are choosing today for a new table, v7 is usually the best balance of uniqueness and index performance.

ULID — sortable and readable

A ULID is also time-ordered (48-bit timestamp + 80 bits random) but encoded in Crockford Base32. The result is a 26-character, URL-safe string that omits ambiguous letters, so it is easy to read aloud and type.

How to choose

  • Need maximum compatibility and don't care about insert order → UUID v4
  • Need fast inserts and a standard 128-bit UUID → UUID v7
  • Want short, sortable, URL-friendly ids → ULID

Generate any of these instantly with our tools, then verify the format yourself.