How it works
A 64-bit integer combines an epoch-relative millisecond timestamp, worker identifier, and per-millisecond sequence using shifts and bitwise OR. The fields are shown as decimal or hexadecimal.
- Bit allocation balances service lifetime, workers, and burst rate.
- No central counter is needed when worker IDs are unique.
Worked example
Default Snowflake ID
Generate a Snowflake ID with default Twitter epoch. Output varies with current timestamp. Bits 12-16 encode workerId, bits 17-21 encode datacenterId
Input
Count: 1
Worker ID: 1
Datacenter ID: 1
Epoch: 1288834974657
Output
2092231829779255296
When to use this
Distributed services, message systems, and sharded databases generate Snowflake-style IDs.
Edge cases
- Duplicate worker IDs can collide.
- Sequence overflow in one millisecond requires waiting or an overflow policy.
- Changing the custom epoch changes timestamp decoding.