https://github.com/celrenheit/sandflake
Decentralized, sequential, lexicographically sortable unique id
https://github.com/celrenheit/sandflake
Last synced: 9 months ago
JSON representation
Decentralized, sequential, lexicographically sortable unique id
- Host: GitHub
- URL: https://github.com/celrenheit/sandflake
- Owner: celrenheit
- License: apache-2.0
- Created: 2017-07-08T14:53:59.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-08-28T17:33:55.000Z (almost 6 years ago)
- Last Synced: 2024-06-18T20:05:36.119Z (about 2 years ago)
- Language: Go
- Homepage:
- Size: 19.5 KB
- Stars: 82
- Watchers: 10
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sandflake [](https://travis-ci.org/celrenheit/sandflake) [](https://godoc.org/github.com/celrenheit/sandflake) [](LICENSE) [](https://goreportcard.com/report/github.com/celrenheit/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](#installupdate)
- [Usage](#usage)
- [Composition](#composition)
- [Ports](#ports)
- [Inspiration](#inspiration)
- [License](#license)
## Install/Update
```bash
go get -u github.com/celrenheit/sandflake
```
## Usage
```go
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
* Java: [https://github.com/esiqveland/sandflake-java](https://github.com/esiqveland/sandflake-java)
## Inspiration
* [twitter/snowflake](https://github.com/twitter/snowflake)
* [alizan/ulid](https://github.com/alizain/ulid) and [oklog/ulid](https://github.com/oklog/ulid)
## License
Apache 2.0