System Design Atlas
LOCAL GUEST MODERead and practice without an account.

Your saved topics and reading progress stay in this browser. Sign in to sync supported profile and progress data.

Ticket Seat Reservation Drill

Two buyers confirm the same seat while an expiry worker runs.

● HardDrill 061 min1 prerequisite
My progress
Topic tools

Layout updated

Explore the design, then rehearse the decisions without looking.

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.

5:00

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

Ticket Seat Reservation Drill
G buyer->booking 1. Pass validated input booking->db 2. Persist state db->payment 3. held payment->sold 4. conditional txn buyer Buyer compute booking Booking API compute db PostgreSQL / Seat DB state · durable payment Payment / Finalizer compute sold PostgreSQL / SOLD State state · durable
  • Compute
  • State

━━ Synchronous┄┄ Asynchronous···· Recovery / control▧ Fault

Select a component or follow a numbered connection.

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 / inputResponse and retry contract
Decision contractIdentify acceptance, retry identity, version/ and the response on uncertainty.

High-level design component walkthrough

Backend service

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

Backend service

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

Relational database

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

Backend service

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

Relational database

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.

Deep dive 1

Keep the seat and hold in the same transaction

One authority decides whether the seat is free, held or sold.

Read the explanation and worked example
How it works

Store inventory state, hold identity and reservation version within one transaction authority. Availability checks are advisory until the conditional state change commits. For multiple seats, acquire locks in a stable order and fail the whole reservation if any requested seat is no longer eligible.

Walk through an example

Two buyers observe AVAILABLE simultaneously. The database constraint or expected-state update lets one move it to HELD; the other sees a conflict instead of independently creating ownership.

Failure and recovery

Keep the inventory transaction short, bound lock waits and return the winning durable state on retry. A queue or Redis lock does not replace the database invariant.

Why this helps

A cache lock or delayed timeout cannot prove that an old hold is still current.

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.

Deep dive 2

Make expiry, payment and confirmation agree

Check current state and hold identity every time a worker changes the reservation.

Read the explanation and worked example
How it works

Confirmation and cleanup both verify the exact hold identity, current state, version and expiry using authoritative time. Persist a stable payment identity before contacting the provider. A delayed worker must not act on the assumption that a previously read hold is still current.

Walk through an example

Cleanup reads a hold, pauses, and payment confirmation commits SOLD. When cleanup resumes, its conditional release must affect zero rows rather than release the sold seat.

Failure and recovery

On an ambiguous payment, reconcile the existing attempt before charging or freeing inventory. Test both possible transaction orders and explain what happens when payment succeeds after the hold has genuinely expired.

Why this helps

A worker can resume after another transaction has already sold or released the hold.

What you give up

If payment succeeds after the hold was released, reconcile and follow the refund policy. Do not silently force a late confirmation onto unavailable inventory.

Deep dive 3

What happens if a region fails?

Keep one reservation authority while regions disagree about availability.

Read the explanation and worked example
How it works

All contenders for an event's inventory must reach one fenced transaction authority, even if discovery and payment entry points are regional. Replicated read copies never independently grant the same seat.

Walk through an example

Both regions show the final seat as available while the write-home is isolated.

Failure and recovery

Reject or wait for a safe authority transition, reconcile committed holds/payments and fence the old writer before reopening reservation writes.

Why this helps

At-most-one seat ownership remains the invariant during failover, not only during normal local transactions.

What you give up

Remote synchronous inventory protection costs latency; rapid promotion of stale replicas risks selling the same seat twice.

Deep dive 4

Lost payment response and safe compensation

A payment timeout is an uncertain attempt, not permission to charge again.

Read the explanation and worked example
How it works

Persist the logical payment key before the external call and record attempts against the reservation. Keep UNKNOWN distinct from a confirmed rejection. Query the same provider identity or process an idempotent callback before deciding whether to finalize or release inventory.

Walk through an example

The provider charges successfully, but the worker dies before recording the response. A new worker sees a pending payment and must not issue a new charge identity.

Failure and recovery

Reconcile the original attempt; if the hold is no longer eligible, use the documented refund/compensation path. Do not grant a second seat to hide the mismatch.

Why this helps

Seat atomicity alone does not make a remote payment part of the database transaction.

What you give up

increases completion time and operational state, but immediate recharging or releasing can create financial errors.

Tradeoffs and alternatives

DecisionTradeoff / alternative and recovery implication
Keep the seat and hold in the same transactionThe 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 agreeIf 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

Failure investigation

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 / failureImpactRecovery mechanismAlternative / tradeoff
Primary failure / raceTwo 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-upPayment 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
  1. Prompt
  2. Constraints
  3. Think first
  4. Staged reveal
  5. High-level design
  6. Problem statement
  7. Functional requirements
  8. Non-functional requirements
  9. Entities
  10. API design
  11. High-level design component walkthrough
  12. Engineering control room
  13. Deep dives — decisions, failures and recovery
  14. Tradeoffs and alternatives
  15. Production scars & failure modes
  16. 90-second interview summary
  17. Explain it without looking
  18. Revision checklist

Save & sync your Atlas progress

Sync your profile and topic progress across browsers, then return to the same study desk.

Google sign-in will appear here after its Azure provider is configured.

Architecture diagram