{}DSA Atlas

Design a Ticket Booking System (Ticketmaster / BookMyShow)

Selling limited seats under extreme contention — event and seat-map modelling, temporary seat holds with TTLs, preventing double booking (conditional updates, row locks, Redis holds), the booking state machine with payment, the virtual waiting room for on-sales, bots and fairness, caching seat availability, and recovering from abandoned holds.

Advanced5 interview questions

1. Requirements

Functional

  • Browse events; view seat maps with availability.
  • Select seats → hold for 10 minutes → pay → receive tickets (QR codes).
  • General admission (quantity only) and reserved seating.
  • Cancellation/refunds per policy.

Non-functional

  • No double booking — ever (strong consistency for seat state).
  • Huge read spikes on popular on-sales (millions of users in minutes); normal days are quiet.
  • Fairness and bot resistance for hot events.
  • Availability of browsing even when booking is throttled.

2. Estimation

QuantityValue
Hot on-sale10M users in the first 10 minutes; 70k seats
Seat-map views~100k/s at peak → must be cached
Hold attemptsadmitted at the rate the booking DB handles (e.g., 2–5k/s)
Normal daythousands of events, ~100 bookings/s

3. Data model

SQL
CREATE TABLE events (id BIGINT PRIMARY KEY, venue_id BIGINT, starts_at TIMESTAMPTZ, on_sale_at TIMESTAMPTZ, status TEXT);

CREATE TABLE event_seats (                 -- one row per seat per event (copied from the venue map)
  event_id   BIGINT,
  seat_id    TEXT,                          -- "SEC112-ROW-F-12"
  section    TEXT,
  price_tier TEXT,
  status     TEXT NOT NULL DEFAULT 'AVAILABLE',  -- AVAILABLE | HELD | SOLD
  hold_id    UUID,
  held_until TIMESTAMPTZ,
  version    INT NOT NULL DEFAULT 0,
  PRIMARY KEY (event_id, seat_id)
);

CREATE TABLE bookings (
  id UUID PRIMARY KEY, user_id BIGINT, event_id BIGINT, hold_id UUID UNIQUE,
  status TEXT,                               -- PENDING_PAYMENT | CONFIRMED | CANCELLED | REFUNDED
  amount_cents BIGINT, payment_ref TEXT, created_at TIMESTAMPTZ
);

CREATE TABLE tickets (
  event_id BIGINT, seat_id TEXT, booking_id UUID REFERENCES bookings(id),
  PRIMARY KEY (event_id, seat_id)            -- final guard against double sale
);

Sharding by event_id keeps all contention for an event on one shard (single-shard transactions).

4. High-level design

users waiting roomCDN + queue tokens event catalogue(cached, search) availability cache(seat bitmap) booking svchold · confirm seat DBsharded by event payment svc / PSP holdexpiry ticketing → QR,email (async) admitted only
The waiting room meters traffic; the booking service and seat DB enforce correctness.

5. Booking flow

AVAILABLE HELD (10 min) SOLD hold (atomic) paid + hold valid expired / cancelled
Expiry makes abandoned carts self-healing.
SQL
-- Hold up to 4 seats atomically (all or nothing)
BEGIN;
UPDATE event_seats
   SET status = 'HELD', hold_id = :hold_id, held_until = now() + interval '10 minutes', version = version + 1
 WHERE event_id = :event_id
   AND seat_id = ANY(:seat_ids)
   AND (status = 'AVAILABLE' OR (status = 'HELD' AND held_until < now()));
-- application checks: rows_affected = cardinality(:seat_ids), else ROLLBACK and report conflict
COMMIT;

-- Confirm after payment
BEGIN;
UPDATE event_seats SET status = 'SOLD'
 WHERE event_id = :event_id AND hold_id = :hold_id AND status = 'HELD' AND held_until >= now();
-- rows_affected must equal seat count; then insert tickets (PK guards) and mark booking CONFIRMED
COMMIT;

For general admission (no seat IDs), use an inventory counter per section: UPDATE inventory SET held = held + :n WHERE event_id = ? AND section = ? AND sold + held + :n <= capacity, with hold records holding the quantity.

6. Deep dives

Virtual waiting room

  1. Before on-sale, users land on a static page (CDN) and receive a signed token with arrival time.
  2. At start, tokens are assigned random positions (those who arrived early are shuffled) and later arrivals appended.
  3. An admission controller admits N users/second based on booking-service health (closed-loop control).
  4. Admitted users receive a short-lived JWT; the booking API rejects requests without it.

Bots and fairness

Per-account and per-card purchase limits, verified-fan pre-registration, CAPTCHA/behavioural signals at queue entry, device fingerprinting, cancelling bot orders afterwards, and dynamic pricing or ID-bound tickets to reduce scalping.

Hot rows

All seats of one event on one shard is fine (contention per seat, not per event). For GA counters, split inventory into several sub-counters ("buckets") and pick one randomly to reduce row contention.

7. Trade-offs

DecisionChoice
Consistencystrong (single-shard ACID per event)
Hold mechanismDB conditional update with TTL columns (+ optional Redis front for speed)
Peak protectionwaiting room + admission control, not just autoscaling
Availability displaycached bitmap, eventually consistent; hold is the source of truth
Paymentsaga with idempotency + reconciliation

See also the object-oriented design of this problem in LLD case studies II.

Interview questions

0 / 5 marked confident

Answer out loud first, then open the model answer. Mark a question confident only when you could explain it to an interviewer without notes.