sandflake
sandflake copied to clipboard
Decentralized, sequential, lexicographically sortable unique id
trafficstars
Sandflake

Decentralized, sequential, lexicographically sortable unique id
This is a work in progress, things might change quickly without notice
Features
- 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
Table of contents
- Install/Update
- Usage
- Composition
- Ports
- Inspiration
- License
Install/Update
go get -u github.com/celrenheit/sandflake
Usage
var g sandflake.Generator
id := g.Next()
fmt.Println(id)
Composition
- 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.
Ports
Inspiration
License
Apache 2.0