ULID Generator
Generate ULIDs — sortable unique identifiers with embedded timestamps for distributed systems
Number of ULIDs to generate
What is a ULID?
A ULID (Universally Unique Lexicographically Sortable Identifier) is a 128-bit identifier that combines a 48-bit millisecond timestamp with 80 bits of cryptographic randomness, encoded as 26 Crockford Base32 characters. ULIDs are designed to be globally unique, time-sortable, and human-friendly.
ULID Structure
Each ULID consists of two parts:
01ARZ3NDEKTSV4RRFFQ69G5FAV
|----------|----------------|
Timestamp Randomness
(10 chars) (16 chars)
48 bits 80 bits ULIDs vs UUIDs
- Sortability: ULIDs are naturally sortable by creation time; UUID v4 is random and unsortable.
- Encoding: ULIDs use Crockford Base32 (26 chars); UUIDs use hex with dashes (36 chars).
- Index performance: ULIDs improve B-tree locality in databases; random UUIDs cause page splits.
- Readability: Crockford Base32 avoids ambiguous characters (no I, L, O, U).
- Compatibility: ULIDs are 128-bit and can be stored in UUID columns.
Crockford Base32 Alphabet
The encoding uses 32 characters specifically chosen to avoid visual confusion:
0123456789ABCDEFGHJKMNPQRSTVWXYZ Letters I, L, O, and U are excluded because they can be confused with 1, 1, 0, and V respectively.
Monotonic Ordering
When generating multiple ULIDs within the same millisecond, the random component is incremented by 1 for each subsequent ULID. This guarantees strict lexicographic ordering even at very high generation rates, which is critical for database consistency.
Common Use Cases
- Database primary keys in distributed systems
- Event sourcing and message queue ordering
- Log correlation IDs with natural time ordering
- Object storage keys that sort chronologically
- Session identifiers with built-in creation timestamps
Examples
Here are sample ULIDs showing their sortable nature:
01HX9QFBZ4N4VKGZ8MFXZQJR5Y (earlier)
01HX9QFBZ5P7WRHS9NGYZRJR6Z (later — same millisecond, monotonic)
01HX9QFC00Q8TKMN3FPXZSJR7A (next millisecond) Frequently Asked Questions
What is a ULID and how is it different from a UUID?
A ULID (Universally Unique Lexicographically Sortable Identifier) is a 26-character identifier encoded in Crockford Base32. Unlike UUID v4 which is fully random, ULIDs embed a millisecond-precision timestamp in the first 10 characters, making them naturally sortable by creation time while remaining globally unique.
Are ULIDs safe to use as database primary keys?
Yes. ULIDs are excellent database primary keys because their time-ordered nature improves B-tree index locality, reducing page splits and fragmentation compared to random UUIDs. They are especially well-suited for distributed systems where chronological ordering matters.
What is monotonic ordering in ULIDs?
When multiple ULIDs are generated within the same millisecond, monotonic ordering ensures each subsequent ULID is lexicographically greater than the previous one by incrementing the random component. This guarantees strict ordering even at sub-millisecond generation rates.
What is Crockford Base32 encoding?
Crockford Base32 is a base-32 encoding that uses 32 unambiguous characters (0-9 and A-Z excluding I, L, O, U) to avoid confusion between visually similar characters. This makes ULIDs easy to read, copy, and transmit without errors.