Concert Ticket Flash Sale — Part A: Requirements & High-Level Design
Definitions
Flash sale
- In plain English
- A flash sale is a short sale where demand far exceeds supply and most traffic arrives in the first few minutes.
- Think of it like
- It is like a shop door opening on Black Friday morning.
Virtual waiting room
- In plain English
- A virtual waiting room holds visitors in a fair online queue and lets them into the shop at a controlled rate.
- Think of it like
- It is like a theme-park queue line that lets groups onto the ride a few at a time.
The brief
A stadium tour sells 50,000 seats at 10:00. Around two million fans arrive within five minutes. You must keep checkout fair and prevent duplicate sales.
What it must do
- View the event page and join a waiting room with position updates.
- Admitted fans choose seats and hold them for ten minutes.
- Pay, receive a ticket, and release unpaid holds automatically.
How well it must do it
- Never sell one seat twice.
- Admit fans in server-recorded arrival order across two million concurrent visitors.
- Keep checkout request p99 below three seconds; show payment progress separately.
- Keep the sale available during payment-provider problems.
Out of scope
- Ticket resale, fraud detection models, and seat-map rendering.
Design walkthrough
Estimates
Joins: 2,000,000 ÷ (5 × 60) ≈ 6,667/s
SSE capacity: 2,000,000 ÷ 50,000 = 40 servers minimum
Admissions: 2,000/min ÷ 60 ≈ 33.3 shoppers/s
Assume one seat per shopper and every shopper buys:
50,000 ÷ 2,000 = 25 minutes of admissions
Assume three database writes per admitted shopper:
33.3 × 3 ≈ 100 writes/s before retries and expiry
Page traffic: 2,000,000 × 1.5 MB = 3,000,000 MB = 3 TB- Forty SSE servers is a connection-capacity minimum, before failure headroom and load testing.
- At one position update every ten seconds, two million connections need 200,000 delivered updates per second.
- Twenty-five minutes is conditional, not a sell-out promise; abandonment and checkout time increase it.
- Use Module 2 estimation to size load tests; row contention still matters at modest write rates.
API sketch
POST /events/{id}/queue
GET /queue/{token}/position
Accept: text/event-stream
POST /events/{id}/holds
Content-Type: application/json
{"seatIds":["14C"],"queueToken":"q7"}
POST /orders
Idempotency-Key: checkout-42
GET /orders/{id}Bind queue and admission tokens to the account. Reconnecting restores the original entry rather than adding another position.
Data model
CREATE TABLE seats (
event_id bigint NOT NULL, seat_id text NOT NULL,
status text NOT NULL
CHECK (status IN ('available','held','paying','sold')),
hold_id uuid, hold_expires_at timestamptz,
version bigint NOT NULL DEFAULT 0,
PRIMARY KEY (event_id, seat_id)
);
CREATE TABLE holds (
id uuid PRIMARY KEY, account_id bigint NOT NULL,
state text NOT NULL, expires_at timestamptz NOT NULL
);
CREATE TABLE orders (
id uuid PRIMARY KEY, hold_id uuid UNIQUE NOT NULL REFERENCES holds(id),
account_id bigint NOT NULL, idempotency_key text NOT NULL,
request_hash text NOT NULL, state text NOT NULL,
UNIQUE (account_id, idempotency_key)
);Store an admission sequence per event in the queue. Orders preserve the request details so reused keys cannot silently buy different seats.
Architecture
Fans use a CDN and gateway; a waiting room stores queue entries, while checkout queues payment work backed by a relational database.
The gateway checks admission before checkout. The payment worker stores ticket details in the database; the app reads them through order status.
This is the message queue from Module 4. Store pending payment work with the order transaction, then publish it through a retrying worker.
Core flow
A fan joins, receives admission, acquires a seat hold, and creates a recorded order for later processing.
A held seat either expires or enters payment; uncertain payment remains reserved until its outcome is resolved.
The short checkout response meets the latency target. A payment confirmation can take longer; the app keeps showing recorded progress.
Design decisions
How do we survive two million people at once?
Our choice
Use a waiting room with steady admissions. This applies Module 5 rate limiting.
Why not the alternatives
- Let everyone in and add app serversApp servers cannot remove contention on the same seat rows.
How do fans see their position?
Our choice
Push updates over Server-Sent Events. This uses one-way real-time communication from Module 1.
Why not the alternatives
- Poll every secondTwo million visitors would create two million position requests each second.
Where does the event page come from?
Our choice
Use a CDN with versioned assets and briefly cached pages. This reuses Module 4 caching.
Why not the alternatives
- Render every request on app serversRepeated page and image traffic would consume checkout capacity.
Which database holds seats?
Our choice
Use one relational database with transactions. This applies Module 3 atomic updates.
Why not the alternatives
- Use a store without the required multi-row transactionsSeparate seat changes could leave a group booking partly reserved.
Trade-offs
Pros
- The waiting room turns a spike into steady load.
- One database owns seat correctness.
Cons
- Fans wait before choosing seats.
- The queue and SSE connections need reliable capacity.
Use when
- Short sales where demand far exceeds supply.
Avoid when
- Ordinary shopping traffic where a waiting room adds delay.
Quick check
Takeaways
- Turn the spike into steady checkout traffic.
- Keep seat correctness in one transactional database.
- Use SSE for positions and a CDN for event pages.