/sandflake

Decentralized, sequential, lexicographically sortable unique id

Primary LanguageGoApache License 2.0Apache-2.0

Sandflake Build Status GoDoc License Go Report Card

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

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