The hardest part of a booking app isn't the booking. It's what happens when two people tap the sa...The hardest part of a booking app isn't the booking. It's what happens when two people tap the sa...
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started
The hardest part of a booking app isn't the booking.
It's what happens when two people tap the same slot four milliseconds apart.
The obvious approach is to check whether the slot is free, and if it is, book it. That works perfectly in testing, because in testing there's one of you. In production, both requests run the check before either one writes. Both are told yes. Both book. Now you have two teams turning up at the same turf, and a venue owner who no longer trusts your app.
The instinct is to fix this in the application — a flag, a check, maybe a mutex. That's fighting the problem in the wrong place. Your app might be running on four servers; they can't see each other's decisions.
The fix is to stop asking permission and let the database refuse:
A unique constraint on (venue, slot). The second insert fails. Not "usually fails" — it cannot succeed, by definition.
A conditional write. update slots set booked_by = ? where id = ? and status = 'free'. If it changes zero rows, someone beat you. That's your answer.
A short-lived lock while they're paying. Hold the slot for five minutes in Redis, release it if they abandon checkout. This is the one users actually notice, because nothing is worse than paying for a slot that was gone before you finished typing your card number.
None of this is exotic. But it only shows up when two people want the same thing at the same time, which is exactly the moment your app is finally working.
Anyone else been bitten by this one? I've seen it in booking, ticketing and inventory — same bug wearing different clothes each time.
Post image
Back to feed
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started