# ULID

Key: `technology.identifier.ulid`

Universally Unique Lexicographically Sortable Identifier. 26-character Crockford Base32 string encoding a 48-bit timestamp and 80 bits of randomness.

Page: <https://meridian.online/docs/projects/finetype/types/technology/identifier/ulid>

Samples: `01ARZ3NDEKTSV4RRFFQ69G5FAV`, `01H5J3XZQK0000000000000000`, `01FWHE4G8R2SXHM3F07YR3FW0T`

## Background

### Origin

ULID stands for Universally Unique Lexicographically Sortable Identifier, a format set out in the ulid/spec repository on GitHub.[[1]](https://github.com/ulid/spec) The ULID specification notes that UUID v4 provides no other information than randomness, which can cause fragmentation in many data structures.[[1]](https://github.com/ulid/spec) The ULID specification describes itself as the current specification of ULID as implemented in the ulid/javascript library.[[1]](https://github.com/ulid/spec) The ulid/javascript package names Alizain Feerasta as its author.[[2]](https://github.com/ulid/javascript/blob/master/package.json) The ULID specification says the format was partly inspired by posts on Instagram's engineering blog and Firebase's blog.[[1]](https://github.com/ulid/spec) RFC 9562 lists ULID first among the 16 implementations analysed while its specification was being prepared.[[3]](https://www.rfc-editor.org/rfc/rfc9562.html)

A ULID is made of a 48-bit timestamp followed by 80 bits of randomness.[[1]](https://github.com/ulid/spec) The ULID timestamp is UNIX time in milliseconds.[[1]](https://github.com/ulid/spec) The ULID specification says the timestamp won't run out of space until the year 10889 AD.[[1]](https://github.com/ulid/spec) In the canonical ULID string, the first 10 characters encode the timestamp and the remaining 16 encode the randomness.[[1]](https://github.com/ulid/spec) ULIDs are canonically encoded as a 26-character string, as opposed to the 36-character UUID.[[1]](https://github.com/ulid/spec)[[4]](https://symfony.com/doc/current/components/uid.html) ULID uses Crockford's Base32, at 5 bits per character.[[1]](https://github.com/ulid/spec) Crockford's Base32 alphabet leaves out the letters I, L, O and U.[[1]](https://github.com/ulid/spec)[[5]](https://www.crockford.com/base32.html) Douglas Crockford's Base 32 page says I and L are left out because each can be confused with 1, and O because it can be confused with 0.[[5]](https://www.crockford.com/base32.html) Douglas Crockford's Base 32 page gives accidental obscenity as the reason for leaving out U.[[5]](https://www.crockford.com/base32.html) In binary, a ULID is 16 octets, with each component encoded most significant byte first.[[1]](https://github.com/ulid/spec)

### Use

The ULID specification sorts ULIDs in lexical order, left-most character first, using the default ASCII character set.[[1]](https://github.com/ulid/spec) The ULID specification says that within the same millisecond, sort order is not guaranteed.[[1]](https://github.com/ulid/spec) In the ULID specification's monotonic mode, when the same millisecond is detected the random component is incremented by 1 bit in the least significant bit position.[[1]](https://github.com/ulid/spec) Sort on a ULID column for a rough creation order, but do not lean on it to order rows that may share a millisecond, and treat the decoded time as a hint set by whichever system minted the ID rather than as an audit timestamp. (Meridian's view)

Laravel's Eloquent ORM can give a model ULID primary keys through its HasUlids trait.[[6]](https://laravel.com/docs/12.x/eloquent) Laravel's documentation describes ULIDs as lexicographically sortable for efficient database indexing.[[6]](https://laravel.com/docs/12.x/eloquent) Symfony's documentation says using ULIDs as primary keys is usually not recommended for performance reasons.[[4]](https://symfony.com/doc/current/components/uid.html) Keep ULIDs as text when you load them, and if a ULID column will not join against another table, check whether the other side holds the same identifiers in a different form, such as a UUID-style string or raw bytes. (Meridian's view)

## Sources

1. [GitHub - ulid/spec: The canonical spec for ulid · GitHub](https://github.com/ulid/spec) — documentation
2. [javascript/package.json at master · ulid/javascript · GitHub](https://github.com/ulid/javascript/blob/master/package.json) — documentation
3. [RFC 9562: Universally Unique IDentifiers (UUIDs)](https://www.rfc-editor.org/rfc/rfc9562.html) — standard
4. [The UID Component (Symfony Docs)](https://symfony.com/doc/current/components/uid.html) — documentation
5. [Base 32](https://www.crockford.com/base32.html) — secondary source
6. [Eloquent: Getting Started \| Laravel 12.x - The clean stack for Artisans and agents](https://laravel.com/docs/12.x/eloquent) — documentation
