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.
- 01
Two people tap seat 14A at once. How does exactly one win?
Two people, one seat · optimistic locking
the checkPlay this labAND status = 'available'and only if it is still free - 02
You hold a seat and walk away. How does it come back?
The hold that frees itself · seat hold expiry
orPlay this labOR (status = 'held' AND held_until < now()))or its hold has run out - 03
The payment goes through, then the server dies. Now what?
Money taken, seat not confirmed · payment failure handling
save bothPlay this labCOMMITtogether, or neither - 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 changePlay this labUPDATE show_seat SET status = 'payment_pending'mark the seat as being paid for