Generate time-sortable identifiers for database keys and event logs. Both formats put a 48-bit millisecond Unix timestamp first, so they sort by creation time and keep B-tree indexes compact, unlike random UUID v4 keys.

  • UUID v7 (RFC 9562) fits any uuid column: 48-bit timestamp, version and variant bits, and 74 random bits.
  • ULID encodes the same idea as 26 Crockford Base32 characters, e.g. 01ARYZ6S41TSV4RRFFQ69G5FAV, which is case-insensitive and URL-safe.

IDs generated in the same millisecond are monotonic: the random part is incremented rather than re-rolled, so a batch stays in order. Randomness comes from crypto.getRandomValues.

The decoder takes a UUID (v7, v1 or v6) or a ULID and shows the embedded timestamp in UTC and local time, plus the same 128-bit value in the other format. It is handy for answering “when was this row created?” from an ID alone. Keep in mind that the timestamp in these IDs is visible to anyone who sees them.