How to prevent double booking when two requests want one slot One slot, one owner.
A double booking is a race condition, not a UI bug. Slotr holds the slot, locks the write and gives every request a definite answer: booked, or unavailable with the reason.
Entities.
Your domain, synced. Doctors, rooms, courts, cars — anything.
Availability.
Ask when something can be booked. Get the real answer.
Rules.
Pricing and eligibility that follow your business logic.
Quotes.
Know the price before the booking exists, with reasons.
Lifecycle.
Create, confirm, reschedule, cancel. One API, safe by default.
No double-booking.
Locks and slot holds, so every slot has exactly one owner.
Booking search.
Your entities, indexed. Search by price, distance and real availability.
AI recommendations.
Suggests the best booking using your rules, prices and availability.
From one sentence to a paid booking. And the insight that brings the next one.
Your marketplace, your brand. Slotr runs search, availability, pricing, payment holds and the console behind it.
Every check passed. Two people still booked the same hour.
- 01
Check, then write
Request A reads the slot as free. Request B reads it as free 20 ms later. Both insert a booking. Each check was correct when it ran, and nothing stopped the second write.
- 02
Payment widens the window
Checkout takes anywhere from a few seconds to a few minutes while a card is authorized. If the slot isn't reserved during that time, a second customer can pay for it too, and someone needs a refund.
- 03
Retries create duplicates
A mobile client times out and retries, or a user taps confirm twice on a slow connection. Without an idempotency key, the same person ends up with two bookings for one session, and both look legitimate.
- 04
External calendars change underneath you
A provider adds a personal appointment in Google Calendar a minute before a customer books. If the conflict check only reads your own bookings table, the slot is sold while the provider is away.
- 05
Capacity counters drift
Spots left is computed as capacity minus bookings in application code. Two concurrent decrements and one cancellation that never released its spot, and a class for 12 shows 13 people.
- 06
The losing request gets a bad answer
The second request often fails as a generic 500 error or a payment refunded hours later. The customer doesn't know whether they booked, so they retry, book elsewhere or write to support.
Hold first, confirm after payment. The second request gets a reason, not a 500.
Drop it into your product. No per-provider accounts, no iframes — your database stays the source of truth.
const booking = await slotr.bookings.create({
bookable: "t_281",
participant: "s_77",
start: "2026-11-04T18:00:00Z",
idempotencyKey: "checkout_9f2c"
});
// → { id: "b_5012", status: "held", expiresAt: "2026-11-04T17:52:10Z" }await slotr.bookings.confirm(booking.id);
// → { status: "confirmed" } webhook: booking.confirmed
// or the hold lapses webhook: hold.expired// a second request for the same slot
→ 409 {
error: "slot_unavailable",
reason: "held by another booking until 17:52:10Z",
next: ["2026-11-04T19:00:00Z", "2026-11-05T18:00:00Z"]
}What happens when two requests arrive together in five steps.
- 1
Deduplicate the intent
Each create call carries an idempotency key. A retry with the same key returns the original result instead of creating a second booking.
- 2
Take the lock
Requests for the same bookable and overlapping time are serialized. Only one of them evaluates availability and writes at a time, so the check and the write can't be split.
- 3
Place a hold with a TTL
The winner gets a hold that blocks the slot for everyone else for a few minutes, long enough to collect payment or details, short enough not to strand inventory.
- 4
Confirm or expire
Confirming turns the hold into a booking and fires booking.confirmed. If nothing confirms in time, the slot is released automatically and hold.expired is sent.
- 5
Answer the loser
The other request gets a 409 with a machine-readable reason, the time the hold ends and the next available slots, so your UI can offer an alternative right away.
Double booking, explained for developers
Why double bookings happen
A double booking happens when two requests check availability, both see the slot as free, and both write a booking. It is a classic time-of-check to time-of-use race. Adding a "is this slot taken?" query before the insert doesn't fix it, because the gap between the read and the write is exactly where the second request slips in.
The fix is to make the decision and the write a single exclusive step, and to reserve the slot for the time a human or a payment provider needs to finish.
Make the write exclusive
In a relational database you have three common options. A unique index on (bookable_id, start) works only when every booking has the same fixed length. A row lock, such as SELECT ... FOR UPDATE on the bookable, serializes all writers for that resource. In Postgres, an exclusion constraint on a tstzrange column with the btree_gist extension rejects any overlapping range for the same bookable at the database level.
Overlap is what matters. A 10:00 to 11:00 booking and a 10:30 to 11:30 booking don't share a start time, but they still conflict. Buffers count too, so extend each range by its buffer before comparing.
Holds and idempotency keys
A hold is a temporary booking with an expiry. It blocks the slot while the customer pays, then becomes a confirmed booking or disappears. Pick a TTL that covers a normal checkout plus a 3-D Secure challenge, and release expired holds on a timer rather than waiting for the next read.
Don't charge before the hold succeeds. Authorizing a card for a slot you can't give is how refunds and chargebacks start.
Networks fail after the server has committed but before the client hears back. Generate an idempotency key per checkout attempt on the client and store it with the booking. A repeat request with the same key returns the stored result, so retries are safe.
Capacity and external calendars
For classes, boats or group sessions, never read a count and then write. Use a conditional update, such as decrementing spots only where spots are above zero, or lock the slot row while you insert. Release the spot in the same transaction that cancels a booking or expires a hold, or the counter drifts.
External calendars are the conflict source teams forget. A provider's dentist appointment in Google Calendar is just as real as a booking in your table. Sync those events into the same conflict check, and recheck right before the hold is granted, not only when the page loads.
Give the losing request a useful answer
Most systems prevent the conflict and then fail badly. Return a specific status, the reason, when the slot might free up and the next options. Slotr does this by default, so the customer who lost the race sees another time instead of an error page.
Questions about double booking
What causes double booking in an app?
Usually a race condition. Two requests check the same slot at nearly the same time, both see it as free and both write a booking. Retries without idempotency keys and calendars that change outside your system cause the rest.
Is a unique constraint enough to prevent double booking?
Only when every booking has the same length and start grid. Real bookings overlap without sharing a start time, so you need overlap detection, such as a Postgres exclusion constraint on a time range, or a lock per bookable around the check and the write.
How long should a booking hold last?
Long enough to finish a normal checkout, including payment authentication, and short enough that abandoned carts don't block popular slots. A few minutes is typical. In Slotr, expired holds are released automatically and a hold.expired webhook tells your app the slot is free again.
What is an idempotency key in a booking API?
A unique value the client sends with a create request. If the same request is retried with the same key, the API returns the original booking instead of creating a new one. It makes timeouts and double taps safe.
How does Slotr prevent conflicts with Google Calendar or Outlook events?
Connected calendars block time in Slotr's availability, so a provider's external event removes the overlapping slots. Conflict checks run against bookings, active holds and synced external events together before a hold is granted.
What happens to the second customer who requests the same slot?
They get a clear unavailable response with the reason, such as the slot being held by another booking, plus the next available times. Your UI can show alternatives immediately instead of an error or a delayed refund.
Does double booking prevention work for classes and group bookings?
Yes. For bookables with capacity, Slotr serializes requests for the last spots the same way it does for single slots. A class for 12 accepts the twelfth booking and returns a reason to the thirteenth.
Let two people want the same slot. Only one of them gets it.
Join the waitlist for early access to Slotr's conflict protection.