Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/callicoder/java-snowflake
Distributed Unique ID Generator in Java inspired by Twitter Snowflake
https://github.com/callicoder/java-snowflake
distributed-id-generator distributed-sequence-generator id-generator java sequence-generator snowflake unique-id-generator
Last synced: 5 days ago
JSON representation
Distributed Unique ID Generator in Java inspired by Twitter Snowflake
- Host: GitHub
- URL: https://github.com/callicoder/java-snowflake
- Owner: callicoder
- Created: 2018-11-17T10:29:36.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-04T07:02:51.000Z (almost 5 years ago)
- Last Synced: 2024-04-11T15:33:48.291Z (7 months ago)
- Topics: distributed-id-generator, distributed-sequence-generator, id-generator, java, sequence-generator, snowflake, unique-id-generator
- Language: Java
- Homepage: https://www.callicoder.com/distributed-unique-id-sequence-number-generator/
- Size: 63.5 KB
- Stars: 154
- Watchers: 9
- Forks: 42
- Open Issues: 3
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
## Java distributed Unique ID generator inspired by Twitter snowflake
You can read about Twitter snowflake [here](https://blog.twitter.com/engineering/en_us/a/2010/announcing-snowflake.html).
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`, which comes out to be `Wednesday, September 7, 2039 3:47:35.551 PM`. 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.
```java
Snowflake s = new Snowflake(275)
s.nextId()
```Read the blog to understand more:
- [Generating unique IDs in a distributed environment at high scale.](https://www.callicoder.com/distributed-unique-id-sequence-number-generator/)