ULID vs UUID — Which Should You Use?
UUIDs are ubiquitous, but they have one practical flaw for databases: they're random, which fragments indexes and slows inserts at scale. ULID (Universally Unique Lexicographically Sortable Identifier) was designed to fix that while keeping the "no coordination needed" property.
What a ULID looks like
01ARZ3NDEKTSV4RRFFQ69G5FAV
26 characters, Crockford Base32. Compared to a UUID:
550e8400-e29b-41d4-a716-446655440000
| ULID | UUID v4 | |
|---|---|---|
| Length | 26 chars | 36 chars (with dashes) |
| Bits | 128 | 128 |
| Time prefix | Yes (48-bit ms timestamp) | No |
| Sortable | Yes (lexicographic) | No |
| URL-safe | Yes | Yes (without dashes) |
| Dashes | No | Yes |
Why sortability matters
A B-tree index works best when new rows land near the end — sequential IDs cause a "hot" insert point, which databases handle efficiently. Random UUIDs scatter new rows across the entire index, causing page splits and cache misses. At millions of rows, this measurably slows inserts.
ULIDs start with a 48-bit millisecond timestamp, so rows inserted close in time sort close together. Your index stays tidy.
The time component isn't a privacy leak
The timestamp embedded in a ULID is millisecond-precision — you can see approximately when a record was created, but not more. If even that is unacceptable (e.g. you don't want creation time guessable from an ID), stick with UUID v4.
UUID v7 is the standards-based alternative
If you want sortable UUIDs that stay within the RFC 9562 spec, UUID v7 adds a Unix timestamp prefix in the same 8-4-4-4-12 format. ULIDs aren't an IETF standard; v7 is. For new projects where tooling matters, v7 is increasingly the right call.
When to pick each
- ULID — you want sortable IDs, don't need RFC UUID format, want URL-safe with no dashes.
- UUID v4 — pure randomness, no time correlation, widest library support.
- UUID v7 — sortable UUIDs that stay spec-compliant.
- Auto-increment — single-node databases where predictability and compactness matter more than distributed generation.
Generate standard UUIDs right now with the UUID generator, and see what is a UUID for the basics of how UUID uniqueness works.
Got a config file to check?
Open the config toolkit →