📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

How do you generate unique, short IDs across many service instances without a single database bottleneck?

Distributed ID generation for short codes: leased ID ranges, Snowflake-style 64-bit IDs and UUIDv7, with their length, coordination, ordering and failure trade-offs.

Mid-Level SystemDesign Intermediate distributed-systems id-generation snowflake-id system-design url-shortener uuidv7

🎯 Key points

  • Leased ranges (hi/lo): one allocator call per block of e.g. 10,000 IDs; gaps on crash are acceptable
  • Allocator outage only blocks instances whose block runs out; lease bigger blocks or keep a spare block
  • Snowflake: 64-bit = 41-bit ms timestamp + 10-bit worker id + 12-bit sequence (4,096 IDs/ms per worker)
  • Each node has its own clock: if it goes backwards, wait or refuse to issue IDs; unique worker ids prevent duplicates
  • Worker ids must be leased (e.g. from a table or blob lease) so two instances never share one
  • UUIDv7 (Guid.CreateVersion7, .NET 9 and later) needs no coordination but is 128-bit, ~22 Base62 chars
  • Base62-encode the number for the code; a 7-char Base62 code covers 3.5 trillion values
  • Choose by required length, ordering and how much coordination you can tolerate

⏱ 30-second answer

Three options. Leased ID ranges: each instance reserves a block (say 10,000 IDs) from an allocator table in one call and hands them out from memory — shortest codes, one database call per block, gaps on crash. Snowflake-style IDs: 64-bit timestamp + worker id + sequence, no per-ID coordination and time-ordered, but each worker id must be unique and a node whose clock jumps backwards must stop issuing. UUIDv7 / random: zero coordination, but 128 bits is ~22 Base62 characters — too long for short links. Then Base62-encode. The trade-off is length versus coordination versus ordering: for a URL shortener I pick leased ranges; for internal event ids, UUIDv7.

🔍 What the interviewer is checking

Checks knowledge of leased ID ranges, Snowflake-style IDs and their trade-offs

↩ Usually asked after

More in Systems to Design

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me