Bugpit

Lessons › Big architectures

Ticket sale: one show, everyone at once

Tickets for the year's biggest tour go on sale at 10:00. 50,000 req/s arrive in the first minute, for 60,000 seats. Two people must never get the same seat, and every buyer is charged by a provider that allows 100 charges a second.

Play this level

Part of Bugpit Pro. It runs in your browser: build the design, press Run, and watch what breaks.

The lesson

A ticket sale has three problems stacked up. A crowd far bigger than your servers. Seats that must never be sold twice. And a payment provider with a hard limit.

The crowd goes in a Waiting Room. People queue for a place instead of getting an error, and your servers see only what they can take. Images and the event page come from a CDN, and seat maps from a cache.

Selling a seat is a transaction: check it's free and take it, in one step that two buyers can't both win. That needs SQL. Here the writes are too many for one primary, so use Distributed SQL, which keeps transactions and grows by adding nodes.

Charging comes last, through a queue. The seat is held, the buyer sees "you're in", and a worker charges the card at the provider's pace, with an idempotency key so a retry never charges twice.

What you have to achieve

50,000 requests a second at the busiest hour, 0% of them writes and 40% static files.

What you learn

Nobody saw an error, no seat was sold twice, and the provider was never pushed past its limit. Each part answered one of the three problems. When a design looks hard, list the problems first and give each one its own part.

Check yourself

Why do seats need SQL transactions?

Show the answer

Checking a seat is free and taking it must be one step that two buyers can't both win. Without a transaction, two buyers can both see the seat free and both take it.

The payment provider allows 100 charges a second. How do you sell faster than that?

Show the answer

Hold the seat, answer the buyer, and charge from a queue at the provider's pace. You can't add machines to someone else's API. The queue lets the charges catch up after the rush.

What does the waiting room protect?

Show the answer

Your servers, by letting in only what they can take. Everyone else waits for a place in line instead of getting an error.

Try it yourself

More in Big architectures

← Chat app: 6 million online Ride hailing: a driver in two seconds →