Skip to content

Decisions7 min read

Preventing double bookings: seat holds and timeouts in a ticketing system

By Published

Short answerDouble bookings happen when two requests both read a seat as free before either one saves. The fix is layered. A database constraint makes a second booking for the same seat impossible to save. A row lock makes simultaneous buyers take turns. A hold with an expiry keeps the seat for one buyer while they pay, then releases it. I would not ship a booking system without the constraint.

Why two buyers can both be told the seat is free

Booking code usually does two things in order. It checks whether the seat is free, then it saves the booking. A double booking lives in the gap between those two steps.

Two people tap the same seat a fraction of a second apart. Request A checks: free. Request B checks: free, because A has not saved yet. Both save. Both get a ticket. Nothing crashed and no error appears in any log, which is why this bug survives testing by one person clicking around.

PostgreSQL's documentation explains the mechanics. At its default isolation level, Read Committed, a query sees only data committed before the query began, and never another transaction's uncommitted work. B is not careless. B cannot see what A is doing.

The same gap exists for a clinic slot, a meeting room, a rental car or the last table at 8pm.

The last seat on the 10:00 departure, second by second

Here is one seat, 14C, sold correctly with a 10-minute hold. Times are examples. Take away the lock and the hold, and the second row reads differently: both requests see 'free', both write, and two people board holding the same seat number.

TimeBuyer ABuyer BSeat 14C
10:00:00Opens the seat map and sees 14C freeOpens the seat map and sees 14C freeFree
10:00:05Taps 14C. The request locks the seat's row, finds it free and writes a hold that expires at 10:10:05Taps 14C an instant later. The request waits for A's lockLocked for an instant
10:00:05Sees the payment screen with a countdownThe lock clears, B's request reads the updated row and finds the hold. B is told the seat is being heldHeld until 10:10:05
10:07:30Pays. The hold becomes a confirmed bookingHas chosen 15ASold
10:10:05Had A not paid, the hold would lapse hereCould now take 14CFree again, only if unpaid

Six techniques, what each prevents and where it falls short

No single tool covers everything. The first five are PostgreSQL features, described the way its documentation describes them.

My opinion: the constraint is the last line of defence, and I would not ship without it. Locks and holds depend on every piece of code doing the right thing. A constraint does not. If a bug, a script or a second app tries to save a duplicate, the database refuses.

TechniqueWhat it preventsWhere it falls short
Unique constraint on trip and seatTwo confirmed bookings for the same seat. The second save raises an errorKnows nothing about time ranges or holds. By default two null values are not treated as equal, so a nullable column in the key leaves a hole
Exclusion constraint on a time rangeOverlapping appointments for one room or staff member, a case the docs say a unique constraint is usually unsuitable forCombining 'same room' with 'overlapping time' needs the btree_gist extension. Cleaning time and buffers have to be inside the stored range
Row lock with SELECT ... FOR UPDATETwo requests deciding about the same seat at once. The second waits, then reads the updated rowThe lock ends when the transaction ends, so it cannot be the 10-minute hold. PostgreSQL resolves a deadlock by aborting one transaction, which the code must handle
SKIP LOCKEDBuyers queueing behind each other when any seat will do. Each request takes rows nobody else has lockedThe docs say it gives an inconsistent view of the data and is not suitable for general purpose work. Wrong tool for 'is 14C free?'
Serializable isolationConcurrent transactions producing a result that could not happen if they ran one at a timeNot the default level. The application must be prepared to retry transactions after serialization failures
Hold with an expiryThe seat being sold to someone else while the first buyer types card detailsNeeds a release path that always runs, and a rule for payments that arrive after it lapses

The hold: a record with an expiry time, and who sets its length

A hold is a small record: this seat, this buyer, expires at this time. I would keep it in PostgreSQL next to the bookings, so the same transaction that checks the seat also writes the hold. Available then means two things: no confirmed booking, and no unexpired hold.

Some teams keep holds in Redis. Its SET command has an NX option, which sets a key only if it does not already exist, and an EX option that expires it after a number of seconds. Redis's own documentation is careful about this pattern. It says locking on a single instance is viable where a race condition from time to time is acceptable, and that adding a replica cannot give mutual exclusion, because Redis replication is asynchronous. So a Redis hold can drive the countdown and take load off the database. I would not give it the final say on who owns the seat.

Hold length is a business decision. Too short, and buyers lose seats while their bank's verification screen loads. Too long, and abandoned carts lock stock during a sell-out. Decide it per product, show the countdown, and write down whether a buyer may extend it.

Payment timing: what happens when the money arrives late

The hold and the payment page run on separate clocks. With Stripe Checkout, a session can expire anywhere from 30 minutes to 24 hours after it is created, and the default is 24 hours. A 10-minute seat hold is shorter than Stripe's minimum. So the booking system has to end the session itself: Stripe's API can expire a session while its status is open, after which the customer can no longer complete it.

A payment can still land in the same second the hold lapses. My rule: a booking is confirmed only inside a database transaction that checks the hold is still valid. If it is not, the customer is told at once and refunded automatically, with no staff involved.

An alternative is to authorise the card first and capture only once the seat is confirmed. Stripe's documentation says an online card authorisation is usually valid for 7 days, and that if it expires before capture the funds are released. If the seat is lost, you cancel the authorisation. One caveat from the same page: card statements from some issuers do not always distinguish authorisations from captured payments, which can confuse customers.

The double-booking tests I would ask to see pass

One person clicking cannot find this bug. These are the tests I would want run before launch.

  • Fire 50 simultaneous requests at one seat. Exactly 1 booking exists afterwards, and the other 49 buyers got a clear message.
  • Repeat with the application's own availability check switched off, to prove the database constraint alone refuses the duplicate.
  • Book overlapping times for one room or staff member, including two appointments that only touch at the edges.
  • Let a hold expire, then confirm the seat is on sale again and the first buyer's payment page no longer works.
  • Pay in the last second of a hold, and one second after it.
  • Stop the server between hold and payment. The hold still expires.
  • Sell the same seat from two channels at once, for example the app and the counter screen.
  • Deliver the payment confirmation twice. One booking, one ticket.

Seat holds in a ticketing or booking build I quote

Ticketing and booking systems with seat maps, several sales channels and payments are custom software, which I quote as a fixed price after a written scope. That scope should name the hold length, the release rule and what happens to a late payment. Complex payment gateway work is quoted separately. Gateway fees, hosting and ongoing maintenance are not included.

A simpler appointment app can fit a package. Growth at $1,699 and Scale at $2,500 both run on a Node.js backend and a PostgreSQL database, so the constraints described here are available from the first day. The railway ticketing platform in my case studies shows why the rule belongs in one place: it has a passenger app, agent interfaces and kiosk interfaces around the same seat selection and booking workflows.

Send me how seats or slots are sold today and through which channels, and I will tell you where the double-booking risks sit.

Questions

Is checking availability before saving enough to stop double bookings?
No. Two requests can both check before either saves, and under PostgreSQL's default isolation level neither sees the other's uncommitted work. A unique or exclusion constraint in the database is what refuses the second booking.
How long should a seat hold last?
It is a business decision: long enough to finish payment, short enough that abandoned carts do not block stock in a rush. With Stripe Checkout, a session cannot be set to expire sooner than 30 minutes after creation, so a shorter hold needs the system to expire the session itself.
Do I need Redis for seat holds?
No. A hold can be a row in PostgreSQL with an expiry time. Redis can help with speed and countdowns, but its own documentation describes the limits of using it for locks, so I keep the final decision in the database.

Sources

Platform rules and fees in this article were checked against these official pages on 12 November 2026. They change, so confirm before you rely on them.

Sannan Malik is a software architect and product builder with 8+ years in software, CEO of Alpha Notic FZE and a Certified Scrum Product Owner. He builds mobile apps and business software for companies in the UAE, the wider Gulf, the UK, the US, Canada and Australia.

Let's build it

Got an idea? Let's talk.

The fastest way to reach me is WhatsApp. Tell me what you're building and I'll reply with how I'd approach it, which package fits, or what a custom scope would look like.

Message me on WhatsApp