Build a Table Booking Platform for Many Restaurants
System DesignModel answerLast updated
Design a multi-restaurant table booking backend that prevents double-booking, serves fast availability queries, survives peak-hour spikes, and keeps a full audit trail.
Task
You are asked to design the backend for an online table booking platform that serves many independent restaurants. Guests use it to find open times and reserve a table. Restaurant staff use it to configure their venue and run service.
What guests must be able to do
- Check which times are open for a chosen date, time and party size.
- Make a booking by providing a name, contact details, party size, desired time and optional notes.
- Change or cancel an existing booking.
- Get a confirmation right after booking and reminders before the visit, via email, SMS or push.
What restaurants must be able to do
- Create and edit a restaurant profile, opening hours, and closed days (holidays, private events).
- Define the table inventory: table identifiers, seating capacity, and which tables may be pushed together for larger parties.
- See upcoming bookings and mark each as seated, completed or no-show.
Non-functional requirements
- Correctness first: the same table must never be promised to two parties for overlapping times.
- Fast reads: availability lookups should have a p95 latency of roughly 200-300 ms.
- Traffic spikes: lunch and dinner peaks, and sudden demand for popular venues, must be absorbed.
- Traceability: every change or cancellation should record who did it, and write APIs must be safe to retry.
Assumptions to state in your answer
- The platform hosts many restaurants.
- A booking occupies a table for a fixed length of time (default 90 minutes, configurable).
- All scheduling is timezone-aware.
What your answer should cover
- Back-of-the-envelope scale estimates.
- Data model (tables, bookings, temporary holds, time slots or ranges).
- APIs and the main flow: search availability, book, confirm, remind.
- The concurrency strategy that prevents double-booking, with alternatives and trade-offs.
- Scaling and caching approach.
- Edge cases: cancellations, no-shows, walk-ins, combined tables, overbooking and waitlists.
Hints
Hint 1
Put numbers on the problem first (restaurants, bookings per day, read-to-write ratio, peak multiplier). They show that availability search is the hot path while writes are modest and shardable by restaurant.
Hint 2
Model time as a range per table rather than pre-generated slot rows, and let the database enforce that active ranges for the same table cannot overlap. Compare this against slot rows with a unique key, row locks, and distributed locks.
Hint 3
Treat the cache as a hint only: the booking transaction is the source of truth. Think about idempotency keys, short-lived holds, an outbox for notifications, and how DST and local opening hours affect slot generation.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Scope and scale
State assumptions, since they drive the design:
- About 100k restaurants with roughly 30 tables each, and about 100 bookings per restaurant per day, which gives ~10M bookings/day (~115 writes/s on average).
- Peaks are 10-20x average, so plan for ~2k writes/s.
- Browsing dominates: about 50:1 reads to writes, so ~100k availability reads/s at peak.
- Storage is about 1 KB per booking plus audit rows, so ~10-20 GB/day and a few TB/year. This is easy to shard and archive.
- Slot grid of 15 minutes, default duration 90 minutes (configurable by restaurant and party size).
- Store instants in UTC; each restaurant has an IANA timezone and opening hours are kept in local time.
Priorities: (1) no double-booking, which needs strong consistency per restaurant; (2) fast availability; (3) resilience at peaks; (4) auditability.
2. API sketch
GET /restaurants/{id}/availability?date=&party_size=
-> [{start, end, table_hint}, ...]
POST /restaurants/{id}/holds (Idempotency-Key)
{start, party_size} -> {hold_id, expires_at} # optional ~5 min
POST /reservations (Idempotency-Key)
{restaurant_id, hold_id | start, party_size, guest, notes}
-> 201 {reservation_id, status: CONFIRMED, version}
PATCH /reservations/{id} {start?, party_size?, notes?, version}
DELETE /reservations/{id} # soft cancel
# Restaurant side
PUT /restaurants/{id}/hours | /blackouts | /tables | /table-combinations
GET /restaurants/{id}/reservations?date=
POST /reservations/{id}/status {SEATED|COMPLETED|NO_SHOW}
POST /restaurants/{id}/walkins {party_size, table_ids}
3. Data model
Use a relational store (Postgres), sharded by restaurant_id so every booking decision stays inside one shard.
restaurant(id, timezone, default_duration, slot_minutes, policies)operating_hours(restaurant_id, weekday, open_local, close_local)blackout(restaurant_id, date or range, reason)dining_table(id, restaurant_id, min_cap, max_cap, area, active)table_combination(id, restaurant_id, table_ids[], min_cap, max_cap)reservation(id, restaurant_id, guest_id, party_size, period, status, source, version, created_by, idempotency_key UNIQUE)reservation_table(reservation_id, table_id, period, active)hold(id, table_ids, period, expires_at)audit_log(entity, entity_id, actor, action, before, after, ts), append-onlywaitlist_entry(restaurant_id, guest_id, party_size, desired_window, status)
Time is stored as a range per table. Slots are computed on read from ranges plus the slot grid, so variable durations are free.
4. Architecture
Clients -> Gateway (auth, rate limit)
-> Availability service -> Redis -> read replicas
-> Booking service -> Postgres primary (shard by restaurant_id)
-> Admin service
Booking/Admin -> outbox -> CDC/Kafka -> notifications, reminder scheduler,
cache invalidation, analytics
- The booking service is the only writer of reservations.
- Outbox pattern: the reservation and its event commit in one transaction, so no confirmation is sent for a rolled-back booking and none is lost.
- Reminders: delayed jobs at T-24h and T-2h (or a scan over an indexed
send_at). Each job re-checks status before sending, and sends are idempotent per (reservation, reminder type).
5. Preventing double-booking
Options, in order of preference:
- Database exclusion constraint (recommended).
The booking transaction picks candidate tables, inserts the reservation and oneALTER TABLE reservation_table ADD CONSTRAINT no_overlap EXCLUDE USING gist (table_id WITH =, period WITH &&) WHERE (active);reservation_tablerow per table. An overlap makes the insert fail; the service tries the next candidate or returns 409. Correctness holds even if the application has bugs or races. - Slot rows with a unique key
(table_id, slot_start). Portable (works with DynamoDB conditional writes) but needs ~6 rows per 90-minute booking and handles variable durations awkwardly. - Pessimistic row lock (
SELECT ... FOR UPDATE). Correct but serializes all bookings for a restaurant, hurting hot venues. - Distributed lock (Redis). Only as a contention-reducing optimization, never the source of truth, since expiry and failover can break it.
Combined tables: a party of 8 using T4+T5 writes a row for each physical table in one transaction, so the constraint protects both against single-table bookings and other combinations.
Holds: during checkout, write the same rows with an expiry; a sweeper deactivates expired ones. This makes "the slot vanished while I typed" rare during spikes.
Idempotency: the client's Idempotency-Key is unique on the reservation, so a retry returns the original result.
Modification: one transaction deactivates old rows, inserts new ones and bumps version (optimistic concurrency between guest and staff edits). If the new time is unavailable, it rolls back and the guest keeps the original booking.
6. Fast availability
For (restaurant, date, party size):
- Load hours, blackouts, eligible tables and combinations, and that day's active ranges (a few hundred rows).
- For each candidate start on the slot grid within opening hours, convert local to UTC. Skip nonexistent local times on DST changes.
- Check whether any eligible table or combination is free for
[start, start + duration).
This is in-memory work taking well under 10 ms.
Caching: cache the computed per-restaurant, per-day availability (or the compact occupancy ranges) in Redis with a short TTL of 5-30 s, and invalidate on booking events from the outbox. Serve reads from replicas. Because the cache can be stale, the booking transaction always re-validates; a stale hit just means a 409 and a refreshed list. Popular venues can use request coalescing to avoid cache stampedes.
7. Scaling
- Shard by
restaurant_id; a booking never crosses shards. - Autoscale stateless services. Rate-limit per user and IP, and use a queue or virtual waiting room for drop-style events.
- Hot restaurants are bounded by a single shard's write rate (low hundreds per second at worst), which the exclusion constraint handles comfortably.
- Archive finished reservations to cold storage; keep the audit log append-only.
8. Edge cases
- Cancellation: soft-delete, set
active=falseon its table rows, emit an event that invalidates the cache and triggers waitlist matching. - No-shows: staff mark NO_SHOW; the table is released early, and the guest's history can feed a deposit or penalty policy.
- Walk-ins: insert a reservation with
source=walkinand an estimated duration through the same constraint path, so they cannot collide with later bookings. - Overbooking: only as an explicit per-restaurant policy (a soft capacity buffer) kept outside the hard constraint.
- Waitlist: on a freed slot, notify the first matching entry with a short hold; if it is not claimed, move on.
- Overrunning parties: staff can extend a seated reservation; if that conflicts with the next booking, surface it rather than silently overlapping.
Common mistakes
- Relying on a cache or application-level check as the guarantee against double-booking.
- Using a distributed lock as the source of truth.
- Pre-generating slot rows, which makes variable durations and combinations painful.
- Ignoring timezones and DST.
- Sending notifications before the booking transaction commits.
- Forgetting idempotency on retries.