Snowflake

Unique ID generation scheme in distributed systems.

Feature

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

Description

1-bit Reserve (always 0)
41-bits Time (millisecond precision w/ 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)

Performance

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

Limition

生成规则中含有时间位,表面在一个时间单元内,仅通过自增ID来约束,如果节点在时间单元内重启,有可能导致在该节点上出现重复ID

Solution

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