UUID vs ULID Comparison
Compare UUID and ULID: format differences, sortability, encoding efficiency, and database performance. Learn which identifier is better for your use case.
Detailed Explanation
ULID (Universally Unique Lexicographically Sortable Identifier) was created in 2016 as an alternative to UUID that prioritizes sortability and human readability. With the introduction of UUID v7, the two formats now overlap significantly in functionality.
Format comparison:
| Property | UUID | ULID |
|---|---|---|
| Size | 128 bits | 128 bits |
| String length | 36 chars (with hyphens) | 26 chars (Crockford Base32) |
| Sortable | v7 only | Always |
| Timestamp | v7: 48-bit ms | 48-bit ms |
| Randomness | v4: 122 bits, v7: 62 bits | 80 bits |
| Encoding | Hexadecimal | Crockford Base32 |
ULID structure (128 bits):
01AN4Z07BY 79KA1307SR9X4MV3
|----------| |----------------|
Timestamp Randomness
48 bits 80 bits
(10 chars) (16 chars)
A ULID looks like 01ARZ3NDEKTSV4RRFFQ69G5FAV — no hyphens, uppercase, 26 characters. The Crockford Base32 encoding excludes I, L, O, and U to avoid ambiguity with 1, l, 0, and obscene words.
UUID v7 vs ULID — key differences:
- Encoding: ULIDs use Base32 (26 chars) vs UUID's hex (36 chars), saving 10 characters per ID. This adds up in URLs, logs, and APIs.
- Randomness: ULID has 80 random bits vs UUID v7's 62 bits, giving ULID a lower collision probability within the same millisecond.
- Ecosystem: UUID is an IETF standard (RFC 9562) with native support in virtually every database, language, and framework. ULID is a community specification with growing but less universal support.
- Compatibility: ULIDs can be stored in UUID columns (both are 128 bits), but the string representation is different, which can cause confusion.
When to choose ULID: Prefer ULID when string length matters (URLs, user-facing IDs), you do not need database-native UUID support, and your ecosystem already uses ULID libraries.
When to choose UUID v7: Prefer UUID v7 when you need broad compatibility with databases (PostgreSQL uuid type, MySQL BINARY(16)), standards compliance matters, and your tools already understand UUID format.
Performance: Both perform equally well for database indexing because both are time-ordered. The storage cost is identical at 128 bits (16 bytes) in binary. The only difference is string representation size.
Use Case
Choosing between UUID and ULID typically depends on ecosystem constraints: use UUID v7 for PostgreSQL-heavy backends with native UUID column types, and ULID for systems where shorter, URL-safe identifiers are valuable.