← InfraDraft

Infrastructure Primitives

Design a Distributed ID Generator (Snowflake)

A coordination-free service producing k-sortable, globally unique 64-bit IDs by combining timestamp, worker ID, and sequence bits.

Open and Simulate this Architecture in InfraDraft

Core Architectural Components

Timestamp + Worker ID + Sequence Encoder

Packs three fields into one 64-bit integer, keeping IDs roughly time-sortable.

Worker ID Allocation Service

Assigns unique worker IDs via a coordination service (ZooKeeper/etcd lease) to avoid collisions.

Clock Drift / NTP Guard

Detects backward clock jumps and refuses to generate IDs that could collide.

Per-Node Sequence Counter

In-memory monotonic counter disambiguating multiple IDs within the same millisecond.

Embedded Client SDK

Generates IDs locally with zero network round-trip per ID.