Skip to content

Decentralized, sequential, lexicographically sortable unique id

License

Notifications You must be signed in to change notification settings

celrenheit/sandflake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Decentralized, sequential, lexicographically sortable unique id

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages