Under the hood

How double-booking is prevented

Two guests press Book on the last table for eight o’clock in the same second. Only one of them can have it, and the other has to be told before they leave the page, not at the door.

41 statements, each traced to code or a test.

All technical pages

The problem a busy Friday creates

A double booking is rarely one mistake. It is two correct actions that happened at the same moment: a guest on the website and a host on the phone, or two guests who both saw the same free table. Each was shown a true answer, and both answers could not stay true.

The cost lands at the door. A party is standing in front of a full room holding a confirmation, a manager is deciding which regular to disappoint, and the review is written before the starters go out. A booking system that only checks availability when the page loads leaves that gap open every busy evening.

Closing it takes three things: every booking has to be checked at the moment it is written, competing requests have to wait for each other, and a request that is sent twice has to count once. This page sets out how TableSpark does each of them.

In short
  • Before a booking is written, the database takes a lock: on the restaurant and the date when capacity is counted by tables, on the service and the date when it is counted by covers. Requests that compete for the same capacity are handled one after another, never at the same moment.
  • The availability check, the booking record and the table assignment are made inside that lock, in one database transaction.
  • Every booking request carries a unique reference created in the guest’s browser, and the database allows one booking per restaurant for each reference.
  • An automated test races two sessions for the last table, and two services for one table, and requires exactly one winner each time.

Two ways to count capacity

Each service counts capacity in one of two ways: by covers per time slot, or by specific tables.

By coversIn covers mode a time is open when, at every slot the sitting touches, the covers already booked plus the new party stay within the limit you set.
By tablesA table is offered to a party when the party falls between that table’s smallest and largest seating, and the tightest fit is chosen first. When no single table fits, two tables marked as combinable in the same zone are offered together.

A table counts as taken when a booking that is requested, confirmed, arrived or seated overlaps the sitting by even one minute. A table blocked for a date, or for part of a date, is left out of both searches.

For larger parties the owner defines combinations of up to eight tables with their own seat range, and the tightest combination whose tables are all free and unblocked is used. A service can also limit how many covers or bookings arrive in one time window, and how many covers it takes in a day. That check runs inside the same lock, after capacity has said yes.

A service can be switched to table mode only when it has active tables and every future booking already has one. A booking in table mode cannot be saved without at least one table: the database rejects the transaction.

What happens when a guest presses Book

  1. The form is checkedThe public booking form is checked with Cloudflare Turnstile and rate-limited per visitor before it reaches the database.
  2. The day is lockedBefore a booking is written, the database takes a lock: on the restaurant and the date when capacity is counted by tables, on the service and the date when it is counted by covers. Requests that compete for the same capacity are handled one after another, never at the same moment. The table lock leaves the service out on purpose, because lunch and an afternoon service share the same tables.
  3. The rules are applied againThe booking step repeats every rule the availability page applied: party size, opening window, slot grid and notice period. A page left open on a phone cannot book a time that has since gone.
  4. The table is found and the booking is writtenThe availability check, the booking record and the table assignment are made inside that lock, in one database transaction.
  5. If the time has gone, the guest is told nowWhen the chosen time has just gone, the guest is offered up to four other times within two hours of it, nearest first.
The TableSpark bookings diary for one lunch service, listing each booking with its time, party size, status and table
The bookings diary for one service. Every row here was written through the steps above.

Everyone goes through the same door

A lock only protects the paths that take it. A host adding a phone booking, a walk-in seated from the queue and a guest changing their own time are all ways for two bookings to meet, so they are treated the same way as the booking page.

Bookings taken by staff, guests seated from the waitlist and guests who move their own booking all pass through the same booking function as the public booking page. Moving a booking, assigning tables by hand and blocking a table take the same lock, so none of them can slip between a guest’s availability check and that guest’s booking.

Assigning a table that is already taken at an overlapping time is refused. When a signed-in guest moves their own booking, the new time is booked first and the old one is released only after that succeeds, in a single transaction.

Bookings brought in from another system are imported as one transaction through the same booking function: if any row has a problem, nothing is written and every problem is listed by row.

How availability is worked out

The times a guest sees are computed from the restaurant’s own settings each time they are asked for.

Times offeredTimes are offered from the first to the last seating of each service, in steps of 15, 30 or 60 minutes.
NoticeA time is offered only when it is far enough ahead to meet the service’s notice period, measured on London time.
Party and horizonEach service has its own smallest and largest party and its own booking horizon in days.
Length of a sittingThe length of a sitting is set per service, with a longer sitting for parties at or above a size you choose. Where one longer sitting for large parties is too coarse, the length can be set in bands by party size.
Special datesA special date replaces the weekly hours for bookings, and a date marked closed offers no times. A closure for a date always wins over any opening override.

Deposits and holds

A table that is waiting for a deposit is the classic way to sell the same table twice: the first guest is on the payment page while the second is offered the slot.

A booking that needs a deposit or a card guarantee holds its table from the moment it is requested, exactly as a confirmed booking does. A hold that is still unpaid after 15 minutes is cancelled by a sweep that runs every quarter of an hour, and the table goes back on sale.

The cancellation terms in force are copied onto each deposit when it is taken, so a later change of policy leaves earlier deposits as they were agreed. A guest cancels from a private link, and a cancelled booking stops counting at once, so the time is offered again.

A request sent twice counts once

Phones lose signal in basements and on trains, and a booking form that is tapped twice must not seat the same party at two tables.

Every booking request carries a unique reference created in the guest’s browser, and the database allows one booking per restaurant for each reference. If a phone loses signal and sends the request twice, the second request returns the booking that already exists, and the confirmation email is sent once.

Where bookings come from

Each online booking records the channel it came through (the booking form on the restaurant’s site, a widget on another site, the Guest App, the Google booking link or an AI assistant’s hand-off) and the campaign tags of the page it was made on.

The Reserve with Google capability is a booking-link connection: the restaurant’s booking address is saved once and published as the link Google sends guests to. Booking confirmation, change and cancellation emails carry a calendar file the guest can add to their diary.

How this is tested

Concurrency faults do not show up when one person clicks through a form. They show up when requests are fired at the same instant, on purpose, against a real database.

  • An automated test races two sessions for the last table, and two services for one table, and requires exactly one winner each time.
  • A concurrency script fires 100 simultaneous booking requests at the last places in a service and requires exactly one confirmed booking and one stored row.
  • Another test races a table block against a booking in both orders, then repeats a free-for-all for twelve rounds.
  • A waitlist test sends two staff to seat the same waiting party at once and requires exactly one to succeed.

Questions owners ask

What stops two guests booking the last table at the same moment?

Before a booking is written, the database takes a lock: on the restaurant and the date when capacity is counted by tables, on the service and the date when it is counted by covers. Requests that compete for the same capacity are handled one after another, never at the same moment. The availability check, the booking record and the table assignment are made inside that lock, in one database transaction.

Does a table stay free while a guest is paying a deposit?

A booking that needs a deposit or a card guarantee holds its table from the moment it is requested, exactly as a confirmed booking does. A hold that is still unpaid after 15 minutes is cancelled by a sweep that runs every quarter of an hour, and the table goes back on sale.

What happens if a guest taps Book twice?

Every booking request carries a unique reference created in the guest’s browser, and the database allows one booking per restaurant for each reference. If a phone loses signal and sends the request twice, the second request returns the booking that already exists, and the confirmation email is sent once.

How this page is kept true

This page makes 41 statements about how TableSpark behaves. Each one is recorded with the place in the code, the database or the test suite that enforces it, and an automated check fails when a statement loses its evidence. The suites named below exercise the behaviour described here.

Automated suites behind this page

  • booking-attribution
  • booking-capacity-db
  • deposit-cancel-policy-db
  • product-truth-reserve-google
  • reservations-tables
  • table-blocks-engine-db
  • waitlist-db

See it on your own restaurant

Build your site free and publish when you are ready. Plans start at £19 a month, excluding VAT.

Start building free