Design a Flash Sale With a Virtual Queue
Design a flash-sale or limited-ticket purchase system that receives far more demand than the checkout stack can process. Users enter a virtual queue; admitted users may attempt one purchase; inventory must stay exact; retries must never create duplicate orders.
Three things are graded: the queuing service that throttles inflow and tells users where they stand, the stock reservation that never oversells under very high throughput on one hot item, and the idempotency check that lets a user buy at most once despite network retries, refreshes and duplicate message delivery. A successful response must correspond to one durable order and one consumed unit. Reservations expire if payment does not complete in time.
Assume one sale can be a single hot key and that arrivals exceed sustainable capacity by orders of magnitude. Say where the durable source of truth lives and how the system recovers if the fast path is lost.
Hints
Hint 1
Separate admission from purchase. The waiting room issues signed, expiring queue tokens and admits a metered number per second; checkout only accepts requests carrying a valid admitted token.
Hint 2
Make the stock transition atomic: a single Lua script or compare-and-set on the counter in Redis, or a conditional update in the database, that either reserves one unit or fails, with a reservation record that expires.
Hint 3
An idempotency key per (user, sale) stored with the order outcome turns a retry into a replay of the first answer; the order writer checks it in the same transaction that creates the order.
Asked at
Sign in to talk to the interviewer — ask what's in scope, what scale to design for, or for a nudge when you're stuck. Conversations save to your account.
Sign in to use the assistant — ask what the problem means, get a hint when you're stuck, or have your current work reviewed. Conversations save to your account.