The requirement
Many systems need IDs that are globally unique, generated fast, and ideally roughly time ordered so recent records sort together. A single database sequence is simple but becomes a central bottleneck.
The Snowflake approach
Pack an ID into bits from several sources:
- A timestamp prefix gives rough ordering and uniqueness over time.
- A machine id ensures two nodes never collide.
- A per node sequence counter disambiguates IDs within the same millisecond.
Because each node generates IDs locally from its own machine id, there is no coordination on the hot path.
Trade offs
UUIDs are fully decentralized but random, so they sort poorly and hurt index locality. Snowflake style IDs sort by time but require clock care, since a backward clock jump could repeat a timestamp.
Key idea
Snowflake style IDs combine timestamp, machine id, and sequence bits to generate unique, roughly ordered IDs locally with no central coordination.