Generate ULIDs: 26-character, lexicographically sortable unique identifiers with a millisecond timestamp. A sortable alternative to UUIDs.
A ULID is 48 bits of millisecond timestamp followed by 80 bits of randomness, encoded in Crockford base32. Because the timestamp comes first, ULIDs generated later sort after earlier ones as plain text. Randomness uses the Web Crypto API.
A ULID is a Universally Unique Lexicographically Sortable Identifier. Like a UUID it is unique, but its first half is a timestamp, so ULIDs sort in creation order as plain strings. It is also shorter (26 characters) and uses a case-insensitive, URL-safe alphabet.
Sortable IDs make great database primary keys because new rows naturally append in order, which keeps indexes efficient and lets you sort by ID instead of needing a separate timestamp column.
The 80 bits of randomness come from the Web Crypto API, making collisions astronomically unlikely even within the same millisecond. Generation is fully local and nothing is sent anywhere.