ULID

Created: 2023-11-06T18:50:50-06:00

Return to the Index

This card pertains to a resource available on the internet.

Another simple ID generator aimed at not blowing up B-Trees in databases like random numbers do.

A ULID is a 48-bit timestamp stored in the leftmost bits and combined with 80 bits of randomness.

Randomness is sampled only when a new milisecond is detected; all IDs created the same milisecond will have the same randomness. Instead the random number is incremented by one for each subsequent message.

Textual representations use Crockford's Base32 encoding.

// Assume that these calls occur within the same millisecond
ulid() // 01BX5ZZKBKACTAV9WEVGEMMVRY
ulid() // 01BX5ZZKBKACTAV9WEVGEMMVRZ
ulid() // 01BX5ZZKBKACTAV9WEVGEMMVS0
ulid() // 01BX5ZZKBKACTAV9WEVGEMMVS1