MentorNode
Start free
Foundations & Core PatternsEasydesign-unique-id-generator

Design a Distributed Unique ID Generator (Snowflake)

Design a service that hands out 64-bit, roughly time-ordered, globally unique identifiers without a central database sequence becoming a bottleneck.

Snowflake IDsLogical ClocksSequence RangesClock Skew Handling
Traffic & Capacity Estimates:

1M IDs/second across 1,024 nodes · 64-bit IDs · k-sortable by creation time

Functional Requirements

  • •Generate 64-bit numeric IDs that are unique across every node in the fleet.
  • •IDs must be roughly sortable by creation time so they work as primary keys and cursors.
  • •No coordination round-trip on the hot path — a node generates IDs locally.
  • •Support node identity assignment when instances are added, restarted, or replaced.

Non-Functional Requirements

  • •Generation latency under 1ms at p99, with no network call in the common case.
  • •Survive clock skew and NTP step-back without ever emitting a duplicate.
  • •Tolerate a coordination-service outage for the lifetime of an already-leased node ID.

Back-of-the-Envelope Math

  • Snowflake layout: 41 bits timestamp (69 years) + 10 bits node ID (1,024 nodes) + 12 bits sequence (4,096 IDs/ms/node).
  • Theoretical ceiling: 4,096 * 1,000 * 1,024 = ~4.2 billion IDs/second.

Key Architectural Trade-offs

  • Snowflake-style timestamp composition vs UUIDv4 (no coordination, but random ordering destroys B-tree locality) vs UUIDv7.
  • Node IDs leased from ZooKeeper/etcd vs derived from host metadata — leasing costs a dependency, derivation risks collisions.
  • Clock moved backwards: refuse to generate and block, or borrow from the sequence bits — availability vs monotonicity.

Click or drag a component onto the canvas, then connect the handles to draw the data flow.

3 nodes · 2 edges

Components · 35

Client & Edge4
Compute & Gateway7
Storage & Caching11
Messaging & Streaming6
Coordination & Ops5
Intelligence2
Canvas overview