Ticket Seat Reservation Drill
Two buyers confirm the same seat while an expiry worker runs.
Topic tools
Layout updated
Prompt
Two buyers confirm the same seat while an expiry worker runs.
A seat is one item with a state machine. Buyers compete for a state transition, not for the right to write an arbitrary status.
Constraints
- Allow at most one committed owner for each seat.
- Make expiry and confirmation safe when they happen together.
Think first
Take five minutes to state the failure, the evidence you need and your first safe move.
Staged reveal
First move
One authority decides whether the seat is free, held or sold.
What to check
Trace the winning reservation, expected state/version and expiry instant.
Recovery
Put conditional transitions and constraints at one database authority; retry the command identity instead of creating another reservation.
What you give up
The database can guarantee one seat owner. Charging a remote provider is a separate action that still needs retry and recovery rules.
Architecture and technical reference
High-level design
- Compute
- State
━━ Synchronous┄┄ Asynchronous···· Recovery / control▧ Fault
Each arrow is one interaction. Request, background and recovery branches are not one linear transaction.
Read the 4 flow steps
Problem statement
Two buyers reserve the same seat while an expiry worker and a payment callback also run. Which transaction wins?
Functional requirements
- Hold a seat for one buyer.
- Confirm, cancel or expire the hold.
- Check the result when payment times out.
Non-functional requirements
- Allow at most one committed owner for each seat.
- Make expiry and confirmation safe when they happen together.
Entities
| Entity / logical owner |
|---|
| Authoritative state |
API design
| Operation / input | Response and retry contract |
|---|---|
Decision contract | Identify acceptance, retry identity, version/ and the response on uncertainty. |
High-level design component walkthrough
Buyer
Select one seat
Why, tradeoff and connected operations
Isolate this operation so it can scale and fail independently from storage.
Tradeoff: Double-clicks / competing buyers
Connected operations: Pass validated input
Booking API
Create reservation
Why, tradeoff and connected operations
Isolate this operation so it can scale and fail independently from storage.
Tradeoff: Retry may create duplicate hold
Connected operations: Pass validated input; Persist state
PostgreSQL / Seat DB
Conditional AVAILABLE → HELD
Why, tradeoff and connected operations
: PostgreSQL. Relational tables and constraints own this state. Logical tables shown within the same business database are not separate databases; only at the defined transaction boundary. Use transactional constraints for related authoritative records; indexes follow the access pattern.
Tradeoff: Contention on one seat row
Connected operations: Persist state; held
Payment / Finalizer
Idempotent completion
Why, tradeoff and connected operations
Isolate this operation so it can scale and fail independently from storage.
Tradeoff: Charge and inventory can diverge
Connected operations: held; conditional txn
PostgreSQL / SOLD State
At most one winner
Why, tradeoff and connected operations
: PostgreSQL. Relational tables and constraints own this state. Logical tables shown within the same business database are not separate databases; only at the defined transaction boundary. Use transactional constraints for related authoritative records; indexes follow the access pattern.
Tradeoff: Winner finalization must be idempotent
Connected operations: conditional txn
Engineering control room
Deep dives — decisions, failures and recovery
Open a deep dive to follow the steps, try an example and see how recovery works.
Tradeoffs and alternatives
| Decision | Tradeoff / alternative and recovery implication |
|---|---|
| Keep the seat and hold in the same transaction | The database can guarantee one seat owner. Charging a remote provider is a separate action that still needs retry and recovery rules. |
| Make expiry, payment and confirmation agree | If payment succeeds after the hold was released, reconcile and follow the refund policy. Do not silently force a late confirmation onto unavailable inventory. |
| What happens if a region fails? | Remote synchronous inventory protection costs latency; rapid promotion of stale replicas risks selling the same seat twice. |
| Lost payment response and safe compensation | increases completion time and operational state, but immediate recharging or releasing can create financial errors. |
Production scars & failure modes
Two buyers confirm the same seat while an expiry worker runs.
Look for: Trace the winning reservation, expected state/version and expiry instant.
Recovery and invariant: Put conditional transitions and constraints at one database authority; retry the command identity instead of creating another reservation.
| Component / failure | Impact | Recovery mechanism | Alternative / tradeoff |
|---|---|---|---|
| Primary failure / race | Two buyers reserve the same seat while an expiry worker and a payment callback also run. Which transaction wins? | Serialize/conditionally update expected state and expiry; keep a unique logical payment identity. Cleanup must recheck state/version. | You can guarantee one owner in ; charging and owning the seat are not one transaction with an arbitrary provider. |
| Recovery follow-up | Payment succeeds externally after the hold was released. Explain finalization failure and refund/. | Serialize/conditionally update expected state and expiry; keep a unique logical payment identity. Cleanup must recheck state/version. | State the guarantee you relax and how you detect recovery. |
90-second interview summary
For the seat-reservation drill, I would start with the invariant: one seat cannot have two committed owners. PostgreSQL owns seat state, hold identity and reservation version inside one transaction domain. Search results or Redis availability are only hints until that transaction commits.
Competing buyers use locks in a stable order or conditional expected-state updates. A multi-seat hold succeeds completely or not at all. Confirmation, cancellation and expiry compare the exact hold identity, current version and authoritative database time so stale cleanup cannot release a seat already sold by a newer transaction.
Payment has its own stable request identity recorded before the provider call. A timeout is an unknown result, so queries that same attempt. If payment succeeds after the hold is no longer eligible, the compensation/refund policy resolves it rather than inventing a second seat.
I would preserve this authority through regional failover, fence the old writer and refuse unsafe reservation writes when committed history is uncertain. I would watch lock waits, conflict rates, old holds and unresolved payments. The tradeoff is short periods of waiting or rejection in exchange for a transaction boundary that can explain every race without depending on best-effort cache locks.
Explain it without looking
Explain keep the seat and hold in the same transaction
Reveal answer
One authority decides whether the seat is free, held or sold.
A cache lock or delayed timeout cannot prove that an old hold is still current.
The database can guarantee one seat owner. Charging a remote provider is a separate action that still needs retry and recovery rules.
Explain make expiry, payment and confirmation agree
Reveal answer
Check current state and hold identity every time a worker changes the reservation.
A worker can resume after another transaction has already sold or released the hold.
If payment succeeds after the hold was released, reconcile and follow the refund policy. Do not silently force a late confirmation onto unavailable inventory.
Explain what happens if a region fails?
Reveal answer
Keep one reservation authority while regions disagree about availability.
At-most-one seat ownership remains the invariant during failover, not only during normal local transactions.
Remote synchronous inventory protection costs latency; rapid promotion of stale replicas risks selling the same seat twice.
Explain lost payment response and safe compensation
Reveal answer
A payment timeout is an uncertain attempt, not permission to charge again.
Seat atomicity alone does not make a remote payment part of the database transaction.
increases completion time and operational state, but immediate recharging or releasing can create financial errors.
Revision checklist
Revision checklist
- Reconstruct keep the seat and hold in the same transaction: One authority decides whether the seat is free, held or sold.
- Reconstruct make expiry, payment and confirmation agree: Check current state and hold identity every time a worker changes the reservation.
- Reconstruct what happens if a region fails?: Keep one reservation authority while regions disagree about availability.
- Reconstruct lost payment response and safe compensation: A payment timeout is an uncertain attempt, not permission to charge again.
- Name the authoritative state, boundary, retry identity and failure-domain durability guarantee.
- Explain one alternative and exactly which guarantee you would relax.
- Redraw the request and recovery paths without looking; mark what required a hint.
On this page
- Prompt
- Constraints
- Think first
- Staged reveal
- High-level design
- Problem statement
- Functional requirements
- Non-functional requirements
- Entities
- API design
- High-level design component walkthrough
- Engineering control room
- Deep dives — decisions, failures and recovery
- Tradeoffs and alternatives
- Production scars & failure modes
- 90-second interview summary
- Explain it without looking
- Revision checklist