You want to design a system that generates unique IDs across multiple servers without collisions. Which architecture below best ensures uniqueness and scalability?
Think about how to avoid collisions and maintain scalability without a single bottleneck.
Option C uses a combination of timestamp, server ID, and sequence number to ensure uniqueness and scalability. Option C creates a bottleneck. Option C risks collisions. Option C can cause collisions and is not reliable.
Your unique ID generator uses 41 bits for timestamp (in milliseconds), 10 bits for machine ID, and 12 bits for sequence number per millisecond. How many unique IDs can the system generate per millisecond?
Calculate how many IDs the sequence number allows per millisecond, then convert to per second.
12 bits for sequence number means 2^12 = 4096 IDs per millisecond. Since 1 second = 1000 milliseconds, total per second is 4096 * 1000 = 4,096,000 IDs. The question asks per millisecond but options focus on per millisecond or per second. The correct choice is 4096 IDs per millisecond.
You design a unique ID with 64 bits total. You can allocate bits between timestamp and sequence number. Allocating more bits to timestamp increases the time range IDs remain unique, but reduces IDs per millisecond. Allocating more bits to sequence number increases IDs per millisecond but shortens uniqueness duration. Which allocation is best for a system needing 10,000 IDs per millisecond and uniqueness for 10 years?
Calculate if the timestamp bits cover 10 years and if sequence bits cover 10,000 IDs per millisecond.
14 bits sequence number = 16384 IDs per millisecond, which covers 10,000 IDs. 39 bits timestamp covers about 17 years (2^39 ms ≈ 17 years), which covers 10 years. Other options either have too few sequence bits or too few timestamp bits.
What is the biggest challenge when designing a distributed unique ID generator that works across many servers?
Think about what happens when multiple servers generate IDs independently.
The main challenge is avoiding collisions (duplicate IDs) without relying on a central server, which can become a bottleneck or single point of failure. Cryptographic security and human readability are less critical. Minimizing ID size to 16 bits is impractical for uniqueness.
In a Snowflake-like distributed ID generator, which sequence correctly describes the request flow when a client requests a new ID?
Think about the logical order from request to ID generation and response.
The client first sends the request (1). The service checks timestamp (2). If timestamp same as last, increment sequence (3). If sequence maxed, wait (4). Then compose ID (5) and return it (6). Other orders break logical flow.
