Two guests grab the last box
at the exact same instant.
At 01:00 on a Friday it happens for real — two people pay for the last free Small Box and both get assigned it. Below, fifty do it at once. Watch exactly one win.
The race
Guaranteed by one statement — SELECT … FOR UPDATE OF b SKIP LOCKED — backed by a partial
unique index that makes any double-book fail closed at the database. No Redis, no app locks, no retry loops.
The guest journey
Every tap hits the real API. The box is held before you pay; the number is revealed only after payment confirms.
Live zone
Club Prisma · Main Cloakroom · 40 boxes
A TTL hold locks a specific box the instant you pick a product — before Stripe. If you don't pay in time, the sweep returns it to the pool.
The hold TTL is far shorter than Stripe's 30-minute floor, so it expires the checkout early. If a payment still lands late, the session reassigns to another free box — or refunds.
Box online-state is a cached column behind a BoxStateProvider interface — never a live per-request call to the hardware vendor. Swapping in the real adapter is one line.