Skip to main content
Abstract Algorithms Logo
Abstract Algorithms
โ† All Problemsยทsystem designMedium~30 min

Design a Distributed Unique ID Generator

Design a globally distributed unique ID generation service (similar to Twitter Snowflake). Generated IDs must be 64-bit integers, globally unique, roughly time-sortable, and generated at high scale without cross-node network coordination.

Requirements

  • โœ“IDs must be globally unique across all nodes.
  • โœ“IDs must fit into a 64-bit integer (int64) for database index efficiency.
  • โœ“IDs must be roughly chronological / time-sortable.
  • โœ“High availability: service must generate at least 10,000 IDs per second per node with sub-millisecond latency.
  • โœ“No single point of failure and no runtime consensus round-trips (Paxos/Raft) in the ID generation path.

Constraints & Scale

  • โ€”64 bits maximum.
  • โ€”System lifetime: at least 50 years before epoch overflow.
  • โ€”Clock synchronization: tolerate minor NTP clock drift without generating duplicate IDs.
Understand
Guided mode

Why are UUID v4 unsuitable for high-throughput primary keys? Why is a centralized auto-increment database counter a bottleneck?

Context & Constraints โ€” Human Reviewed

UUID v4 is 128-bit and non-sequential, causing B-tree fragmentation, page splits, and cache misses in database indexes. Centralized DB auto-increment introduces a single write bottleneck and single point of failure.

Trade-offs

  • โš–UUID v4: fully distributed, zero coordination, but 128-bit non-sequential degrades DB indexing.
  • โš–Centralized DB counter (Ticket Server): simple and sequential, but single point of failure and latency bottleneck.
  • โš–Snowflake 64-bit scheme: 64-bit, time-sortable, decentralized, but depends on system clock stability.

Concepts used in this stage