What is a ULID?
ULID (Universally Unique Lexicographically Sortable IDentifier) is a 26-character Crockford Base32 string: 48 bits timestamp (ms since Unix epoch) + 80 bits randomness. Because the timestamp comes first and Base32 keeps lexicographic order, sorting ULIDs as strings equals sorting by creation time — the property that makes them the go-to for database primary keys and distributed logs.
ULID vs UUID
- Sortable: UUID v4 is random — no ordering. ULID rows come out in insert order without an extra timestamp column.
- Compact: 26 chars vs 36; URL-safe without escaping.
- Monotonicity: within the same millisecond, ULIDs can bump randomness so they still sort (the spec's
monotonicoption). - UUID v7 is the IETF's time-sortable standard — same idea, different encoding. If your platform supports v7 natively, prefer it; otherwise ULID works everywhere as a plain string.
Uses
Primary keys in SQL (better insert locality than UUIDs), event IDs in logs (grep by time prefix), idempotency keys, and any place you want IDs that tell you when they were made — the decoder shows the exact millisecond.
Everything runs locally: no server, no tracking, IDs are generated with crypto.getRandomValues.