Buildfest Learn System DesignRead and experiment freely · Chapter activities stay in this tab
Practice librarySystem DesignWorked interview ticket booking

LESSON 13 • SYSTEM DESIGN

Worked interview ticket bookingMany buyers. One seat.
Keep every booking correct.

Worked interview ticket booking. Learn the concepts, explore a model and defend your design.

DEFINITION

A ticket-booking system coordinates scarce inventory and uncertain payment outcomes. Browsing can show an approximate seat map, but reservation and sale need an authoritative state transition that prevents two buyers being promised the same seat. This is an original worked solution to a Microsoft candidate-reported ticket-booking topic.

A seat has a controlled state machine
  1. STEP 1AvailableCan attempt a hold
  2. STEP 2HeldExpires under a stated rule
  3. STEP 3ConfirmedPayment + seat rules satisfied

A transition must be atomic at its authority; a screen displaying availability does not own the seat.

CONCEPT 1

Microsoft reported topic · A ticket-booking service

1 Clarify the teaching problem

Let users view a show, temporarily hold a specific seat and confirm a purchase. The key rule is that one seat cannot be sold to two different buyers. Browsing may tolerate a slightly stale seat map, while checkout must use an authoritative decision. For this example, assume a three-minute hold and a payment sandbox. These choices explain the solution; they are not established as Microsoft's exact question.

2 Model the seat and the operation

Use Show, Seat(show_id,seat_id,state,hold_token,hold_until) and Booking(id,user_id,seat_id,status,operation_key). Define a uniqueness rule for one successful sale per show and seat. Scope operation_key to the customer and intended checkout. Add a hold token that changes whenever ownership of a hold changes, so a delayed event cannot act as the newest seat holder.

3 Make the hold atomic

In one database transaction, change an available or expired seat into a held seat and record its token and expiry. A conditional update or appropriate locking strategy ensures only one competing request wins. Check the update result; another request should receive an unavailable outcome. Do not decide based solely on a cached map or an earlier read that said available. Avoid holding the database transaction open while waiting for the payment network.

CONCEPT 2

Ticket booking · Solve the failure follow-ups

4 What if the request or response is lost

Before a request reaches the server, nothing may have happened. After a successful commit with a lost reply, a hold or booking may already exist. The retry must reuse its original operation key and look up the existing result. A fresh key can be a new purchase intent, so do not create one automatically on every timeout. This distinction prevents duplicate bookings caused by uncertain network outcomes.

5 What if payment arrives after the hold expires

A callback must prove the provider event is authentic and refer to the intended booking and hold token. Apply a transition only if the current state still allows it. If that seat has since been allocated to another buyer, do not overwrite the newer ownership. Use a declared recovery policy, such as refund or manual reconciliation. Release expired holds safely, and coordinate cleanup with checkout so both cannot win different interpretations of the same state.

6 What if the service is under heavy demand

Cache suitable show details and browsing data, but send holds and final confirmation to the authoritative transactional path. A waiting room, per-user limits and bounded concurrency can protect it. If the authority is unavailable or partitioned, reject or defer uncertain seat sales rather than letting both sides independently promise the final seat. Observe hold success, expiry, payment reconciliation, contention and duplicate-operation handling.

A concise model answer

I would separate approximate browsing from strongly coordinated purchase state. A database-enforced hold and unique sale rule protect the seat, while an operation key makes retries safe. I would not hold locks across payment calls. Authenticated callbacks and reconciliation would handle uncertain payment outcomes, including late success after a hold has expired.

Payment and booking are separate state machines
  1. STEP 1Provider succeedsPayment result becomes known
  2. STEP 2Booking ruleHold may already have expired
  3. STEP 3ReconcileConfirm or refund under policy

Retries and duplicate callbacks must not create extra seats or duplicate refunds.

Key learning points

  • Separate approximate browsing from authoritative reservation.
  • Use a stable operation identity and a changing hold token for different hold ownerships.
  • Keep locks short and external payment outside a long-held local transaction.
  • Late callbacks and expired holds need explicit reconciliation.

Compare the important ideas

Worked interview ticket booking: concepts and trade-offs
Seat or booking stateAllowed next behaviorRequired check
AvailableCreate one held reservationAtomic authoritative decision
HeldPay, expire or releaseCurrent holder/token and time policy
Payment pendingConfirm or reconcileAuthenticated provider evidence and allowed transition
ConfirmedFulfil or follow a cancellation policyNo second successful sale for that seat
Expired holdNew reservation may be allowedOld callback cannot overwrite a newer holder

WORKED EXAMPLE

A safe lost-reply path

An order operation commits a hold, but its reply is lost. The app sends the same user-scoped operation key again. The service returns the existing hold/result rather than creating a new purchase. If payment success arrives after that hold expired and a newer buyer owns the seat, the old hold token must not authorize a sale. Resolve the money under the declared refund or reconciliation policy.

Further reading

Original teaching explanations by Buildfest Learn. Check these primary references for the underlying concepts and implementation details.

Interview cases adapt publicly reported topics with original teaching constraints and solutions. They are not official company questions or answer keys.