KatInterview

Designing a Flash-Sale Ticketing Platform That Never Double-Sells

System DesignModel answer
MediumModel answerSystem Designsystem-designconcurrencyrate-limiting

Last updated

Design a ticketing platform that survives a sudden surge when sales open, holds seats during checkout, and guarantees no ticket is ever sold to two buyers.

You are building the backend for selling tickets to very popular events. Sales open at a publicly announced time, and the number of people trying to buy greatly exceeds the number of tickets. A buyer picks tickets, keeps them reserved for a short period while paying, and receives them once payment succeeds.

Your design should address two main difficulties:

  1. The sudden burst of traffic the instant sales open.
  2. Inventory and concurrency control, so that one ticket can never end up with two owners, including how a cache and a database cooperate under heavy contention.

The numbers are not given. Ask about them or state your own assumptions (event size, number of concurrent buyers, peak request rate, hold duration, per-user ticket limit, seated vs. general admission, fairness expectations, bot concerns).

Reserved tickets that are not paid for within the time limit must be released back to sale.

Part 1: Core flow and data model

Describe the main components, the APIs, and the data model. Walk through one purchase from viewing the event page to holding a confirmed ticket. Cover:

  • Entities for events, inventory, holds, orders, and payments
  • APIs for checking availability, placing a hold, paying, and confirming
  • The lifecycle of a ticket from available to held to sold or released
  • Idempotency of hold and payment calls under retries and double clicks

Part 2: The traffic spike at sale open

Explain how you prevent a flood of simultaneous requests from overwhelming services and the database. Consider CDNs and caching, load balancing and pre-scaling, a waiting room or queue, and rate limiting and bot defense.

Part 3: Inventory and concurrency control

Explain how you guarantee no ticket is sold twice. Cover how inventory is decremented, how holds work during payment, how they are released on timeout, and how cache and database stay consistent. Address hot rows and the race between a late payment and an expired hold.

Hints

Hint 1

Separate the read path (event pages, availability display) from the write path (holds and purchases). The read path can be cached heavily and be slightly stale; the write path must be strictly correct.

Hint 2

Treat the database as the single source of truth for the no-oversell invariant, using a conditional atomic update. Use caches or counters only to reject obviously hopeless requests early, never as the final authority.

Hint 3

Model a hold as a row with an expiry time and a state machine. Think about what happens when the payment callback arrives after the expiry, and make every step idempotent with a client-supplied key.