How does a distributed ID generation system produce 100K+ unique, time-sortable 64-bit IDs per second across 1000+ nodes with zero coordination between them and guaranteed zero collisions?
Core challenge: Need IDs that are globally unique (no central coordinator), time-sortable (newer IDs > older IDs for timeline ordering), compact (64-bit, fits in a long), and generated at 100K+/sec per node without any cross-node communication.
100K+
IDs generated / sec
64-bit
compact, fits in long
1000+
nodes, no coordination
Zero
collisions guaranteed
Architecture
Bit layout: 1 bit sign + 41 bits timestamp (ms since custom epoch, ~69 years) + 10 bits node ID (1024 machines) + 12 bits sequence (4096 IDs/ms/node). Total capacity: 4M IDs/sec/node. Time-sortable because timestamp is the most significant bits.
Zero coordination: Each node has a unique node_id (assigned at deploy via ZooKeeper/config). Within the same millisecond, sequence counter increments locally. Different nodes can never collide because their node_id bits differ. No network calls needed during ID generation.
Anti-patterns:UUID v4 (128-bit random) · not sortable, wastes space, poor index locality. Auto-increment DB · single point of failure, not distributed. Timestamp-only · collisions within same ms. No clock monotonicity check · NTP jumps cause duplicate timestamps.
Clock skew handling: If system clock moves backward (NTP adjustment), the generator refuses to generate IDs until clock catches up · prevents duplicate timestamps. Some implementations use logical clocks or wait. Critical for correctness guarantee.
Interview Cheat Sheet
1.64-bit layout · 41 timestamp + 10 node_id + 12 sequence = time-sortable, unique, compact 2.No coordination · node_id assigned once, all generation is local (no network calls) 3.Time-sortable · timestamp in MSB means IDs naturally sort by creation time 4.Capacity · 4096 IDs/ms/node = 4M/sec/node, 1024 nodes = 4B IDs/sec total 5.Clock skew · refuse generation on backward clock jump, wait for catch-up 6.Trade-offs vs UUID · smaller (64 vs 128 bit), sortable, but requires node_id management