TOUGH TONGUE AI
  • Home
    LogoTOUGH TONGUE AI

    RESOURCES

    Loading...

    HomeLibrarySD Mock · Design Ticketmaster

    SD Mock · Design Ticketmaster

    SD Mock · Design Ticketmaster

    Overview

    Design a ticket booking system like Ticketmaster or BookMyShow on a live architecture board: drag components, wire them up, and defend your design to an expert interviewer who watches every move.

    Your Instructions

    Design Ticketmaster

    A 20-minute mock system design interview. You drive the pace. Jump to the board when you are ready; skip capacity math if you want. The interviewer grades your thinking, not a template match.

    This question looks like CRUD and is not. The inventory is finite and unique: seat G14 for the 7 pm show exists exactly once. The signal concentrates in three places: how you guarantee a seat is never sold twice, how a 5-minute hold expires safely, and whether you see that a hot on-sale is an admission problem, not a database-throughput problem. "Wrap it in a transaction" is not a design.

    Two shared surfaces (only one is on screen at a time; use the panel arrow to switch):

    • Notepad. Shared notes. Requirements, capacity math, schema, and end-of-session feedback live here. You can type in it too.
    • Architecture board. Your design canvas. Drag typed components, wire them, label edges, mark scaled tiers as distributed. If it is not on the board, it is not in your design.

    Build incrementally while you talk. Trace one booking end to end through your diagram, from seat map to confirmed ticket, including the user who loses the race. Argue the tradeoff, not "industry standard."

    Design choices interviewers probe

    Read this before you go in. These are the decisions, and why they matter.

    Preventing double booking

    The naive flow is read seat status → check it is free → write HELD. Two users click seat 55 in the same millisecond: both read "free", both write, both get charged. The check and the write must be one atomic step on the seat rows.

    Grokking's answer is a SERIALIZABLE transaction: select the requested Show_Seat rows that are free, confirm the count, update seats and booking, commit. It is correct, but a serializable read takes shared locks, so two concurrent bookers usually deadlock or abort and retry, exactly when traffic peaks. The sharper default is a conditional update: UPDATE Show_Seat SET status=HELD, hold_id, expires_at WHERE show_id=99 AND seat_id IN (54,55,56) AND (status=AVAILABLE OR expires_at < now()), then check the affected row count; fewer than requested → roll back, return 409. Row locks last microseconds and the default isolation level is enough. SELECT … FOR UPDATE with seat IDs sorted (to avoid deadlocks) is equally defensible. A unique constraint on (show_id, seat_id) in the tickets table is the last line of defence.

    A Redis lock (SET seat:99:55 NX PX 300000) is fast and gives expiry for free, but it is a second source of truth. Use it as a filter in front of the database if you like; the database still enforces the commit.

    Holds and expiry

    A hold lasts 5 minutes. A database transaction must not. So the hold is state on the seat row (HELD, hold_id, expires_at), not an open transaction.

    Grokking tracks live holds in memory in an ActiveReservationsService: per show, a linked hash map from booking ID to creation time, head = oldest, so expiry pops from the head and completion removes in O(1). The durable copy is the Booking row with Status = Reserved. It adds a 5-second server-side buffer so the client's countdown always ends first.

    The stronger refinement is lazy expiry: put expires_at in the hold predicate so an expired hold is free the instant it expires, even if the sweeper is late or dead. The sweeper then only tidies up and wakes waiting users. Also know the late-payment case: payment succeeds 20 seconds after the hold expired. Confirm must be conditional too (seats become BOOKED only where still HELD by this hold_id); otherwise rebook if still free, or refund.

    The on-sale surge

    Grokking's averages: 3 B page views and 10 M tickets a month is about 4 tickets per second. The real problem is the on-sale: BookMyShow's Coldplay sale had about 13 M people queued for about 150 K tickets. Even selling out in 30 minutes is only ~83 tickets per second. The booking database is not the bottleneck; arrivals are.

    So put a virtual waiting room in front of booking. The waiting page is static on a CDN. An admission controller lets users through at a rate the booking path can handle (keep a few thousand active shoppers per show) and hands each a signed admission token that the booking service verifies locally. "Autoscale everything" is the weak answer: you would be scaling to serve millions of seat-map refreshes for seats that do not exist.

    Fairness: FIFO or random?

    Grokking serves waiting users strictly first come, first served: a per-show WaitingUsersService (linked hash map, head = longest waiting) notified over long polling when holds expire. That is right for "all seats held, some may free up."

    For a pre-sale crowd, strict FIFO rewards whoever's packet lands first at 12:00:00, which means bots. Ticketmaster's queue gives everyone who arrives before the start a random position, then appends later arrivals in order. Speed buys nothing. Pair it with login, per-account limits enforced at hold time across all of that account's holds, and rate limits at the gateway. Either policy is defensible if you can say who it favours.

    Payments and idempotency

    Payment is an external, slow, sometimes ambiguous call. Double-clicks and retries must not charge twice. Send an idempotency key (use hold_id) to the provider, treat the provider's webhook as the source of truth, and make the confirm write conditional on the hold. If the provider goes down mid-sale: stop admitting new shoppers, extend or pause existing holds, resume on recovery. Do not book seats you have not been paid for.

    Partitioning and the hot show

    Grokking: partition by ShowID, not MovieID; MovieID piles every show of a blockbuster onto one server. Keep Show_Seat, Booking and the show's holds on the same shard so hold and confirm are single-shard transactions. The hottest show is still one partition, and that is fine: with admission control its write rate is tens per second. What needs protecting is its read path: cache the seat map for 1–2 seconds and push seat changes to viewers instead of letting thousands refresh.

    Reference solution

    One complete design you can study, then rebuild in your own words. Do not recite it. In the interview, draw your graph and defend the choices.

    Requirements (lock these or take the defaults)

    • Browse by city → movie → cinema and showtime; search by keyword, location, date
    • Seat map that shows available vs held vs booked
    • Select up to 10 seats, all or nothing; hold for 5 minutes while paying
    • If no seats are free but some are held, users may wait (max 1 hour) and are served fairly
    • Non-functional: never double book (ACID on seats and bookings), highly concurrent, survive release-day spikes, secure payments via an external provider
    • Out of scope unless asked: refunds, resale, dynamic pricing, general admission

    Capacity

    • Traffic: 3 B page views/month ÷ 2.6 M s ≈ 1,160 page views/s; 10 M tickets ÷ 2.6 M s ≈ 4 tickets/s; read:write = 3 B ÷ 10 M = 300:1
    • Storage: 500 cities × 10 cinemas × 2,000 seats × 2 shows = 20 M seat-shows/day × 100 B = 2 GB/day, ≈ 3.6 TB over 5 years. Those rows are Show_Seat inventory, not bookings.
    • Surge: 13 M queued ÷ 150 K tickets ≈ 87 people per ticket; 150 K tickets in 30 min ≈ 83 tickets/s. Waiting clients polling every 10 s = 1.3 M req/s, so the waiting page lives at the edge.

    Rough numbers are fine; the method is what gets graded. The win is using them: "commits are tiny, arrivals are huge, so I build admission control, not a bigger database."

    Components to put on the board

    How the graph works: browsing and booking are separate branches. Browsing (search, show lists, seat maps) is read-heavy, cached, and allowed to be a second stale. Booking goes through a waiting room, then a Booking Service that places holds with one atomic statement against Postgres, tracks expiry in Redis, and confirms after the payment provider says yes. Seat changes are pushed back to viewers.

    Web Client, Mobile Client
        → CDN (static pages + the waiting-room page)
        → API Gateway (auth, Rate Limiter rules; mark distributed)
            → Service "Search" → Elasticsearch  ← Postgres "Catalog" (CDC)
            → Service "Waiting Room" ↔ Redis "Queue" (per-show sorted set) → signed admission token
            → Service "Booking" (mark distributed)
                 ↔ Postgres "Bookings" (Show_Seat, Booking; sharded by ShowID)   [atomic hold, conditional confirm]
                 ↔ Redis "Holds" (hold_id → seats, TTL 5 min + 5 s)
                 → Third-party API "Payment provider" (idempotency key = hold_id; webhook back)
                 → Pub/Sub Topic "seat changes" → WebSocket Server → clients
            Worker "Hold sweeper" → Postgres + wakes Waiting Room when seats free
    

    Components:

    • Web Client, Mobile Client. Browse, queue, pick seats, pay. They show a hold countdown that ends before the server's.
    • CDN. Serves static pages and, during a sale, the waiting-room page. Without it, 13 M refreshes hit your origin.
    • API Gateway (with Rate Limiter). TLS, auth, per-IP and per-account limits. The first bot filter.
    • Search Service + Elasticsearch. City, movie, cinema, showtime queries. Fed from the catalog Postgres by change data capture; cached and CDN-friendly.
    • Waiting Room Service + Redis queue. Per-show queue; randomises pre-sale arrivals, FIFO after; admits users at a controlled rate; issues signed admission tokens with a ~10-minute window.
    • Booking Service. Stateless, marked distributed. Verifies the admission token, places holds with one conditional update, confirms after payment, enforces per-account seat limits.
    • Postgres (Bookings). The source of truth for Show_Seat and Booking. Sharded by ShowID so a show's seats, holds and bookings live together. ACID is the reason it is relational.
    • Redis (Holds). Fast lookup and TTL for live holds. Not the authority: the seat row's expires_at is.
    • Third-party API (Payment provider). Charges with an idempotency key; its webhook confirms.
    • Worker (Hold sweeper). Clears expired holds, emits seat-freed events, wakes waiting users. Correctness does not depend on it because of lazy expiry.
    • Pub/Sub Topic + WebSocket Server. Pushes seat-map diffs and queue positions. Long polling is Grokking's equivalent and equally fine.

    Walk one booking: Fan A holds G14–G16 for show 99 and pays

    1. A opens show 99 from the Web Client; the seat map comes from cache (1–2 s old). G14–G16 are green.
    2. It is a hot show, so A is in the Waiting Room first; when admitted, A's client receives a signed admission token.
    3. A sends POST /holds {G14, G15, G16} with the token. The API Gateway checks the rate limit; the Booking Service checks the token and A's seat count for this show.
    4. The Booking Service runs one conditional update on the Postgres shard for show 99: three rows AVAILABLE (or expired) → HELD with hold_id and expires_at = now + 5 min. Three rows changed: success. The hold is recorded in Redis with a TTL.
    5. Fan B's request for G15–G16 lands 3 ms later. The same statement matches zero rows; B gets 409 with the taken seats and returns to the map.
    6. A pays. The Booking Service calls the payment provider with idempotency key = hold_id. The webhook reports success.
    7. The Booking Service flips the three rows HELD (by this hold) → BOOKED, writes the Booking row, deletes the Redis hold, and publishes a seat-change event. Viewers' maps turn G14–G16 red over the WebSocket Server.

    A never pays: at expires_at the seats are free again for the next conditional update, whether or not the sweeper has run. The sweeper tidies the rows and tells the Waiting Room seats freed up.

    Payment lands after expiry: the confirm update matches zero rows. Rebook in the same transaction if the seats are still free, otherwise refund automatically.

    The Waiting Room node dies: the queue lives in replicated Redis and each user holds a signed queue ticket with their position, so a replacement re-admits them in order. Grokking's in-memory WaitingUsersService loses the queue here unless it has a secondary; say so.

    Schema

    Show(show_id, movie_id, cinema_hall_id, starts_at)
    Show_Seat(show_id, seat_id, status [AVAILABLE|HELD|BOOKED], hold_id, expires_at, booking_id, price)
    Booking(booking_id, user_id, show_id, num_seats, status [RESERVED|BOOKED|EXPIRED], created_at)
    Payment(payment_id, booking_id, amount, provider_txn_id, idempotency_key, status)
    Hold (Redis): hold:{hold_id} → {show_id, seat_ids, user_id}  TTL 305 s
    Queue (Redis): queue:{show_id} → sorted set of user_id scored by position
    
    • Primary key (show_id, seat_id) on Show_Seat; unique (show_id, seat_id) on issued tickets
    • Shard Show_Seat, Booking and holds by show_id; replicate each shard primary–secondary
    • Catalog tables (City, Cinema, Cinema_Hall, Movie) are small: replicate, cache, index into search

    Scaling and wrap-up

    • Booking Service and API Gateway scale horizontally; Postgres scales by ShowID shard; Redis replicated
    • The CDN and caches absorb browsing (300:1 on a normal day, far more during a sale); the Waiting Room absorbs the surge; Postgres only sees admitted, contended writes
    • First metrics: oversold seats (must be zero, reconciled nightly), hold → booking conversion and hold expiry rate, 409 rate, queue time p99, payment error rate
    • If time: best-available seat selection, general admission (atomic counter instead of seats), resale and transfer, bots and Verified Fan style pre-registration

    Equally defensible variants

    SELECT … FOR UPDATE or optimistic versioning instead of the conditional update. Grokking's SERIALIZABLE transaction, if you name its abort cost. Grokking's in-memory ActiveReservationsService and WaitingUsersService with consistent hashing on ShowID, if you give them a recovery story. Redis locks with TTL in front of the database. Long polling or SSE instead of WebSockets. What matters is that you can argue the tradeoff.

    More in System Design Interview Prep: AI Coach Edition

    • SD Mock · Design a Web Crawler
    • SD Coach · Distributed Storage
    • SD Mock · Design a Key-Value Store
    • SD Coach · File Sync: Dropbox and Google Drive
    • SD Mock · Design Dropbox
    • SD Coach · Transactional Systems
    • SD Coach · Batch and Stream Pipelines
    • SD Coach · Real-Time Chat and Collaboration
    • SD Mock · Design Facebook Messenger
    • SD Mock · Design Uber Backend
    • SD Mock · Design Yelp / Nearby Friends
    • SD Coach · Media Streaming
    View the full course (43 sessions) →