Concert Ticket Flash Sale — Part B: Deep Dives & Failures
Definitions
Seat hold
- In plain English
- A seat hold reserves a seat for one buyer for a limited time before payment.
- Think of it like
- It is like a shop keeping an item behind the counter for you until closing time.
Overselling
- In plain English
- Overselling is selling more units than exist, such as two buyers getting seat 14C.
- Think of it like
- Like two people being given the same hotel room key.
The brief
You will protect seat holds, resolve uncertain payments, and recover the flash sale after failures.
What it must do
How well it must do it
- Never sell a seat twice.
- Never charge twice for the same order.
- Keep the sale controlled during a payment outage.
Out of scope
- Resale and fraud models.
Design walkthrough
Deep dive 1: hold seats without overselling
Use Module 3 transactions to check and change ownership together. Deduplicate requested seat IDs before counting them.
BEGIN;
UPDATE seats
SET status = 'held', hold_id = $1,
hold_expires_at = now() + interval '10 minutes',
version = version + 1
WHERE event_id = $2 AND seat_id = ANY($3::text[])
AND (status = 'available' OR
(status = 'held' AND hold_expires_at <= now()))
RETURNING seat_id;
-- Application checks returned row count before COMMIT.
-- If count differs from distinct requested IDs: ROLLBACK.
-- Otherwise insert the hold record, then COMMIT.A worker releases expired held seats every 30 seconds. Reads may show expired holds as available; the conditional update remains authoritative.
Available seats become held; held seats can expire or enter payment, which resolves to sold or confirmed release.
Starting payment locks the hold and its seats in one transaction. Verify owner and expiry, then change every seat to paying.
All paths lock rows in the same order and verify row counts. Expiry must never release paying seats.
Deep dive 2: pay safely across services
This is the saga from Module 4. The durable order records each step so a worker can resume after crashing.
The worker either records a confirmed sale or preserves payment uncertainty and asks the provider for the original result.
- Use the same provider key for retries; require provider support for idempotency and outcome lookup.
- Commit sold seats, order completion, and one ticket per seat together; repeat completion returns the existing ticket.
- A confirmed decline releases paying seats conditionally for that order. Unknown outcomes keep seats reserved until resolved.
- If fulfilment becomes impossible, record and retry a refund before releasing ownership.
The Module 5 circuit breaker stops new payment calls during an outage. Extend eligible held seats transactionally before promising more time.
Bound extensions and pause admissions when needed. Existing paying seats remain protected; a timeout is never proof that no charge occurred.
Deep dive 3: one hot event
A leader assigns arrival numbers, distributed storage retains entries, and admission follows that order; cached seat reads bypass checkout writes.
Hashing queue tokens spreads storage, but does not preserve global order. Admit by the smallest outstanding server-assigned sequence across partitions.
Use Module 5 leadership and fencing for the sequence leader. Pause admissions when ordering is uncertain; keep acknowledged positions durable.
Keep seat transactions short and never call payments while holding database locks. The two-second cache is a hint, not a reservation.
What breaks, and what happens
| Failure | Effect | Mitigation |
|---|---|---|
| Waiting-room node dies | SSE connections disconnect. | Reconnect using the same token and restore durable queue entries from replicas. |
| Database primary fails | Seat changes pause. | Promote a synchronous standby only with safe leadership; reject writes while ownership is uncertain. |
| Payment provider stops responding | Charges have uncertain outcomes. | Open the breaker, protect paying seats, and resolve outcomes before release. |
| Bots flood the queue | Human fans face extra traffic. | Limit per account and IP; bind queue tokens to accounts. |
Monitoring on sale day
- Track latency, traffic, errors, and saturation from Module 5 observability.
- Measure admission rate, queue age, hold-to-sale conversion, and the oldest unresolved payment.
- Alarm on duplicate seat tickets, ownership mismatches, and sold-seat counts above capacity.
- Compare provider charges with completed orders; a capacity total alone cannot detect duplicate ticket issuance.
At ten times the scale
Twenty million visitors need at least 20,000,000 ÷ 50,000 = 400 SSE servers under the same capacity assumption.
Add failure headroom and more queue partitions. Preserve ordered admission across those partitions.
Shard seats by event ID when selling many events. Splitting events does not remove contention inside one hot event.
Design decisions
How do competing holds stay safe?
Our choice
Use a conditional update inside one transaction. This is Module 3 atomicity.
Why not the alternatives
- Read availability, then write laterTwo buyers could read the same available seat before either writes.
How do we recover unfinished payments?
Our choice
Persist saga progress and reuse stable keys. This combines Module 4 events with Module 5 idempotency.
Why not the alternatives
- Restart the entire purchase with a new keyA confirmed or uncertain earlier charge could be charged again.
How do we protect checkout during payment outages?
Our choice
Use timeouts and a breaker from Module 5. Preserve uncertain payment ownership.
Why not the alternatives
- Keep retrying every requestRepeated calls consume capacity and can delay recovery.
How do seat writes survive a primary failure?
Our choice
Use a synchronous standby and safe failover. This joins Module 3 replication with Module 5 consistency.
Why not the alternatives
- Acknowledge writes before any replica receives themFailover can lose acknowledged ownership and permit a second sale.
Trade-offs
Pros
- Transactions preserve seat ownership.
- Recorded payment progress makes recovery safe.
- Breakers reduce outage pressure.
Cons
- Saga recovery requires durable state and retries.
- Protected payments and extended holds slow the sale.
Use when
- Sales with scarce inventory and external payments.
Avoid when
- Unlimited goods where inventory ownership is unnecessary.
Quick check
Takeaways
- Use conditional seat updates and verify every requested row changed.
- Recover the payment saga with stable keys and protected inventory.
- Write the failure table before sale day.