← Lessons

quiz vs the machine

Platinum1750

System Design

Distributed Unique IDs

Generating globally unique, roughly ordered IDs without a central bottleneck.

5 min read · advanced · beat Platinum to climb

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.

Check yourself

Answer to earn rating on the learn ladder.

1. Why does a Snowflake style ID need no central coordination?

2. What is a downside of random UUIDs compared to time ordered IDs?