Distributed Unique ID Generator

Unique ID generation scheme in distributed systems.
Snowflake & Sonyflake

Feature

Unique ID generator
Green pluggable, without external storage like Redis or MySQL
Suitable for distributed systems

Snowflake

1-bit Reserve (always 0)
41-bits Time (millisecond precision, a custom epoch gives us 69 years)
10-bits Configured machine id (gives us up to 1024 machines)
12-bits Sequence number (rolls over every 4096 per machine)

minimum 2m ids per second per process
response rate 2ms (plus network latency)

Sonyflake

1-bit Reserve (always 0)
39-bits Time (10-milliseconds precision, a custom epoch gives us 174 years)
8-bits Sequence number (rolls over every 256 per machine)
16-bits Configured machine id (gives us up to 65536 machines)

minimum 10k ids per second per process
response rate 2ms (plus network latency)

Limition

生成规则中含有时间位,表明在同一个节点的同一个时间单元内,仅通过自增ID来约束,如果节点在时间单元内重启,有可能导致在该节点上出现重复ID。(延迟重启时间间隔, Snowflake > 1ms, Sonyflake > 10ms

Solution

https://github.com/bwmarrin/snowflake
https://github.com/sony/sonyflake