Whiteboard ScaleTopicsID Generator

Unique ID Generator

COMMON

Unique ID generator design is asked at Twitter, Discord, and Meta because it packs distributed-systems judgment into the smallest possible surface: 64 bits. It is the Snowflake design behind every tweet, Discord message, and Instagram photo ID. You will budget the 64 bits (41 timestamp + 10 worker + 12 sequence), handle the clock that steps backward without ever minting a duplicate, assign worker IDs with leases and fencing deadlines, and beat the real bottleneck: RPC overhead, not bit arithmetic: with batching and library embedding.

  • Budget 64 bits (1+41+10+12) and explain what each field buys: and how Sonyflake tunes the split
  • Handle backward clock steps with the spin/refuse/borrow ladder: loud beats wrong
  • Assign worker IDs with ephemeral leases and fencing deadlines that survive GC pauses
TwitterDiscordMetaInstagramSonyBaidu
8
Concepts
Deep dives
10
Cheat Items
Quick ref
Elevator Pitch3-minute interview summary

I would design a Snowflake-class generator: 64-bit IDs from 41 timestamp bits (69.7 years from a custom epoch), 10 worker bits (1,024 coordination-free minters), and 12 sequence bits (4,096 per millisecond per worker, a 4.2 billion/sec cluster ceiling). Demand of 10M IDs/sec is 0.24% of the bits: the real ceiling is RPC, so batch-500 calls and library embedding serve the platform on 12 workers. Clocks that step backward hit a policy ladder: spin-wait under 20ms, refuse and page beyond, because a paused generator beats a duplicating one. Worker IDs come from ephemeral leases with fencing deadlines that survive GC pauses, and a 1-in-1,000 SETNX canary continuously proves uniqueness.

Concepts Unlocked8 concepts in this topic