Let’s talk
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
  1. 1const seat = await db.get("seat");AliceBob
  2. 2if (seat !== "available") return "SOLD_OUT";
  3. 3await payments.charge(userId);
  4. 4await db.set("seat", "booked");
  5. 5await db.insert("bookings", userId);
  6. 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
Postgres
A1

available

A2
A3
A4

bookings

  • (no bookings)

payments

  • (no charges)

What happened

  1. Step a request to begin.
0 steps · 0 switches · par 2