8000 GitHub - arompr/java-snowflake: Distributed Unique ID Generator in Java inspired by Twitter Snowflake
[go: up one dir, main page]

Skip to content

arompr/java-snowflake

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java distributed Unique ID generator inspired by Twitter snowflake

You can read about Twitter snowflake here.

The IDs are 64-bits in size and are generated with the combination of the following:

  • Epoch timestamp in milliseconds precision - 41 bits. The maximum timestamp that can be represented using 41 bits is 2^41 - 1, or 2199023255551, That gives us 69 years with respect to a custom epoch..
  • Node ID - 10 bits. This gives us 1024 nodes/machines.
  • Local counter per machine - 12 bits. The counter’s max value would be 4095.

How to use

The Snowflake class should be used as a singleton in your application.

SnowflakeIdGenerator s = new SnowflakeIdGenerator(275)
s.nextId()

Read the blog to understand more:

About

Distributed Unique ID Generator in Java inspired by Twitter Snowflake

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Java 100.0%
0