LOAD-BEARINGfree
Architecture labTier 13 · unit 10 of 31

Inventory and booking

Tickets go on sale at a fixed instant. Two hundred thousand people arrive in the same minute for fifty thousand seats. Overselling is unacceptable. Showing slightly stale availability is merely annoying.

Envelope50k seats · 200k buyers in the first minute · zero oversells

What the design must do

  • A seat is sold to at most one buyer, under any level of concurrency
  • Reservations expire so abandoned carts return inventory automatically
  • Availability display may be stale; the reservation itself may not
  • Payment is confirmed asynchronously, after the seat is already held

The worked envelope

Assumed. 50k seats, 200k buyers arriving in the first minute, half of them in the first ten seconds, 15-minute holds.

Worked envelope
Request rate100k in 10 s = 10k/s at the front
Contention200k buyers for 50k seats = 4:1 — most must fail
Live holdsat most 50k × 100 B = 5 MB of state
Hot rowsa popular block of 500 seats absorbs most attempts
Total inventory50k rows ≈ 5 MB — the entire dataset
Oversell tolerancezero

What the numbers decide. The whole system is five megabytes of data. There is nothing to shard, nothing to cache for size, no storage problem of any kind. What there is: ten thousand requests a second converging on a few hundred rows, and a correctness requirement that admits no error.

So every mechanism in this design exists for contention, not capacity. That reframes the work — the interesting questions become how a seat is claimed atomically, how a hold expires without a human, and how you shed the three-quarters of traffic that is going to fail anyway before it reaches the rows everyone is fighting over.

The decisions, and what each one costs

Claim a seat with a conditional update, not read-then-write

Because
Check-then-act across many processes is the double-booking bug at scale; only an atomic operation that succeeds for exactly one caller can hold a zero-oversell requirement
The cost
Most requests fail, so the client and the UI must treat contention as a normal outcome rather than an error
Rejected
Application-level locking, which orders threads inside one process and protects nothing across a fleet

Holds as first-class rows with an expiry, swept by a job

Because
A buyer needs time to pay, and an abandoned checkout must return the seat without anyone intervening
The cost
Seats are unavailable while held even though nobody bought them, so the hold window is a direct revenue tradeoff
Rejected
Holding a database transaction open during checkout, which pins a connection for minutes and deadlocks under load

A queue in front of the sale, with an honest position shown to the user

Because
4:1 contention means most traffic cannot succeed; admitting it in a controlled order beats melting the inventory rows and failing randomly
The cost
Extra infrastructure, and the queue itself becomes the thing that must not fall over
Rejected
Letting everyone through and rejecting on failure, which spends peak capacity generating errors

Inventory in the relational store, not the cache

Because
The dataset is 5 MB, so the cache buys nothing on size, and a cache that can serve a stale "available" is precisely the oversell you promised would never happen
The cost
Every attempt reaches the database, which is why the queue and the conditional update matter
Rejected
Decrementing a counter in Redis, which is fast, and loses the atomic link between the count and the seat

Components in the reference design

Client
Browser or mobile app
Load Balancer
L7 routing, TLS termination, health checks
App Service
Stateless business logic
SQL DB
Relational, ACID, joins
Cache
Redis / Memcached, sub-ms lookups
Queue
Work distribution, one consumer per message
Worker
Async consumer, background jobs

What not to draw

  • NoSQL Store — The single invariant in this system — a seat sold once — needs an atomic conditional write the store guarantees. An eventually consistent store gives you a very fast oversell.

The reference design

This is Tier 2's double-booking bug, at scale. Lesson 2.05 showed two threads both reading "seat available" and both writing. A mutex fixed it inside one process and stopped working the moment there were two servers. Here there are hundreds, and the fix is the same one Tier 3 gave you: make the check and the write a single atomic operation.

UPDATE seats SET held_by = :buyer, held_until = now() + interval '10 min'
 WHERE id = :seat AND held_by IS NULL

One row updated means you won; zero rows means someone else did. No read-then-write, no distributed lock, no coordination beyond the row itself. Everything else in this design exists to keep load away from that statement — not to replace it.

Split the two consistency requirements. The seat map a buyer browses can be seconds stale and served entirely from cache; nobody is harmed by seeing a seat that was just taken. The reservation is strongly consistent and hits the database. Conflating them is what makes people reach for a distributed lock they do not need.

Hold, then charge. Payment takes seconds and can fail, so it must not run inside the transaction that claims the seat. Claim the seat with an expiry, publish the order, and let a worker take the payment — Lesson 6.05's saga, with the compensation being that an unpaid hold simply expires. The expiry is what makes abandoned carts self-healing rather than an operations task.

Expiry is a correctness mechanism. A held seat with no expiry is inventory lost to a closed browser tab. Reclaim by sweeping expired holds, and make the sweep idempotent — it will run concurrently with itself eventually.

The queue that is really a fairness decision. At 200k arrivals in a minute, a virtual waiting room in front of the sale converts a stampede into a controlled admission rate. That is Lesson 9.03's load shedding, presented to users as a queue position rather than an error.