A compact identifier that encodes to 12 characters — half the 26 that a standard ULID requires — and fits entirely in a 64-bit integer. Designed for human readability and database index performance in small to medium applications. IDs sort lexicographically by creation time with second precision, and the 28-bit random segment keeps collision probability below 0.05% at up to 500 inserts per second.
0Y31Z00AQG93
The 12 Crockford Base32 characters encode 60 bits split into two fields:
0 Y 3 1 Z 0 0 A Q G 9 3
╰─────────────╯ ╰─────────╯
seconds since random
2020-01-01 UTC (28 bits)
(32 bits)
The field boundary falls mid-character (after bit 32 of 60), so the first ~7 characters represent the timestamp and the last ~5 characters represent the random segment.
| Field | Bits | Description |
|---|---|---|
| Seconds | 32 (MSB) | Seconds since 2020-01-01 UTC · valid until ~2156 |
| Random | 28 (LSB) | Cryptographically random per ID |
Within any given second, all IDs share the same timestamp prefix. Collision risk depends only on how many IDs are generated in that window.
| IDs / second | Collision chance |
|---|---|
| 10 | < 0.001% |
| 100 | ~0.002% |
| 500 | ~0.047% |
| 1,000 | ~0.19% |
| 2,000 | ~0.74% |
| 2,300 | ~1% |
import miniulid "github.com/chisenberg/mini-ulid"
id, err := miniulid.Generate()
if err != nil {
log.Fatal(err)
}
fmt.Println(id.String()) // e.g. 0Y31Z00AQG93