Your seat hold ran out while the buyer was still paying

The interviewer says the ticket site sold seat F12 to two people during a concert sale, and asks where the bug is. You say "put a lock on the seat", and the next question arrives at once: held for how long, and what happens to the person who is still typing their card number when it runs out?

The requirement

A hall has 20,000 seats, and sales open at ten o'clock. Far more people arrive in the first minute than there are seats. Buyers pick a seat on a map, then go to a payment page, where most of them spend two to four minutes and a few spend ten.

The requirement has two halves. A seat is sold at most once. And a seat that someone chose and walked away from goes back on sale soon, because an empty seat is lost money too.

What goes wrong, with the input that shows it

The first bug is the one most candidates find: the code reads the seat, sees it free, and writes the sale later. Two requests read "free" in the same millisecond and both write. The fix is to make the write itself the check: one conditional update, and if it changed no row, you did not get the seat.

The second bug is the one the interviewer is waiting for. Suppose you hold the seat for eight minutes when it is picked, then mark it sold after payment:

  1. Buyer A picks F12 at 10:00:00. The hold runs to 10:08:00.
  2. A's bank asks for an extra check, and A is still on the payment page at 10:08.
  3. Buyer B picks F12 at 10:08:10. The hold has expired, so B gets it.
  4. A's payment succeeds at 10:08:20, and the code runs "mark F12 sold".

If that last step is a plain update on the seat, both A and B are now told the seat is theirs. The hold was conditional; the sale was not.

Two designs and what each one costs

Option A: no hold, claim the seat after payment. The buyer pays, and then one conditional update claims the seat if it is still unsold.

Option B: hold first, and make the sale conditional on still holding. Picking a seat claims a hold with an expiry. Paying ends with an update that succeeds only for the current holder.

HOLD_SECONDS = 480  # eight minutes to pay

def hold(db, seat, buyer, now):
    cur = db.execute(
        "UPDATE seats SET holder = ?, hold_until = ? "
        "WHERE seat = ? AND sold = 0 AND (holder IS NULL OR hold_until <= ?)",
        (buyer, now + HOLD_SECONDS, seat, now))
    return cur.rowcount == 1

def confirm(db, seat, buyer):
    cur = db.execute(
        "UPDATE seats SET sold = 1 WHERE seat = ? AND holder = ? AND sold = 0",
        (seat, buyer))
    return cur.rowcount == 1  # False: release the card authorisation

Trace the story above, in seconds from ten o'clock. hold(F12, A, 0) returns True. hold(F12, B, 100) returns False, because the hold runs to 480. hold(F12, B, 490) returns True, because the hold expired. confirm(F12, A) returns False, because the holder is now B. confirm(F12, B) returns True. One sale.

Two details are worth saying. Expiry needs no clean-up job: the next hold checks it. And confirm does not check the clock. If A's hold expired but nobody took the seat, A's late payment still gets it, which is what A wanted.

What to say out loud

Ask first: "How many buyers want the same seat at the moment of sale, and how long does paying take?" Then commit to both branches: "If two people rarely want the same thing, I skip the hold and claim it with one conditional write after payment. If many want each seat at once, I hold it on pick, sell it only to the current holder, authorise the card during the hold and charge only after the sale is written. The hold length comes from how long people really take to pay."

The exercise

  1. Pick something you have built where two people can want the last unit: a slot, a seat, an item, a username.
  2. Write down the time between choosing it and the moment it is final.
  3. Write the four-step story where that time runs out, with clock times, as above.
  4. Write the condition your final write needs so that the story ends in one sale.
  5. Say the deciding question aloud, then your choice for each answer to it, in under a minute.

Where this fits in Gadfly

System design is one of Gadfly's four rooms, alongside algorithms, behavioral and code review. The design is drawn on a shared board, guided or as a mock, one trade-off at a time. In guided mode the tutor asks the next question, such as what happens when the hold runs out mid-payment, and does not hand over the design. In a mock it behaves like an interviewer: no coaching during the round, then a debrief that quotes what you said rather than giving a grade.

Published 25 November 2026 · System design: one trade-off · all notes · feed

This note was drafted by Gadfly's scout — an automated writing agent run by Dmytro Hryshchenko — and checked by rules against the product's claims registry, not read by a person before it went live. The exercise is original. Spotted a mistake? [email protected].