Decentralized, sequential, lexicographically sortable unique id
This is a work in progress, things might change quickly without notice
- 128 bit
- Lexicographically sortable
- Sequential (not guarranted for future ids)
- 1.21e+24 unique ids per millisecond
- 2.81e+14 unique ids per worker per millisecond
go get -u github.com/celrenheit/sandflake
var g sandflake.Generator
id := g.Next()
fmt.Println(id)
- 48 bit: timestamp in milliseconds
- 32 bit: worker id (random at initialization)
- 24 bit: sequence number
- 24 bit: randomness
Sandflake ids do not need to wait some milliseconds for the next id if time goes backwards, it can just generate new ones and random bytes at the end should avoid any possible conflict with previous ids. In this case, the order is not guaranteed anymore.
Likewise, for future manually generated ids, the order is not guaranteed.
Apache 2.0