GOAT EngineerPreparing your learning space…

System Design · Interview breakdown · Free article

Design a Ticket Booking System (Ticketmaster, BookMyShow)

Hold a party’s seats as one decision, let holds expire without a cleanup job deciding who owns a seat, and take money exactly once when the reply is lost. Built one step at a time, with experiments you can run.

A ticket booking system lets fans find an event, pick seats, hold them for a few minutes and pay. Keep one row for every seat at every show in a transactional database. A hold locks the requested rows in one short transaction and stamps them with a hold ID and a deadline. Payment becomes a booking only if that hold still owns the seats; a payment that arrives too late is refunded. A waiting room lets fans in at the rate seats can be sold.

Difficulty: Medium. Reported in interviews at Meta, Google, Amazon, Microsoft, Apple. Also asked as Design Ticketmaster, Design BookMyShow, Design a concert ticket system, Design a seat reservation system.

How do you design a ticket booking system like Ticketmaster?

A ticket booking system lets people find an event, pick seats on a map, hold them for a few minutes, and pay. The hard part is that thousands of other fans are trying to buy the same seats at the same moment.

  1. Search: Band, city, date. Everyone opens the same few event pages at once, so they must come from a cache.
  2. Seat map: Pick B4 and B5. A million people watch it change. It may lag a little, never a lot.
  3. Hold: B4, B5 held · 9:59. Two fans click B5 in the same instant. Only one may get it.
  4. Pay: $180. The reply can be lost, or arrive after the timer ran out.
  5. Tickets: B4, B5 · 14 March. Sent only once the money is confirmed, even if email is down.
At 10:00 a million fans reach the first screen for 20,000 seats. That rush is what makes every later screen hard.

Picture Noor buying two concert tickets for herself and a friend. She searches for the band and opens the seat map for the show on 14 March. She picks B4 and B5 and gets ten minutes to pay. She pays $180. Two tickets arrive by email.

At a cinema on a Tuesday afternoon, that is the whole story. A stadium tour is different. The sale opens at 10:00. A million fans arrive in the first minute, for 20,000 seats.

Two fans click the same seat. A hold has to end on its own when nobody pays. A payment can succeed after the hold ran out. Money cannot be rolled back like a database row. Every screen hides a race like these, which is why interviewers like this problem.

Here is the design in four sentences. Keep one row for every seat at every show in a transactional database. To hold seats, lock those rows in one short transaction, check that they are all free, and stamp them with a hold ID and a deadline. Payment turns the hold into a booking only if the hold still owns the seats when the money is confirmed. A waiting room in front lets fans in at the rate the database can sell.

The rest of this page is about the moments that design has to survive.

Here is the first one. At 10:00 Noor asks for B4 and B5. In the same instant, Kofi asks for B5 and B6. Both screens show all three seats in green. Suppose the service checks the seats in one step and writes them in another. Both fans pass the check for B5. Both are told it is theirs.

Here is the second. Noor gets her pair and presses Pay with 40 seconds left on the hold. The payment provider charges her card. Its reply is lost. The hold runs out. Kofi takes B4 and B5. A minute later the provider reports that Noor’s payment succeeded. Whose seats are they now, and what happens to her $180? A design with no answer to that question loses the round.

What is the interviewer testing?

Most candidates draw an event service, a booking service, a database and a payment provider in the first ten minutes. That drawing is right. A mid-level answer often stops there.

The interviewer then pushes on the moments the drawing has to survive. Two fans click the same seat. Noor needs ten minutes to pay. The payment reply is lost, and the hold runs out. A million fans watch the seat map. A million fans arrive at 10:00. A senior answer handles the first three. A staff answer also sizes the map and the waiting room from the sale’s numbers, and keeps a failover from selling a seat twice.

Spend most of the deep-dive time on the seat race, the hold and the late payment. The waiting room is the usual follow-up. Failover is where a staff round goes. How to run a round has the time plan for a 45 to 60 minute round and a 15-minute screen.

What should you ask before drawing anything?

Four questions change the design. Ask them in the first two minutes. If the interviewer leaves one open, say your assumption out loud.

Assigned seats, or general admission?
Picture a festival field where anyone stands anywhere. Now picture Row B, seat 5. The field needs one number that must never go below zero. The seats need a map, and a party that sits together. Assume assigned seats; the general admission version is a short section below.
How hot is the busiest sale?
A Tuesday cinema matinee sells 40 seats over a week. A stadium tour sells 20,000 in the first minutes to a million people. The second needs a waiting room and a map served from a cache. Assume the stadium.
How long may a fan hold seats, and what if payment finishes late?
Noor is typing her card number when the timer reaches zero. Does she lose the seats, or does paying buy extra time? Assume a ten-minute hold with a hard deadline, and a refund when the money arrives too late.
Must a party sit together, and can one order span two shows?
Noor wants B4 and B5, not B4 and D11. Assume up to eight seats per order, side by side where possible, for one show at a time.

Functional requirements

On the board: Functional requirements
1. Search events, open an event page
2. See the seat map, pick seats
3. Hold seats, all or none, 10 min
4. Pay → tickets, or a refund
5. My bookings; release a hold
out: resale, pricing, venue tools

Say it, don’t write it: The rule that can never bend is that a seat at a show has one owner.

The brief is a ticketing site for assigned-seat events. Two people use it: a fan who buys, and the payment provider that reports whether money moved.

  1. A fan finds an event by name, city or date, and opens its page.
  2. A fan sees the seat map for one show, with free seats marked. The fan asks for named seats, or for the best seats together for a party.
  3. A fan holds the chosen seats, all of them or none, for 10 minutes, with a countdown.
  4. A fan pays. The fan gets tickets if the hold was still valid when the payment was accepted, and a refund otherwise.
  5. A fan sees bookings and tickets later, and can release a hold early. An abandoned hold frees its seats on its own.

Out of scope

  • Resale and ticket transfers
  • Dynamic pricing
  • Tools for venues to set up events and seat maps
  • Recommendations
  • Splitting one payment across several people

One product rule matters later. A fan may have one active hold per show. An order holds at most eight seats.

Non-functional requirements

On the board: Non-functional requirements
• One owner per seat, always (strong)
• A party’s seats: all or none
• Hold answers in < 500 ms (p95)
• Map loads fast; a few seconds stale is fine
• 1M fans at 10:00 → waiting room
• Never charged without tickets or a refund

Say it, don’t write it: Ownership is strict, and the map is allowed to lag. That split decides the whole design.

A green seat that turns out to be taken is annoying. Noor can pick another. A seat sold to two people is a disaster at the door. So the map may be a little behind. Ownership may never be wrong.

  • A seat at a show has at most one owner, ever.
  • A party’s seats are held all together or not at all.
  • 95% of holds answer within 500 ms once a fan is admitted.
  • The seat map loads within a second at the rush, and is at most a few seconds behind.
  • A confirmed booking survives the loss of a database machine.
  • A fan is never charged without either tickets or a refund in progress.
  • Fans who arrive on time get an even chance.

The sale that sets the numbers is a million fans at 10:00 for a 20,000-seat arena. Each deep dive below works out the numbers it needs from those two. They are illustrative interview targets, not measurements of any real service.

Suppose the seat database for a show cannot confirm a safe owner. Holds pause for that show, while search and the map stay up. When two of these promises conflict, ownership wins.

Out of scope

  • A strict first-come order to the millisecond across the whole internet
  • A seat map that updates in under a second
  • Stopping every scalper; that is fraud work beyond this design

Core entities

On the board: Core entities
EventSeat(event, seat, status, hold, expires)
Hold(id, user, seats, expires_at, price)
Payment(id, hold, idem_key, status)
Booking(id, hold) · Ticket(id, seat, rev)

Say it, don’t write it: Seat rows, bookings and payments must be exact. The map and search are copies that may lag.

Follow one booking through the system. Noor opens show E7, the concert on 14 March. B5 is one physical seat in the arena. It exists for every show. What she buys is B5 at E7, so ownership lives in an event seat row keyed by show and seat. Her hold H1 names B4 and B5 and a deadline. Her payment attempt C1 records one try at taking $180. If C1 succeeds in time, booking K1 and two tickets are created.

The event seat rows, holds, bookings and payment attempts must never be wrong, so they live in one transactional database. The map, the search results and the countdown on Noor’s phone may be a few seconds behind, so they come from caches and copies. That one distinction shapes the whole design.

Where the data lives

Event seats, holds, payment attempts, bookings and tickets go in PostgreSQL. Noor’s hold changes two rows at once, B4 and B5, and they must change together. A relational database does that in one transaction, with row locks and unique constraints.

One show is 20,000 rows, which is small. Across the platform, 5,000 shows × 20,000 seats × 100 bytes is about 10 GB, which fits one database. So the split is for heat, not size. Keep every row for one show in the same database, so a hold never spans machines. Put different shows on different databases, which keeps one hot sale away from the rest.

Four constraints do real work:

- Noor and Kofi must compete for the same row for B5. The event seat table’s primary key, (event_id, seat_id), makes sure there is exactly one row per seat per show. - When a ticket for B5 is cancelled and B5 is sold again, the new ticket must be allowed. A second valid ticket must not. So tickets have a unique index on (event_id, seat_id) that covers only active tickets. - A double tap sends the same request twice. Holds are unique on (user_id, request_id), so the second request finds the hold the first one made. - Two tabs pressing Pay must not start two charges. Payment attempts allow at most one unresolved attempt per hold, through a unique index that covers only unresolved rows.

Money is stored as whole cents with a currency, so $180 is 18000 USD.

Events and venues live in a separate catalog database, with a search index built from it. That keeps the heavy browsing traffic off the database that sells seats.

API

On the board: API
GET  /events?q=…
GET  /events/:id/seatmap, /availability
POST /events/:id/holds {seatIds} → hold
POST /holds/:id/payments {requestId}
POST /webhooks/payments (provider)

Say it, don’t write it: A request ID makes a retried tap return the same hold instead of a second one.

A million fans load the same event page and the same seat drawing, so everything a fan reads while browsing can come from a cache. A hold changes who owns a seat, so it goes to one endpoint that answers with a definite result: the hold, or the seats that were taken.

RequestResponseRule it enforces
GET /events?q=…&city=…&from=…Matching eventsServed from the search index and cached
GET /events/{id}/seatmapSeat positions, rows and aislesThe same for every show at a venue, cached for days
GET /events/{id}/availabilityWhich seats are free, and a revision numberMay be a few seconds behind
POST /events/{id}/holds201 with the hold, or 409 with the taken seats and suggestionsAll the seats or none; the same request ID returns the same hold
POST /holds/{id}/payments202 with a payment attempt IDOne unresolved attempt per hold
GET /payments/{attemptId}Pending, booked, or refund on the wayWhat Noor sees after a lost reply or a closed tab
DELETE /holds/{id}204Frees the seats only if this hold still owns them
POST /webhooks/payments (from the provider)200 once the event is recordedSignature checked; each event handled once
Concrete exchangeMeaning
POST /events/E7/holds with {"requestId":"r-51","seatIds":["B4","B5"]}201 {"holdId":"H1","seats":["B4","B5"],"expiresAt":"2026-03-01T10:10:00Z","serverTime":"2026-03-01T10:00:00Z","amount":{"minor":18000,"currency":"USD"}}
POST /events/E7/holds with {"requestId":"r-88","seatIds":["B5","B6"]}409 {"taken":["B5"],"suggestions":[["B6","B7"]]}
POST /holds/H1/payments with {"requestId":"p-12","paymentToken":"tok_…"}202 {"attemptId":"C1","status":"pending"}
GET /payments/C1200 {"status":"booked","bookingId":"K1"}

Three fields exist for a reason. The request ID makes a double tap, or a retry after a dropped connection, return the same hold rather than a second one. The server time lets the app run an accurate countdown on a phone whose clock is wrong. The payment token is what the provider’s card form returns, so Noor’s card number goes straight to the provider and never touches our servers. That keeps most card-security rules off our systems.

A request body can say anything, so the fan’s identity comes from the login. The server looks up the price for the same reason. A request ID reused with different seats is refused rather than matched to the old hold.

Step 1: find an event

Noor searches for the band. The CDN passes the search to the Event API, which asks Elasticsearch for matching shows and returns them. The event page comes from the same index. The catalog in PostgreSQL is the source of truth. A change feed copies each change into the index within seconds. An event description a few seconds old harms nobody. The post search breakdown covers building an index like this in depth.

The interactive version of this example is available when JavaScript loads.

Nothing on this path decides who owns a seat, so all of it can be cached and copied freely.

Step 2: see the seat map

Noor opens show E7. Her app downloads the drawing of the arena: where every seat sits, the rows, the aisles. The drawing is the same for every show at this venue, so the CDN caches it for days. Then the app asks which seats are free. In this first version the Event API reads the status of all 20,000 seats from the seat inventory and returns them.

The interactive version of this example is available when JavaScript loads.

A green seat is an invitation to try. It is never a promise. Only the hold, in the next step, decides who owns a seat.

Step 3: hold the seats

Noor taps B4 and B5 and presses Continue. The Booking API opens one transaction on the seat inventory. It locks the two rows, checks that both are free, stamps both with hold H1 and a deadline ten minutes away, and commits. Noor gets H1, the deadline and the server time. Her countdown starts.

The interactive version of this example is available when JavaScript loads.

Here are the two transactions that decide who owns a seat: taking a hold, and confirming it after payment.

The interactive version of this example is available when JavaScript loads.

The first deep dive shows why this has to be one transaction. The second shows why the deadline is a column rather than a lock.

Step 4: pay, and get tickets or a refund

Noor presses Pay. The Booking API saves payment attempt C1 against H1, then asks the payment provider, here Stripe, to charge $180 with C1’s idempotency key. The provider reports the result to the webhook intake. The intake checks the event’s signature, stores the event, answers the provider, and then runs the confirm transaction from the stored copy. If H1 still owns B4 and B5 before its deadline, the seats become booked. A booking and two tickets are written. If not, the payment is recorded and a refund is owed.

The interactive version of this example is available when JavaScript loads.

The provider’s result can arrive after the hold ends, arrive twice, or never arrive at all. The third deep dive walks through each case.

Step 5: release abandoned holds, send tickets, repair what went wrong

Three jobs run in the background. The expiry worker marks holds past their deadline as expired and tidies their seat rows. The ticket worker reads the outbox rows that the confirm transaction wrote, and emails Noor her tickets. The reconciler looks for payments stuck in unknown, and for money and bookings that disagree. It settles each one with the provider.

Suppose the email service is down when Noor’s booking commits. The booking must still commit. The email must still go out later. So tickets are sent from an outbox rather than inside the confirm transaction. The email is retried from the outbox row. Noor can always see her tickets in the app, whatever happened to the email.

Each ticket carries a code signed by the service, bound to the ticket ID and its revision. A reissued ticket gets a new revision. The gate refuses the old code. A scanner that works offline cannot know that the same code entered through another gate a minute ago. Scanners therefore share used ticket IDs whenever they are connected. The promise of one entry per ticket holds only as far as that sharing reaches.

The interactive version of this example is available when JavaScript loads.

That is a working design. The rest of the interview is about the moments that break it.

Two fans click B5 at the same moment. How do you make sure only one gets it?

Noor asks for B4 and B5. Kofi asks for B5 and B6. Both requests reach the Booking API in the same millisecond.

Start with the simplest code. Read the seats, and if they are free, write them. Now watch the two requests side by side. Noor’s request reads B4 and B5, and both are free. One millisecond later Kofi’s request reads B5 and B6, and both are free, because Noor has not written anything yet. Noor’s request writes H1 on B4 and B5. Kofi’s request writes H2 on B5 and B6. B5 now says H2. Both fans were told the seat is theirs, and Noor’s hold has lost a seat without anyone noticing.

The read and the write are two steps, and another request fits between them. On a quiet Tuesday two fans almost never reach the same seat in the same millisecond. At 10:00 on sale day it is the normal case. About one fan in ten tries to hold seats in the first minute. 100,000 ÷ 60 is about 1,667 hold attempts a second, and most of them want the same front rows.

The first fix makes the second request wait. Open a transaction and lock the rows before reading them, with SELECT … FOR UPDATE. Replay the race. Noor’s request locks B4 and B5. Kofi’s request asks to lock B5 and has to wait. Noor’s request finds both free, writes H1 and commits. Now Kofi’s lock is granted. He reads B5, finds it held, and is told it is taken. The race is closed.

Waiting has two prices. The first is connections. Every waiting request holds a database connection while it waits. Before the waiting room below exists, those 1,667 attempts a second queue on the same front rows, and the connection pool fills with them. A fan holding seats for a quiet Tuesday show on the same database then cannot get a connection at all.

The second price is a deadlock. Request X locks B5, then asks for B4. Request Y locks B4, then asks for B5. Each waits for the other forever, until PostgreSQL notices and kills one. The cure is to lock seats in one order everywhere, lowest seat first, so overlapping requests queue instead of crossing. A lock timeout of about two seconds turns a long queue into a quick “try other seats”.

The second fix makes the check part of the write, so there is nothing between them. One statement changes a seat to held only where it is still free. The database finds B5, sees it is free, and marks it held, and no other statement can change B5 in between. If two statements reach B5 together, the second waits for the first to commit. Then it reads the row again, finds it no longer free, and changes nothing.

Replay the race once more. Noor’s statement changes B4 and B5: two rows. She wanted two, so her transaction commits. Kofi’s statement changes only B6, because B5 is no longer free: one row. He wanted two, so his transaction rolls back, and B6 is free again. Kofi waited only for Noor’s short transaction to finish, never for her app, and each fan learned the answer in one round trip.

That last step matters. The count of changed rows is compared inside the transaction, before the commit. If each seat is written and committed on its own, B4 commits for Noor and B5 fails, and she holds one seat of a pair. A pair is one decision, so it commits whole or not at all.

The three tabs replay the race. The first is the gap itself. The second writes each seat in its own transaction. The third decides the pair in one transaction.

The interactive version of this example is available when JavaScript loads.

One problem is left, and it is about the app, not the database. Suppose the app computes the best available pair the same way for everyone. A thousand fans are all offered B4 and B5. One wins. 999 fail, and all 999 are offered the next pair, and collide again. The database does a thousand writes to sell two seats. So the app offers each fan one of several good pairs, and a conflict comes back with the nearest free pair rather than a bare error.

At the rush, most requests ask for seats that are already gone. A copy of availability in Redis can turn those away without touching the database. The copy can be a moment behind, and a Redis failover can lose recent writes. So Redis may only ever say no. Even its no can be wrong about a seat freed a moment ago, which costs one fan a seat they could have had. That is acceptable. Selling a seat twice is not. The moment it says yes and decides who owns a seat, there are two sources of truth, and they will disagree.

Some teams go further, with one writer per show. Every hold for the show goes onto one queue partition. One worker reads it and decides holds strictly in order, from memory. That gives strict first-come order. It also makes every hold asynchronous: the fan sees “processing” and waits. And a crashed worker must rebuild the show and replay its queue without holding anything twice. That is a lot of machinery for a sale the waiting room already slows to 100 holds a second.

One detail joins the two fixes. An update on several rows takes its row locks in whatever order it happens to find them, not necessarily seat order. So two overlapping pairs can still deadlock under the conditional update alone. That is why the hold code shown in step 3 does both. It first locks the pair in seat order, lowest first. Then it writes with the “still free” condition. PostgreSQL’s locking guide recommends taking locks in the same order everywhere.

A hold can also succeed while its answer is lost, when the fan’s connection drops just after the commit. The app retries with the same request ID. The database already has a hold with that ID, so the retry returns it instead of making a second one.

The gap: Reading that B5 is free and writing that it is Noor’s are two steps, and Kofi’s request fits between them.

Option 1: Lock the rows, then check

Lock both seat rows with SELECT … FOR UPDATE, check them, write, commit.

BEGIN;
SELECT seat_id, status FROM event_seats
WHERE event_id = 'E7' AND seat_id IN ('B4', 'B5')
ORDER BY seat_id
FOR UPDATE;
-- Both free: write both. Otherwise ROLLBACK.
UPDATE event_seats SET status = 'held', hold_id = 'H1'
WHERE event_id = 'E7' AND seat_id IN ('B4', 'B5');
COMMIT;

Works when: Contention is low, or something in front keeps it bounded.

Breaks when: At the rush, waiting requests fill the connection pool, and crossed lock orders deadlock.

Fix within it: Lock seats lowest first, and set a lock timeout of about two seconds.

Option 2: One conditional update for the pair (start here)

Change each seat only where it is still free, and commit only if every seat changed.

BEGIN;
UPDATE event_seats SET status = 'held', hold_id = 'H1'
WHERE event_id = 'E7' AND seat_id IN ('B4', 'B5')
  AND status = 'free';
-- 2 rows changed: COMMIT. Fewer: ROLLBACK, the pair is taken.
COMMIT;

Works when: Almost always. The check and the write are one statement, so nothing fits between them.

Watch for: A thousand fans offered the same best pair collide again and again, and two overlapping pairs can still deadlock.

Fix within it: Lock the pair in seat order first, offer a spread of good pairs, and answer a conflict with the nearest free pair.

Option 3: A Redis copy of availability, in front

Turn away requests for seats Redis already shows as taken; send the rest to option 2.

Works when: Most requests at the rush ask for seats already gone.

Watch for: The moment Redis says yes, there are two sources of truth.

Option 4: One writer per show

Queue every hold for the show on one partition, and let one worker decide them in order.

Works when: Strict first-come order is required, or one show outgrows one database.

Watch for: Holds become asynchronous, and a crashed worker must replay without holding twice.

In the interview: Open with option 2. Say “the check and the write are one statement, and the pair commits only if both rows changed”. If the interviewer asks about locks, give option 1 with its seat-order rule. Add option 3 when they push on the rush. Reach for option 4 only if they ask for strict first-come order or a sale rate beyond one database, and say what you give up for it.

Say this: The bug is a check-then-act race: two fans both read B5 as free before either writes. I close it with one conditional update for the whole pair inside a transaction, and commit only if both rows changed, so a pair never half succeeds. At the rush, the waiting room bounds the rate and a Redis copy of availability turns away requests for seats already taken. The database still makes every decision.

Noor has ten minutes to pay. What holds the seats, and what lets them go?

Noor holds B4 and B5 at 10:00. Now she types her card number, and perhaps texts her friend to check the date. That can take ten minutes. Something has to keep Kofi off the pair until then. If she walks away, something has to give the pair back.

The obvious answer is the lock from the last deep dive, kept for ten minutes. Leave the transaction open until Noor pays. Now count. The waiting room below lets in 100 holds a second, and each stays open for 600 seconds. That is 60,000 open transactions, each holding a database connection. No database takes 60,000 connections. So the claim on the seats has to outlive the transaction that made it.

A Redis key looks made for this. Write one key per seat, only if it does not exist yet, and let Redis delete it after ten minutes. The seats free themselves. But now ownership lives in two places. The seat database cannot see the key, so the confirm step still has to check something. A Redis failover can lose a key that had not been copied yet, and hand the seat to someone else. And a server can pause for a few seconds, for example for garbage collection. It wakes after its key has expired, and still writes as if it held the seat.

So keep the claim in the seat rows themselves. The hold writes H1 and a deadline, 10:10, into the rows for B4 and B5, and commits in milliseconds. The ten minutes live in a column, not in a lock.

Something still has to notice when 10:10 passes. The obvious answer is a background job, a sweeper, that finds expired holds and marks their seats free. It fails in two ways. First, seats stay unsellable until the sweeper gets to them. At the rush thousands of holds are abandoned, and the sweeper’s lag hangs a sold-out sign over seats that are free. Second, and worse, a late sweeper acts on an old fact. Picture H1 expiring at 10:10. The sweeper frees B4 and B5, and at 10:10:30 Kofi’s hold H2 takes them. At 10:12 a retried run of H1’s cleanup frees B4 and B5 by seat number, and Kofi loses seats he holds.

The fix changes two rules, and each closes one of those gaps.

First, expired means free, at the moment of decision. The hold statement treats a seat as free if it has no hold, or if its hold’s deadline has passed. At 10:10:01 Kofi can take B4 and B5 without waiting for any sweeper.

Second, every later step names the hold. A confirm, a release or a cleanup for H1 changes a seat only where the row still says H1. Replay the late cleanup. At 10:12 it asks to free the seats where the hold is H1. The rows say H2. Zero rows match, and nothing changes. The sweeper can still run, so that the map updates, but it no longer decides who may buy a seat.

One clock has to decide. In PostgreSQL, now() is the time the transaction started. A hold that waited two seconds for a lock would check deadlines against a time two seconds old. clock_timestamp() is the time at the moment it is called (date and time functions). Read it once, after the locks, and use it for every check and for the new deadline. The app counts down from the server time in the hold response, not the phone’s clock. A phone set to the wrong time still shows the right time left.

Watch H1’s cleanup arrive two minutes late in three versions of the design.

The interactive version of this example is available when JavaScript loads.

That leaves the length of a hold. Holds tie seats up, and the arithmetic is Little’s law: seats tied up equal holds per second, times seats per hold, times seconds held. At 100 holds a second, two seats each, for 600 seconds, that is 120,000 seats, six times the arena. Put another way, the whole venue is held within 20,000 ÷ 200 = 100 seconds, and looks sold out while people type card numbers.

The waiting room sets the first factor and the party sets the second. The hold length is the lever left. In the model below, six in ten holders pay within three minutes, one in ten takes seven, and three in ten walk away. Choose how long a hold lasts.

The interactive version of this example is available when JavaScript loads.

Every choice looks sold out after 100 seconds. What differs is what the holds hide.

With five-minute holds, the slow payers run out of time. About 1,560 parties lose their seats mid-payment in the first 20 minutes. Any of them whose payment was already under way can be charged after the hold ends, which is the next deep dive. With fifteen-minute holds, nobody loses a seat mid-payment. But 6,000 seats sit behind holds that will never pay, until minute 15.

By minute 15, five-minute holds have sold 18,720 seats, ten-minute holds 17,600 and fifteen-minute holds 14,000. This page uses ten. A fan who loses seats while paying is worse than a sale that finishes a little later.

The gap: Ten minutes is far too long to hold a database lock, so the claim has to outlive the transaction that made it.

Option 1: A Redis key that expires by itself

One key per seat, written only if absent, deleted by Redis after ten minutes.

Works when: A lost hold costs nothing, such as a café table held while you order.

Breaks when: Ownership lives in two places, and a Redis failover can hand the seat to someone else.

Option 2: A hold row, freed by a sweeper

Write the hold and its deadline into the seat rows; a background job frees expired ones.

Works when: Holds expire slowly and rarely, so the sweeper keeps up.

Breaks when: Seats look sold while the sweeper lags, and a late cleanup frees seats by number that now belong to Kofi.

Option 3: A hold row whose deadline every step checks (start here)

Expired means free at decision time, and every later write changes a seat only where it still names H1.

-- Cleanup that arrives late changes nothing:
UPDATE event_seats SET status = 'free', hold_id = NULL
WHERE hold_id = 'H1' AND status = 'held';

Works when: Always, at this size. The ten minutes live in a column, not in a lock.

Watch for: A step that changes seats by seat number alone brings back the sweeper’s bug.

Fix within it: Put “where the hold is still H1” on every write.

In the interview: Open with option 3. It lives in the database you already have, and two phrases carry it: “expired means free” and “every step names the hold”. Bring up option 1 only to explain why the claim must not live in two places.

Say this: A ten-minute lock would hold a connection per shopper, so the hold is a row with a deadline instead. A seat whose deadline has passed is free straight away, without waiting for cleanup. Every confirm or release changes a seat only where it still names that hold. Late work then matches nothing and changes nothing.

The payment reply is lost, then the hold runs out. Did Noor pay, and whose seats are they?

Noor presses Pay at 10:09:20, with 40 seconds left on H1. The provider charges her card, and its reply never arrives. At 10:10 the hold ends. At 10:10:30 Kofi takes B4 and B5. At 10:11 the provider reports that Noor’s payment succeeded. A few seconds later it sends the same report again.

Payments are not the busy part of this system. About 10,000 orders over about ten minutes is about 17 payments a second. The hard part is getting every one of them exactly right, because money cannot be rolled back like a database row.

The simplest code treats silence as failure. The request timed out, so the app says “payment failed” and lets Noor try again. She does. But the first charge went through. The provider sees the retry as a second, separate purchase, and Noor pays $360 for two seats.

The provider offers a tool for exactly this: an idempotency key. The service sends a key with the charge, such as the ID of the attempt. If the same key arrives again, the provider returns the first result instead of charging again. Stripe keeps a key’s result for at least 24 hours (idempotent requests).

So retry with the same key, and book the seats when the success event arrives. Replay the story. The retry returns the first result, so Noor pays once. Then the event lands at 10:11. The booking goes through, and B4 and B5 are sold to Noor. Kofi’s hold H2 owns the same seats. One pair of seats now has two owners.

The seat database and the provider can never share one transaction. For a while, nobody knows whether Noor paid. The design has to act correctly during that while, and when the answer arrives late or twice.

Here is the version that does. It has three parts.

First, the attempt is recorded before the call. When Noor presses Pay, the Booking API saves payment attempt C1, with its idempotency key, and only then calls the provider. Picture the other order. The service calls the provider, the charge goes through, and the service crashes before saving anything. Now there is a charge on Noor’s card that our side has no record of. Saving first means every charge the provider knows about has a row on our side.

C1 also outlasts the provider’s memory of the key. A retry with the same key after the provider has forgotten it is a new charge, so the record of what happened has to live with us.

Second, silence means unknown, not failed. C1 stays unknown until the provider says otherwise. A reconciler asks the provider what happened to each unknown attempt. It looks the charge up, and never sends it again.

Third, the confirm is guarded by the hold. When the success event arrives, one transaction books the seats only where they still name H1 and the deadline has not passed. If that changes no rows, the same transaction records the payment and a refund owed.

Replay the story. At 10:11 the event arrives. The confirm looks for seats that still name H1 and finds none, because they name H2. It records Noor’s payment and a refund of $180. Kofi keeps the pair. The event arrives a second time. The webhook intake stored the first copy under its event ID, so it sees the repeat and does nothing. The reconciler may also learn that C1 succeeded, or the provider may send a different event about the same payment. So the refund is recorded against C1, once, when C1 first moves to paid. Noor gets one refund, not two.

One case looks odd. Suppose the payment lands at 10:11 and nobody has taken B4 and B5 yet. The rows still name H1, but the deadline has passed, so Noor is refunded anyway. That is a choice. A deadline that bends for some payments means nothing to the fans waiting behind her.

The intake’s order matters. It checks the signature, stores the event, answers the provider, then processes the stored copy until the confirm or refund commits. Stripe warns that an event may arrive more than once and in any order (webhooks). Picture an intake that stores the event and then crashes before booking. The provider retries. If the intake only asks “have I seen this event ID?”, it throws the retry away, and the booking never happens. So the stored copy is processed until it is done.

Switch between the three answers and follow Noor’s money and Kofi’s seats.

The interactive version of this example is available when JavaScript loads.

The refund is a new outside call, with the same problems as the charge, and a card refund can fail days later (refunds). So a refund gets its own key and its own retries, and a person with a deadline when it fails for good.

Two changes make late payments rarer. The first is a grace period. When Noor presses Pay with time left, the hold is extended once, by a few minutes, in the same transaction that saves C1. Most late payments then land in time. Some still do not, so the guarded confirm stays.

The second is to authorise first and capture later. The provider puts a hold on the card for $180, the seats are booked, and only then is the money captured. A payment that arrives too late becomes an authorisation to cancel, not a charge to refund. The price is time limits: an authorisation expires, after about seven days for most online card payments at Stripe (place a hold). A capture can also fail after the booking, so the booking needs a “payment pending” state that is cancelled if the capture fails for good.

One more push is common. Suppose the provider goes down at 10:05. Fans keep taking holds they cannot pay for, and every one runs out. So pause admission from the waiting room, which stops new holds. Extend the holds of fans who were already paying by the length of the outage, once, with a cap. The distributed transactions article explains why every step between two systems needs a recorded state, and the payment system breakdown goes deeper on the money side.

The gap: The seat database and the payment provider can never share one transaction, so for a while nobody knows whether Noor paid.

Option 1: Treat silence as a decline

After a timeout, show “payment failed” and let Noor pay again with a fresh request.

Works when: Replies always arrive, which no network promises.

Breaks when: The first charge went through, so the retry charges Noor twice.

Option 2: Reuse the key, and confirm when the provider says paid

Retry with the same idempotency key, and book when the success event arrives.

Works when: The event always lands while the hold is still alive.

Breaks when: The event lands after H1 ended, so the seats are sold to Noor while Kofi holds them.

Option 3: A stored attempt, a guarded confirm, and a refund (start here)

Save the attempt before the call, treat silence as unknown, and book only while the hold still owns the seats.

Works when: Always. A crash, a duplicate event or a late event each lands in a recorded state.

Watch for: The refund itself can fail, days later.

Fix within it: Give the refund its own key, its own retries, and a person with a deadline.

Option 4: Authorise first, capture after booking

Hold the money on the card, book the seats, then capture.

Works when: Late payments are common enough that refunds are costly.

Watch for: An authorisation expires, and a capture can fail after the booking.

In the interview: Open with option 3, and name its parts: the attempt is saved before the call, silence means unknown, and the confirm checks the hold. Offer option 4 if the interviewer asks how to avoid refunds. Options 1 and 2 are worth one sentence each, because they are the answers the interviewer is waiting to see you avoid.

Say this: The provider and our database cannot share a transaction, so I save the payment attempt with its idempotency key before calling. A timeout means unknown, so I ask the provider rather than charge again. The confirm books the seats only while the hold still owns them. If it has lost them, the same transaction records the payment and a refund to make.

A million fans watch the seat map. How fresh does it need to be?

It is 10:00:30. Noor’s map shows B8 in green. She taps it, and the hold says it is taken. A million other fans have the same map open.

Start with the numbers. A million fans load the map in the first minute: 1,000,000 ÷ 60 is about 16,667 loads a second. The simplest map reads the seat rows on every load. Each load reads all 20,000 seats. 16,667 × 20,000 is about 333 million row reads a second, on the same database that is trying to sell the seats.

So cache the map. Build it once, keep it for 30 seconds, and serve every fan the copy. The database is saved. Now look at how wrong the copy is. At the rush the waiting room lets in 100 holds a second, two seats each, so 200 seats change hands every second. In 30 seconds that is 6,000 seats, nearly a third of the arena. The copy is also big. As a list, each seat is about 16 bytes: 20,000 × 16 is 320 KB. 320 KB × 16,667 loads is about 5.33 GB a second at the edge.

The fix is to split the map into the part that never changes and the part that does.

The drawing never changes: where every seat sits, the rows, the aisles. It is the same for every show at this venue, so the CDN caches it for days. Prices differ from show to show, so they come with the show, not the drawing.

Availability changes every second, so make it as small as possible. One bit per seat says free or not free. 20,000 bits is 2,500 bytes, against 320 KB for the list. The database already keeps a stream of every committed change, its change feed. A job reads that feed and keeps the bitmap up to date. The CDN caches the bitmap for about a second. At 16,667 loads a second, 2,500 bytes a load is about 41.7 MB a second instead of 5.33 GB.

An open map asks for the bitmap again every few seconds. A million open maps asking every five seconds is 200,000 requests a second, about 500 MB a second, and nearly all of it is answered by the CDN.

An expired hold writes nothing, so it never reaches the feed. A seat whose hold ran out stays grey until the sweeper writes it free, which is why the sweeper still runs.

So Noor’s B8 was a few seconds stale. That is the design’s price, and it is paid in taps that meet “taken”. A green seat is only an invitation to try. The hold is the truth. When a tap loses, the answer comes back with the nearest free seat, so the fan loses a second, not the sale.

If a few seconds is too long, keep a connection open to every map and push each change as it happens. That is a server-sent events stream. Then a million open connections live on our own servers instead of the CDN, through the busiest minute of the year. Name it, and say what it costs.

The interactive version of this example is available when JavaScript loads.

Noor’s party then grows to four, and she asks for the best four seats together. Guess first: can a party of four sit together in this row?

The interactive version of this example is available when JavaScript loads.

C4 to C8 are five free seats in a row by number. An aisle runs between C6 and C7. A party needs one unbroken run, so the count of free seats is the wrong question. Finding seats means reading positions and aisles, which only the drawing and the seat rows together can give.

A block that leaves one seat stranded beside it makes that seat hard to sell. So many sites refuse such a block, or rank it last. That is the single-seat rule, and it is a business choice. Two holds landing at once, one on each side of a free seat, can each look fine alone and together strand it. Enforcing the rule strictly means the hold must also read the neighbouring seats. Either lock the whole run, or run every seat write at the serializable isolation level. At that level the database refuses any transaction that could not have run one at a time. PostgreSQL notes that serializable protects a rule like this only when every writer uses it (application-level consistency). The simpler honest choice is to treat the rule as a ranking preference and say so.

When the service picks seats for a fan, it can lock candidate rows with FOR UPDATE SKIP LOCKED. Rows another transaction holds are skipped instead of queued behind. PostgreSQL warns that this gives an inconsistent view of the data (SELECT). A skipped row may be free a millisecond later. That is fine when proposing seats, because another good pair will do. It is wrong when the fan named B5, because skipping B5 would tell her it is taken when it is not.

The gap: A map is out of date the moment it is drawn, because seats change hands while fans look.

Option 1: Read the seat rows on every load

Each map load reads all 20,000 seats from the seat database.

Works when: A small venue with a trickle of viewers.

Breaks when: At the rush that is 333 million row reads a second on the selling database.

Option 2: Cache the whole map for 30 seconds

Build the full map once and serve every fan the copy.

Works when: Seats change slowly, as on a quiet day.

Breaks when: At the rush the copy is wrong about 6,000 seats, and costs 5.33 GB/s at the edge.

Option 3: Split the drawing from the availability (start here)

Cache the drawing for days, and a 2,500-byte bitmap for about a second.

Works when: At every size here. The CDN answers almost every request.

Watch for: A few seconds of lag, paid in taps that meet “taken”.

Fix within it: Answer a lost tap with the nearest free seat.

Option 4: Push every change as it happens

Keep a server-sent events stream open to each map.

Works when: Seconds matter more than cost.

Watch for: A million open connections live on our servers instead of the CDN.

In the interview: Open with option 3, with the arithmetic: 2,500 bytes a load, about 41.7 MB/s from the CDN. Mention option 4 as what you would do if the interviewer says a few seconds of lag is not acceptable, and say what it costs.

Say this: The map is a hint and the hold is the truth. So I split what never changes, the drawing, from what does: a 2,500-byte availability bitmap, cached for a second and polled. That keeps a million open maps on the CDN, and a tap on a seat that just went comes back with the nearest free alternative.

A million fans arrive at 10:00 for 20,000 seats. What happens to the database?

An average order is two seats, so 20,000 seats is 10,000 orders. A million fans for 10,000 orders is 100 fans for every order, or 50 for every seat. About one fan in a hundred will leave with tickets. The other 99 will all try, many of them several times. Scripts will try hundreds of times a second.

The simplest answer lets everyone at the booking API. Watch what happens at 10:00. Holds pile up behind the locks on the best seats and time out. Fans and scripts retry. The load climbs exactly as the database slows down, and the sale gets slower for everyone.

So protect the database with a rate limit. Above what it can serve, the API answers “too many requests, try again”. The database is safe. Now look at who gets through. Each free place goes to whoever retries fastest. A script retrying every 50 milliseconds beats a fan who arrived early and waited. The limit protected the database and handed the sale to the scripts.

The fix is a line with a place in it. A virtual waiting room gives every fan a place, lets them in at the rate seats can be sold, and tells the rest early.

How fast should it admit? The database could take more than 100 holds a second, so the servers are not the limit. The seats are. Admit 100 fans a second, two seats each, and the whole venue is held within 20,000 ÷ 200 = 100 seconds. Every fan admitted after that finds nothing, until held seats come back. So the room admits at about that pace while seats remain. Then it slows to the rate abandoned holds give seats back, and tells everyone behind that the sale is sold out.

Order is where fairness lives. Fans who arrive before the sale opens get a place drawn at random when it opens, so refreshing at 9:59:59 buys nothing. Anyone who arrives later joins at the back.

An admitted fan gets a short-lived signed pass, bound to their account. The Booking API refuses a hold without one, so skipping the line does not work. Limits per account, such as one active hold per show, are checked by the Booking API, not the browser. When every seat is held, the room tells the whole line at once. When abandoned holds give seats back, it admits a few more fans.

A pass bound to one account stops a pass being shared. It does nothing against one person running 500 accounts; that is fraud work. At the most extreme sales, some sellers go one step further: fans register days ahead, and a draw decides who may buy. That stops most bots, and it means running a second product, with registration, verification and a draw. Most sales do not need it.

Ticketmaster’s guide says its waiting rooms open 15 to 30 minutes before a sale. A fan who joins after the start goes to the back (how the queue works). So does a fan who enters from a new device (queue help). Queue-it, a waiting room vendor, documents drawing the early arrivals’ order at random (pre-queue).

The interactive version of this example is available when JavaScript loads.

The flash sale breakdown builds this waiting room in depth, with its admission model and fairness rules. The edge load shedding article explains why the cheapest place to refuse work is as far forward as possible.

The gap: A million fans want 20,000 seats, fifty fans for every seat, so most lose whatever we build.

Option 1: Let everyone at the booking API

Every fan who clicks goes straight to the hold endpoint.

Works when: Demand is below what the database can serve, as for most shows.

Breaks when: Holds time out behind locks, retries pile on, and the load climbs as the database slows.

Option 2: Rate-limit the booking API

Refuse requests above what the database can serve.

Works when: The goal is only to protect the database.

Breaks when: Each place goes to whoever retries fastest, which is a script.

Option 3: A virtual waiting room (start here)

A place in line for every fan, admission at the selling rate, and a signed pass the Booking API checks.

Works when: Any big on-sale. It is fair, and it can say “sold out” to the whole line at once.

Watch for: One person runs 500 accounts.

Fix within it: Treat many accounts as fraud work, outside the line.

Option 4: Register first, and draw winners before the sale

Fans register days ahead, and a draw decides who may buy.

Works when: Even a fair line would be mostly bots.

Watch for: Fans must act days ahead, and the service runs a second product.

In the interview: Open with option 3, and give its admission rate from the seats, not the servers: 100 holds a second holds the whole venue in about 100 seconds. Mention option 4 when the interviewer asks about bots at a record-breaking sale.

Say this: A million fans for 20,000 seats means most lose, so the system’s job is to pick winners fairly and tell the rest early. A waiting room gives each fan a place, admits them at the rate seats can be held, and hands each a signed pass the Booking API checks. Once every seat is held, it tells the whole line.

If they push: how does general admission change the design?

A festival sells 40,000 field tickets with no seat numbers. There is no map and no party to seat together. The whole inventory is one number: how many are left.

One row holding a counter, decremented only while it stays at zero or above, replaces the seat rows. Holds still carry a deadline. A counter cannot treat an expired hold as free at decision time. So a job adds each expired hold’s tickets back to the count, once, guarded by the hold ID. Payment works exactly as above. The new problem is heat: every buyer now updates the same row. Split the count across several rows and add them up to read the total, or hand out blocks of tickets to each server in advance. The atomic counter article shows how to change a shared number without losing updates. The flash sale breakdown is this problem at full size.

If they push: the seat database’s primary dies at 10:02. Can a seat be sold twice?

Noor’s booking committed at 10:01:59. At 10:02 the machine running the seat database for her show dies. A standby takes over. Does the standby know B4 and B5 are sold?

Not necessarily. A standby copies the primary a moment behind it. Promote the one with the most recent changes, and it may still be missing the last second. If Noor’s booking is in that second, the new primary shows B4 and B5 as free and sells them again.

So the primary confirms a booking only once a standby has it too, and that standby is the one promoted. Now a failover cannot lose a confirmed booking. The price is one round trip to the standby on every hold, a millisecond or two in the same region. A standby in another region would add its round trip to every hold, so keep the synchronous standby close and send the far copies asynchronously.

One gap is left. The old primary may not be dead, only cut off from whatever decided to fail over. If another standby still acknowledges its commits, servers that can reach it keep taking holds. Two primaries then sell the same seats. So before promoting a standby, make sure the old primary can no longer accept writes. One way is a lease: a permission to act as primary that runs out unless it is renewed. Take the old primary’s lease away. That step is called fencing. If no safe primary can be chosen, stop taking holds for that show, and keep search and the map up.

PostgreSQL documents how to name the standbys a commit must wait for (synchronous replication). The database failover article walks through a failed primary that can still write, and the leader and follower replication article explains why a standby runs behind.

A stadium sale runs on its own primary, so a failover pauses one sale, not every sale. If one show is ever too hot for one primary, split it by section. Parties must then stay inside one section, because a hold across two sections would span two machines.

Walk one booking through the final design

Noor waits in the waiting room from 9:50. At 10:00 she gets a random place near the front, and a signed pass seconds later. Her map comes from the CDN: a drawing cached for days and a 2,500-byte bitmap a second old. She taps B4 and B5.

The Booking API checks her pass and opens one transaction. It locks B4, then B5, reads the database clock, and finds both free. It stamps both with H1 and a deadline of 10:10, then commits. The change feed updates the bitmap. Every open map turns the pair grey within seconds.

Noor presses Pay. C1 is saved with its key, H1 is extended once by a few minutes, and the provider is asked to authorise $180. The provider’s event reaches the webhook intake, which checks the signature, stores the event, and confirms from the stored copy: H1 still owns both seats. The seats become booked. A booking, two tickets and an outbox row are written in one transaction, the money is captured, and a worker emails the tickets.

If the event had arrived after H1 lost the seats, the confirm would have found no rows. It would have recorded a cancelled authorisation or a refund owed instead. Kofi would have kept the pair.

The interactive version of this example is available when JavaScript loads.

RequirementWhere it is metThe trade-off
FR1 find an eventSearch index fed from the catalog, CDNEvent pages can be a few seconds behind the catalog
FR2 see the seat mapCached drawing and a one-bit-per-seat bitmap from the change feedA green seat can already be gone; the hold says so
FR3 hold seatsOne transaction per hold, seats locked in order, deadline from the database clockEvery hold for a show goes through one primary
FR4 pay or be refundedStored attempts, guarded confirm, webhook intake, authorise then captureA late payment becomes a refund or a cancelled authorisation, never a stolen seat
FR5 tickets and releaseExpired means free at decision time; outbox; reconcilerBackground workers tidy up, and none of them decides ownership

How does the answer change for BookMyShow, festivals, flights or hotels?

Interview variantWhat carries overWhat changes
Design Ticketmaster (a stadium sale)Everything on this pageThe rush dominates: the waiting room and the map carry most of the load
Design BookMyShow (cinema seats)Seat rows per show, holds, paymentsThousands of small shows spread the load, so the waiting room matters less and search by city and time matters more
General admission festivalHolds, deadlines, paymentsA counter replaces the seat map, and one hot row becomes the problem
Airline seat bookingHolds with deadlines, payment recoveryOne trip can span several flights owned by different systems, so one transaction is no longer enough
Hotel bookingScarce stock held for a timeA stay is several nights, each with its own stock, and room types replace numbered seats
Movie ticket booking, as a low-level designThe same entitiesThe interview is about classes and methods inside one program, not machines and failures

What should an answer reach at each level?

LevelWhat the answer shows
Intern or mid-levelSeparates the cached map from the seat rows. Holds seats in one transaction with a deadline, and books them after payment.
SeniorLocks a party’s seats in order, treats expired holds as free, and conditions every step on the hold ID. Treats a lost payment reply as unknown, reuses one key, and refunds a late payment instead of taking the seats back.
StaffSizes the map as a bitmap and the hold length from the sale’s numbers. Designs a fair waiting room with passes and limits. Makes failover lose no booking and never run two primaries.
PrincipalSets the hold, refund and fairness policies with the business, and shows what each costs in seats, money and trust. Explains how the design changes for general admission, many small shows and multi-leg trips.

Test yourself with the quiz, then pick another problem from the System Design interview breakdowns.

By GOAT Engineer. Back to all breakdowns. Privacy Policy · Contact.