Skip to content
chisenbergPublic

About

A sortable unique ID lib that uses only 8 chars, has up to minute precision and can handle up to 16K unique ID/minute

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mini-ulid

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.

Example

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

Collision probability

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%

Usage

import miniulid "github.com/chisenberg/mini-ulid"

id, err := miniulid.Generate()
if err != nil {
    log.Fatal(err)
}
fmt.Println(id.String()) // e.g. 0Y31Z00AQG93

About

A sortable unique ID lib that uses only 8 chars, has up to minute precision and can handle up to 16K unique ID/minute

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages