Scrivio Interview library
DebuggingIntermediate6 min read · updated 13 November 2026

A booking service holds seats for 8 minutes. Payment providers sometimes confirm after 9 to 12 minutes, by which time the seats have been resold; last month the same seat was sold twice 140 times, each needing a refund and an apology.

How do you make hold expiry and payment completion safe together, so no seat is sold twice and no buyer is charged for seats they lost?

We stop treating expiry and payment as two independent clocks. When payment starts, the hold moves to PAYMENT_PENDING with an expiry that covers the slowest provider, the sale is confirmed only by a conditional UPDATE on that hold, and the card is authorised first and captured only after the seats are confirmed, so a buyer who lost the seats has the authorisation voided instead of being charged. Late callbacks are handled idempotently by payment id, with automatic refunds, and we monitor and reconcile daily.

Why this question is asked

A double sale is one of the most expensive bugs a ticketing company can have: each one costs a refund, a support case and often a public complaint from someone standing at a stadium gate. The 140 double sales here are not random; they come from a race between two processes that each believed they owned the seat. Interviewers ask this to see whether we can find the race and close it with state transitions rather than with longer timeouts alone. In this answer, we will reconstruct the failure, then go through the four changes that fix it: conditional confirmation, a payment-pending state, authorise-then-capture, and idempotent late callbacks, and finish with monitoring.

1Reconstructing the Double Sale

Let us replay one of the 140 cases. Buyer 1 holds seat A-12 at 10:00 for 8 minutes and submits payment at 10:06. The provider is slow and confirms at 10:15. Meanwhile, at 10:08 the expiry job sees an expired hold and releases A-12, and at 10:10 buyer 2 holds it and pays instantly. At 10:15 buyer 1's confirmation arrives, and the old code marks the seat SOLD to buyer 1 because the payment succeeded. Two tickets now exist for one seat.

The root cause is that confirmation trusted the payment and not the seat. It read the hold, saw a successful payment, and wrote SOLD without checking that the hold still owned the seat at that moment. The expiry rule and the payment flow each made sense alone; together they were unsafe.

Step throughHow seat A-12 was sold twice
Buyer 1Booking serviceExpiry jobBuyer 2Provider
10:06 pay for hold H1
charge card
10:08 H1 expired: release A-12
10:10 hold and pay for A-12
ticket for A-12
10:15 H1 payment succeeded
ticket for A-12 again

7 messages in order. Play them, or step through them one at a time.

The late confirmation wrote SOLD without checking that hold H1 still owned the seat.

2Rule 1: Confirm Only Through a Conditional Transition

The first change makes double sale impossible regardless of timing. We never read the hold and then write; we confirm with one statement whose WHERE clause states everything that must still be true.

Java
UPDATE seats
SET status = 'SOLD', order_id = :orderId
WHERE hold_id = :holdId
AND status IN ('HELD', 'PAYMENT_PENDING');
-- 4 rows updated for a 4-seat hold -> the seats are ours, capture the payment
-- 0 rows updated -> the hold lost its seats, void the authorisation

Notice that buyer 2's hold replaced hold_id on A-12, so when buyer 1's late confirmation runs, the WHERE clause matches nothing and the update changes zero rows. The database, not the timing, decides. In a multi-seat hold we compare the count with the number of seats and roll back if it is short, so a partial confirmation never happens.

3Rule 2: Stop the Clock While Payment Is Pending

Rule 1 prevents double sales, but on its own it means buyer 1 loses the seat after paying, which is still a bad experience. So the second change stops expiry from racing an active payment. When the buyer submits payment, we move the hold to PAYMENT_PENDING and extend its expiry to cover the slowest provider's confirmation time. If the data shows confirmations up to 12 minutes, we extend to about 20 minutes from payment start.

Java
UPDATE holds
SET state = 'PAYMENT_PENDING', expires_at = now() + interval '20 minutes'
WHERE id = :holdId AND state = 'ACTIVE' AND expires_at > now();
-- 1 row -> start payment
-- 0 rows -> the hold already expired: ask the buyer to pick seats again, no card touched

The seat rows get the same longer expiry in the same transaction, and the expiry job only releases rows in state HELD whose time has passed, never PAYMENT_PENDING ones before their extended deadline. Notice that the transition itself is conditional too: we only start a payment for a hold that is still alive. This is the important ordering; we secure the seats first, then talk to the payment provider.

4Rule 3: Authorise First, Capture After the Seats Are Ours

Card payments have two steps. Authorisation asks the bank to reserve the amount on the card; capture actually takes the money. Most providers let an authorisation sit for days before capture, and voiding an authorisation costs the buyer nothing.

So we authorise while the hold is valid, run the conditional confirmation from rule 1, and capture only if it updated every seat. If it updated zero rows, we void the authorisation, and the buyer sees the reserved amount disappear instead of a charge followed by a refund days later.

Step throughAuthorise, confirm, then capture
BuyerBooking serviceDatabaseProvider
pay for hold H1
H1 -> PAYMENT_PENDING, extend expiry
authorise amount
authorised
UPDATE seats SET SOLD WHERE hold_id = H1
4 rows
capture
tickets issued

8 messages in order. Play them, or step through them one at a time.

If the UPDATE returns 0 rows, the next call is void instead of capture.

5Rule 4: Make Late Callbacks Idempotent

Providers retry callbacks, and some confirmations still arrive after our extended deadline. Every callback is processed by payment id: we record the payment id in a table with a unique constraint and do nothing if we have already handled it. So a callback delivered three times produces one order.

When a confirmation arrives for a hold that has already been released, we do not try to rescue the seat. We void the authorisation if it has not been captured, or refund automatically if it has, and send the buyer a clear message with an offer to pick other seats. The worst case becomes an apology with no money taken, instead of two people holding the same ticket.

6Monitoring and Reconciliation

We measure the things that show the race directly: confirmation attempts that updated zero rows (each one is a prevented double sale), late confirmations per provider, and holds that reached their deadline while still in PAYMENT_PENDING. If one provider's late rate climbs, we extend that provider's window or route payments elsewhere.

Finally, a daily job compares tickets with captured payments: every ticket must have exactly one captured payment, and every captured payment must have a ticket or a refund. Any mismatch is a bug we have not understood yet, found before the buyer finds it.

7Follow-up questions

Why not simply make the hold 15 minutes long?

That reduces the race but does not remove it, because some provider will one day take 16 minutes. It also keeps seats off sale longer for everybody, including buyers who abandoned the page. Extending the hold only when payment actually starts gives the long window just to the holds that need it.

What if the provider never confirms at all?

When the extended deadline passes, the expiry job releases the seats and we query the provider for the payment status. If it was authorised, we void it; if it later succeeds anyway, the idempotent callback path refunds it. The reconciliation job catches anything left over.

Do we need SERIALIZABLE isolation for this?

No. Each decision is a single-row or single-hold conditional UPDATE, which is atomic at READ COMMITTED because PostgreSQL re-checks the WHERE clause after waiting for a row lock. Higher isolation would add retries without closing any extra gap.

8Conclusion

In this answer, we saw that the 140 double sales came from a late confirmation that trusted the payment instead of checking the seat. We fixed it by confirming only through a conditional UPDATE on the hold, by moving holds to PAYMENT_PENDING with an expiry that covers the slowest provider, by authorising first and capturing only after the seats are confirmed, and by handling late callbacks idempotently with automatic voids or refunds. Monitoring of zero-row confirmations and a daily ticket-to-payment reconciliation keep it honest.

What to say in the interviewAbout 90 seconds aloud

Open with

The double sales come from a race between hold expiry and slow payment confirmations: the expiry job released the seat, someone else bought it, and then the late confirmation wrote SOLD without checking the hold still owned the seat.

Then, if they want more

I would fix it in four layers. First, a sale is only ever confirmed with a conditional update: set the seats to SOLD where hold_id is this hold and the status is HELD or PAYMENT_PENDING. If the row count is short, we did not get the seats, so a double sale becomes impossible regardless of timing.

Second, when payment starts, I move the hold to PAYMENT_PENDING and extend its expiry to cover the slowest provider, say twenty minutes if confirmations take up to twelve, and the expiry job never releases a pending hold before that.

Third, I authorise the card while the hold is valid and capture only after the conditional update succeeds; if it fails I void the authorisation, so nobody is charged for seats they lost. Fourth, callbacks are idempotent by payment id, and a confirmation for a released hold triggers an automatic void or refund and a message to the buyer.

Then I monitor zero-row confirmations, late confirmations per provider and holds expiring while pending, and reconcile tickets against payments every day.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How do you make hold expiry and payment completion safe together, so no seat is sold...": https://scrivio-interview-library.netlify.app/architecture/system-design-problems/71ca8ea70b/