Design a Table Booking Platform for Restaurants
System DesignModel answerLast updated
Design a multi-restaurant reservation platform where diners search availability by party size and time, then book, modify, or cancel — without ever double-booking a table.
Table Booking Platform
A hospitality company wants to build a platform that lets diners discover open tables at restaurants and reserve them online. Restaurants also use the same platform internally — staff log walk-in guests and manually entered reservations through a back-office tool that shares the same table inventory.
What the system needs to do
For diners:
- Search a restaurant's open slots by party size, date, and preferred time
- Book an available slot and receive a confirmation
- Change or cancel an existing reservation
For restaurant staff:
- Configure the restaurant's floor plan (tables and their capacities) and operating hours
- Set a standard seating duration, which may vary by party size or daypart
- View a live dashboard of all reservations and walk-ins for the day
- Seat walk-in guests or enter phone reservations directly, using the same table inventory
Hard requirement
The system must never give two parties the same table for overlapping time windows, even when several diners race to book the last suitable slot simultaneously.
Availability search results should feel fast. It is acceptable for search results to be slightly stale (a table that just got booked might still appear for a second or two), but a booking must only succeed when a table is genuinely free.
Scope and constraints
- A reservation ties a party size to a start time. The table is held for the restaurant's configured seating duration (e.g., 90 minutes). Two reservations conflict if their windows overlap on the same table.
- Combining multiple small tables to seat a large party is out of scope for this design.
- Assume the platform serves thousands of restaurants, with peak total booking attempts in the tens of thousands per minute around popular meal times.
Clarifying questions to consider
Work through these before jumping into your design — they materially affect your choices:
- Does a diner pick a specific table, or just a party size and time, leaving table assignment to the restaurant?
- How should the system handle the window between a diner starting the checkout flow and actually confirming? (What if they abandon?)
- Should popular restaurants be allowed to overbook intentionally, or is capacity always hard?
- How do time zones affect availability search and conflict detection?
- What notification channels are expected — email, SMS, both?
Describe your design. Cover the data model, how you prevent double-booking under concurrent load, how you keep availability search fast, and how you'd scale the write path for a restaurant that gets a surge of bookings at the same moment (e.g., when a celebrity chef is featured in the press).
Hints
Hint 1
Start by nailing down the conflict rule precisely before anything else: two reservations conflict when their time windows overlap on the same table. Write that as a predicate. Everything else — the lock strategy, the schema, the cache invalidation — flows from that definition.
Hint 2
Separate the read path from the write path. Availability search can be served from a precomputed, slightly stale cache per restaurant. A booking confirmation must go through the authoritative data store with a concurrency guard. Mixing these two paths is where most designs fall apart.
Hint 3
A short-lived hold (say, 5–10 minutes) bridges the gap between a diner viewing availability and completing checkout. Think carefully about what happens when the hold expires, and how you make the confirmation step idempotent so a network retry doesn't create a duplicate booking.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Strong Answer
Clarifications and assumptions
Before sketching anything, establish a few ground rules. Diners pick a time and party size; the platform (or restaurant staff) assigns a specific table — diners don't choose tables. Seating duration is configured per restaurant and optionally per party-size tier. Overbooking is off; capacity is hard. Time zones are stored with each restaurant and all conflict math happens in UTC.
Data model
The core entities are Restaurant, Table, Reservation, and an optional Hold.
Restaurant { id, name, timezone, seating_duration_minutes, ... }
Table { id, restaurant_id, capacity, label }
Reservation { id, table_id, restaurant_id, party_size,
starts_at (UTC), ends_at (UTC),
status: confirmed|cancelled,
created_by: diner_id | staff_id,
idempotency_key }
Hold { id, table_id, starts_at, ends_at,
expires_at, session_token }
ends_at = starts_at + seating_duration. A conflict exists between two intervals on the same table when A.starts_at < B.ends_at AND B.starts_at < A.ends_at. That single predicate drives everything.
Preventing double-booking
This is the critical path. Two diners can both see a table as available and both try to book it within milliseconds of each other.
Optimistic locking with a unique constraint is the cleanest approach at this scale. Add a partial unique index on (table_id, time_window) — most relational databases support exclusion constraints (PostgreSQL's EXCLUDE USING gist) that encode the overlap predicate directly. When two concurrent INSERT statements race, one wins and the other gets a constraint violation, not a double booking. The losing request returns a "no longer available" error and the diner is shown the next open slot.
For the confirmation step, use an idempotency_key (generated client-side during checkout). If a network timeout causes a retry, the second attempt hits a unique-key violation on idempotency_key rather than creating a second reservation — the server returns the original booking ID instead.
Short-lived holds handle the abandoned-checkout problem. When a diner clicks "reserve," a Hold row is inserted for 8 minutes. The confirmation step converts the Hold to a Reservation atomically (same transaction: delete hold, insert reservation, enforce overlap constraint). If the diner abandons, a background job sweeps expired holds — they simply aren't converted, and inventory is returned automatically.
A common mistake is to use application-level locking (e.g., Redis SETNX around a table ID) as the sole guard. This is fragile: if the app server dies between acquiring the lock and writing the row, inventory leaks. The database constraint must be the final arbiter.
Availability search (read path)
Searching for open tables on every request against the reservations table is expensive under load. Precompute a per-restaurant availability bitmap — a compact structure keyed by (restaurant_id, date, slot_index) that stores which tables are free for each 15-minute slot. Rebuild this whenever a reservation or hold is created, confirmed, or cancelled, and serve searches from a cache (Redis, ~5-second TTL).
Because TTL is short and a confirmed booking requires a DB check anyway, slightly stale search results are acceptable. The worst case is a diner sees a slot, tries to book it, and gets "no longer available" — that's a recoverable UX failure, not a data integrity failure.
For a restaurant with hundreds of tables and a full day's bookings, this bitmap fits in a few kilobytes. Querying it for all slots that can fit a party size is a simple scan.
Partitioning and scaling
Partition data by restaurant_id. Each restaurant's table inventory, reservations, and holds are logically isolated. This makes it natural to route all writes for a given restaurant to a single database shard, which keeps the exclusion constraint enforcement local and avoids distributed transactions.
Surge scenario: a popular restaurant goes viral and 5,000 people try to book dinner simultaneously. Because each booking attempt serializes at the DB constraint on (table_id, time_window), most will fail cleanly. To reduce thundering-herd pressure, put a request queue in front of the booking write path for that restaurant — drain it at a controlled rate (e.g., 200 bookings/second). Diners get a "joining waitlist" experience rather than an error storm.
Staff and walk-ins
Staff reservations go through the same write path — same Hold→Reservation flow, same constraint enforcement. The only difference is created_by records a staff user ID. The day-view dashboard reads from a replica, filtered by restaurant_id and date, sorted by starts_at. It refreshes every 30 seconds or via a WebSocket push on reservation changes.
Time zones
Store all timestamps in UTC. Accept search queries in local time, convert to UTC immediately, and run all overlap math in UTC. Display times back to diners in the restaurant's local timezone. Failing to do this is the single most common correctness bug in calendar/reservation systems — especially around DST transitions.
Notifications
On confirmation, enqueue a job to send an email (and optionally SMS) confirmation. Send a reminder 24 hours before the reservation. On cancellation, fire the cancellation notice immediately. Use an outbox pattern (write the notification job to the DB in the same transaction as the reservation) so notifications are never lost even if the app crashes after the write.
What interviewers want to see
- The overlap predicate stated explicitly, not hand-waved
- The race condition named and closed at the DB layer, not just in application code
- Hold/confirmation separation, with expiry handling
- Read path and write path kept separate, with acknowledged staleness on search
- Partitioning by restaurant explained, not just mentioned
- At least one concrete capacity number (TTL, hold duration, queue rate) to show calibration