All levels
Level 1 of 5 / you are the scheduler
The double-booked seat
One seat left. Alice and Bob both press Book, on two different servers. The handler checks that the seat is free, charges the card, then books it.
Your goal: make one of these false
- One seat, one bookingnot checked yet
- Nobody pays for a seat they do not getnot checked yet
bookSeat.ts
- 1const seat = await db.get("seat");AliceBob
- 2if (seat !== "available") return "SOLD_OUT";
- 3await payments.charge(userId);
- 4await db.set("seat", "booked");
- 5await db.insert("bookings", userId);
- 6return "CONFIRMED";
Alice and Bob hit Book at the same moment.
You decide whose request moves next. Get the seat sold twice.
AAlice
Midnight Jazz · Row A
Seat A1$120
Hasn't looked at the seat yet.
Card not charged
BBob
Midnight Jazz · Row A
Seat A1$120
Hasn't looked at the seat yet.
Card not charged
Postgreswhat the database holds right now
A1
available
A2
A3
A4
bookings
- (no bookings)
payments
- (no charges)
What happened
- Step a request to begin.
0 steps · 0 switches · par 2