1. Why It Passes Every Test
Most booking code does three things: check whether the slot is free, take the payment, then mark the slot as taken. With one customer that works every time. With two customers arriving together, both checks run before either booking is saved. Both see “free”. Both pay.
The race may be brief and difficult to reproduce in sequential testing. It appears exactly when it hurts most: a launch, a flash sale, a popular instructor opening their calendar, a ticket release. The moments you care most about are the moments the bug comes out.
2. Where I Ran Into It
At ClassFlow, a live tutoring marketplace, peak registration bursts created race conditions where multiple students tried to confirm the same teacher's time slot at the same moment. The failure we designed against was specific: two students clicking “Book” within 50ms of each other and both getting charged for a single instructor seat.
A second, quieter version lived in payments. Unreliable networks dropped payment confirmations or delivered them twice, which could trigger a duplicate transfer, and instructor payouts were calculated by hand in spreadsheets every week.
3. How to Stop It
- Reserve before you charge. Put a short, exclusive hold on the slot before the customer enters checkout. At ClassFlow, a distributed lock (Redis Redlock) held each slot for 45 seconds and released it when checkout completed.
- Tell the second customer immediately. The second request fails fast with “this slot is being held by another student”, before any payment is taken. A clear message beats a refund and an apology email.
- Have a fallback when the lock service is down. At ClassFlow the documented fallback was database row-level locking. For a new system, both the ordinary reservation path and fallback must enforce the same authoritative database invariant. A lease may expire before payment completes, so validate reservation ownership and expiry at commit, use a durable uniqueness constraint for confirmed bookings, and reconcile or refund late payments. Redis locks alone do not guarantee correctness across outages or expired leases.
- Make payments idempotent too. Verify payment webhook signatures and record each event ID atomically with the durable processing state, so duplicate confirmations can be acknowledged without triggering another payout. Handle dropped events through reconciliation and use provider idempotency for retries.
4. Questions to Ask Your Team This Week
- If two customers book the last slot in the same second, who gets it, and is the other one charged?
- Do we hold inventory before payment, or check availability and hope?
- What happens to bookings if our cache or lock service goes down mid-sale?
- If our payment provider sends the same confirmation twice, do we pay out twice?
- Have we ever tested booking with many simultaneous users, or only one at a time?
This applies well beyond tutoring: event tickets, appointment slots, limited stock, delivery windows, hotel rooms. Anywhere two people can want the last one of something, the race exists.
Related reading: Why Your System Pays the Same Customer Twice, What to Do When Growth Outpaces Your Software, and the ClassFlow marketplace case study.
Launching something people will rush to book?
A fixed-scope $250 Pre-Mortem examines one critical flow, such as booking, checkout or payouts, for race conditions and duplicate charges before launch day. You get 3–5 pages of findings and a 30-minute walkthrough.
Explore The Architecture Pre-Mortem →