UUID vs ULID: Which Identifier Should You Use?

The Problem With Sequential IDs
Auto-incrementing integer IDs (1, 2, 3) are simple but come with downsides: they're predictable, don't work across distributed systems, and expose internal scale. That's why most modern systems use opaque unique identifiers — typically UUID or ULID.
What Is a UUID?
A UUID (Universally Unique Identifier) is a 128-bit value standardized in RFC 4122. The most common version is UUID v4 — randomly generated:
f47ac10b-58cc-4372-a567-0e02b2c3d479
- 36 characters (including hyphens)
- 122 bits of randomness
- Extremely low collision probability
- Supported natively in PostgreSQL, MySQL 8+, and most languages
What Is a ULID?
A ULID (Universally Unique Lexicographically Sortable Identifier) was designed to fix UUID's biggest flaw: no ordering:
01ARZ3NDEKTSV4RRFFQ69G5FAV
- 26 characters (Crockford Base32)
- First 10 characters = timestamp (millisecond precision)
- Last 16 characters = random component
- Lexicographically sortable — newer ULIDs sort after older ones
Side-by-Side Comparison
| Feature | UUID v4 | ULID |
|---|---|---|
| Length (string) | 36 chars | 26 chars |
| Sortable | No | Yes (by time) |
| Contains timestamp | No | Yes |
| Randomness | 122 bits | 80 bits |
| DB index performance | Poor (random) | Good (sequential-ish) |
| Native DB support | Wide | Limited |
Why Sortability Matters for Databases
In B-tree indexes (PostgreSQL, MySQL), random UUIDs cause page splits — every new insert may land anywhere in the index, causing fragmentation. This becomes a serious performance issue at scale.
ULIDs, being time-prefixed, mostly insert at the end of the index — similar to an auto-increment ID.
UUID v7 — The New Standard
UUID v7 (RFC 9562, finalized 2024) combines the best of both worlds — it's a UUID with a timestamp prefix:
018e3a1d-e4d3-7000-a7c1-3b5f8d2e1a90
^time prefix^
It's sortable, recognized as a UUID, and has growing support. If you can use UUID v7, it may obsolete ULID for most use cases.
When to Use Each
Use UUID v4 when:
- You need maximum compatibility with older databases and ORMs
- The embedded timestamp would be a privacy concern
Use ULID when:
- You need sortable IDs without a separate
created_atindex - Building distributed systems that generate IDs client-side
Use UUID v7 when:
- Starting a greenfield project and can choose freely
- You want a modern, standardized, sortable identifier
Generate UUIDs and ULIDs Instantly
Use the free UUID / ULID Generator on konvertio.app — generate single or bulk IDs in any version, copy to clipboard, and use them immediately.