Skip to the page
THE HOT PATH

Design a ticket booking system

One seat. Two people who want it. And 50,000 people hitting one show at once. 4 labs, about three minutes each.

Play the first lab Watch the video

  1. 01

    Two people tap seat 14A at once. How does exactly one win?

    Two people, one seat · optimistic locking

    the check AND status = 'available' and only if it is still free
    Play this lab
  2. 02

    You hold a seat and walk away. How does it come back?

    The hold that frees itself · seat hold expiry

    or OR (status = 'held' AND held_until < now())) or its hold has run out
    Play this lab
  3. 03

    The payment goes through, then the server dies. Now what?

    Money taken, seat not confirmed · payment failure handling

    save both COMMIT together, or neither
    Play this lab
  4. 04

    Her ten minutes end while she is paying. Who gets the seat?

    The hold that ends while she is paying · payment pending state

    the change UPDATE show_seat SET status = 'payment_pending' mark the seat as being paid for
    Play this lab

The whole design, in one video.

42 minutes: the requirements, the data model, the architecture, and every problem these labs play. A chapter that has a lab says so.

Watch on YouTube

  1. 0:00 The problem: one seat, sold twice
  2. 1:43 Functional requirements
  3. 3:02 Non-functional requirements
  4. 5:05 Capacity estimation
  5. 7:10 API design
  6. 8:58 Data model
  7. 11:56 High-level architecture
  8. 14:01 Never double-book: the atomic write Lab 1
  9. 19:31 Holding a seat without a cleanup job Lab 2
  10. 22:30 The on-sale surge: a waiting room
  11. 28:24 Payments and confirmation Lab 3Lab 4
  12. 34:51 Reads at scale: browse vs book
  13. 38:25 What breaks: failover and deadlocks
  14. 40:30 Putting it together