Generating unique IDs in a distributed environment at high scale
Generating unique IDs in a distributed environment At high scale
Solution from Twitter Snowflake
Twitter snowflake is a dedicated network service for generating 64-bit unique IDs at high scale. The IDs generated by this service are roughly time sortable.
The IDs are made up of the following components:
- Epoch timestamp in millisecond precision - 41 bits (gives us 69 years with a custom epoch)
- Configured machine id - 10 bits (gives us up to 1024 machines)
- Sequence number - 12 bits (A local counter per machine that rolls over every 4096)
Core part of the code
1 | private static final int TOTAL_BITS = 64; |
Original post can be found from
https://www.callicoder.com/distributed-unique-id-sequence-number-generator/