Design a Restaurant Table Reservation System
- Build a working MVP first: tables, reservations and the SQL that finds a free table
- Stop two guests from booking one table, with holds that expire on their own
- Defend caching, partitioning by restaurant and changes to a booking when pushed
Understanding the problem
Something like this: design a system that lets guests reserve a table at a restaurant. A guest picks a restaurant, a date, a time and a party size, sees what's open, and books it. They can change or cancel later. Start with an MVP, then talk about concurrency and scale.
This is the design prompt that keeps coming back in Toast loops. In 2026 alone, a Staff engineer in India (April), a software engineer in the US (June) and another software engineer (September) all reported a table or seat reservation design. A Senior candidate got "a restaurant table booking system" as the fourth round of a late 2025 loop. Two older reports point the same way. A Principal candidate in 2022 was told "you are the CTO" and asked for an MVP, and a 2019 Boston Senior whiteboarded "a scalable, web-based restaurant reservation system."
It looks small, and in a way it is. A restaurant has maybe 30 tables and serves a few hundred guests a night. The hard part is that a table at 7pm on Friday is a single thing that two people can try to grab in the same second. Most of the hour goes into getting that one write right, then making the reads cheap enough that a busy evening doesn't hammer the database.
Requirements
Functional requirements
Ask who the users are before anything else. There are two. Guests search and book from a website or app. Restaurant staff at the host stand see the night's bookings, seat walk-ins, and fix mistakes. Both write to the same tables, which matters later. Then pin down what a booking is. A guest books a time and a party size, and the system assigns a table. Guests don't pick table 12, but the system has to put them somewhere real, or it will sell the same seats twice.
In scope
- Show open times for a restaurant, date and party size
- Book a time, holding the table while the guest enters details
- Change or cancel a booking
- Never give one table to two parties at the same time
- Let host stand staff see and edit the night's bookings
Below the line (call it out, then skip)
- Searching across every restaurant in a city
- The waitlist, deposits and no-show fees
- Combining tables for large parties, until asked
- Reviews, menus and online ordering
Non-functional requirements
Correctness on the booking path comes first. A double booking means two parties standing at the host stand for one table, and a restaurant remembers that. So the write that claims a table must be strongly consistent. Reads can relax. If the list of open times is 30 seconds stale, the worst case is a guest picking a time that just went, and the booking step tells them so. Availability matters, but a restaurant can survive the booking site being down for a minute. It can't survive the host stand losing tonight's list, so the read of tonight's bookings should be fast and well protected. Ask for numbers. If the interviewer has none, propose some. Say 100,000 restaurants take bookings, each with about 40 a day. Searches run about 20 to 1 against bookings, because people look at several times and places before they commit.
- Bookings: about 4M a day. 100,000 restaurants times 40 bookings. That averages about 46 a second, and maybe 500 a second in the early evening peak.
- Availability reads: about 10,000 a second at peak. Twenty searches per booking gives 80M a day, near 900 a second on average and ten times that at peak.
- Storage: about 450 GB a year. Roughly 1.5 billion reservation rows a year at around 300 bytes each. Easy for Postgres, especially split by restaurant.
- One restaurant: about 30 tables. A night is small: a few dozen tables and a few dozen bookings. Every query for one restaurant and one date touches very few rows.
The data model, in words
Four records carry the design. A restaurant has a time zone and its opening hours for each day of the week, plus a slot interval (every 15 minutes, say) and a turn time per party size. Turn time is how long a party keeps the table. A restaurant might give a party of two 90 minutes and a party of six two and a half hours. A table belongs to one restaurant and seats a range of people, such as two to four. The range matters because a four-top can take a couple on a slow night, but the system should prefer a two-top for them.
A reservation is the record everything turns on. It points at one table and covers a time range, from starts_at to ends_at, which is the start time plus the turn time. It starts as a hold with an expiry a few minutes out, then becomes confirmed, or it ends as cancelled or expired. Walk-ins seated by the host are reservations too, just ones that start now. A guest is the person: a name, a phone number, maybe an email.
| Table | Fields |
|---|---|
| restaurants | restaurant_id · name · time_zone · slot_minutes |
| opening_hours | restaurant_id · day_of_week · opens_at · closes_at |
| turn_times | restaurant_id · min_party · max_party · minutes |
| dining_tables | table_id · restaurant_id · min_seats · max_seats · active |
| reservations | reservation_id · restaurant_id · table_id · guest_id · party_size · starts_at · ends_at · status · hold_expires_at · idempotency_key |
| guests | guest_id · name · phone · email |
A reservation stores a time range on a table, never a list of slots, and the interviewer may ask why. Ranges make the overlap check one comparison, and they survive a restaurant changing its slot interval from 15 to 30 minutes. The index that makes the next query fast is on table id plus start time.
The exact SQL availability query
This query answers "is there a table for four at 7pm?" It finds tables at the restaurant that seat the party, then drops any table with a live reservation that overlaps the requested range. Smallest fitting table first, so a couple doesn't take the eight-top.
SELECT t.table_id FROM dining_tables tWHERE t.restaurant_id = :restaurant AND :party BETWEEN t.min_seats AND t.max_seats AND NOT EXISTS (SELECT 1 FROM reservations r WHERE r.table_id = t.table_id AND (r.status = 'confirmed' OR (r.status = 'held' AND r.hold_expires_at > now())) AND r.starts_at < :wanted_end AND r.ends_at > :wanted_start)ORDER BY t.max_seats, t.table_id;The last condition is the one to get exactly right. Two ranges overlap when each one starts before the other ends. Using strict less-than on both sides treats a range as half open, so a booking ending at half past seven and one starting then sit back to back without clashing. A held reservation only blocks the table while its hold is still in the future. Without that clause, a guest who wandered off mid-checkout would block a table until some cleanup job ran.
The list of open times for an evening is the same query run once per start time. The service builds the start times from the opening hours and slot interval: every 15 minutes from 5pm until the kitchen's last seating. With a few dozen tables and bookings per night, all of it touches a few hundred rows. Postgres can also do it in one statement by generating the start times inside the query, but the loop is easier to explain on a whiteboard.
The API
Five calls cover the guest side. Booking is split into hold and confirm, because the guest needs a minute to type their name and phone number, and nobody else should take the table meanwhile. Both writes take an idempotency key, a value the client generates once per attempt, so a retry after a dropped connection returns the same booking.
The host stand uses the same service with a few staff-only calls: list tonight's bookings, seat a walk-in on a specific table, and mark a party as seated or done. A walk-in goes through the same overlap check as any other booking. If it didn't, a host could seat someone at a table that a guest booked online ten seconds ago.
The architecture end to end
The MVP is one service and one database, and it would work for a long time. The diagram adds three pieces the deep dives earn. A cache absorbs the flood of searches, and a sweeper clears abandoned holds. An event stream tells the cache and the guest what changed. In the diagram, blue is people, violet is a service we run, amber moves events, and green stores state.
1) Search. The guest asks for Friday, party of four. The Reservation API looks up the turn time for four people, builds the evening's start times, and checks the Availability cache for that restaurant, date and party size. On a miss it runs the availability query against the Reservations database for each start time and caches the result. A single restaurant's evening is a few hundred rows, so even a miss returns in tens of milliseconds. The cache is there for volume, and the caching deep dive covers when it goes stale.
2) Hold. The guest taps 7pm. In one transaction, the API finds the smallest free table that fits and inserts a reservation with status held and an expiry five minutes out. It returns the reservation id and the expiry, which the page shows as a countdown. Two guests tapping 7pm on the last table in the same instant is where most of the round's pressure lands, and it gets its own deep dive.
3) Confirm. The guest submits a name and phone number. Next, the API flips the reservation from held to confirmed, but only if the hold is still in the future. That transaction also writes an outbox row, so Booking events picks it up and the Notifier texts a confirmation. Holds nobody confirms are left for the Hold sweeper to mark expired.
4) Change, cancel, seat. A change rewrites the reservation's time and table in one transaction, so the guest never loses the old slot unless the new one succeeds. A cancel sets the status to cancelled, and the table is free the moment that commits. Staff on the Host stand tablet seat walk-ins through the same path. Each of these writes an outbox row, which clears the cached open times for that restaurant and date.
Technology choices
- The Reservations database is Postgres. Booking needs a transaction and a rule that two rows can't overlap, which relational databases do well. Run a synchronous replica so a failover doesn't lose a confirmed booking.
- The Availability cache is Redis, because open times are small, hot and cheap to rebuild. If Redis goes down, searches fall through to Postgres, which can carry the load for a while.
- Booking events use an outbox table plus SQS or Kafka. The outbox closes the gap where a booking commits but its event is lost. Consumers must handle duplicates, since delivery is at least once.
- The Reservation API and Hold sweeper are plain containers. Neither holds state, so a crash loses nothing that isn't already in Postgres.
Name the popular tool and defend the category. If the team uses MySQL, expect to explain how you stop overlapping rows without Postgres's range constraint. The next deep dive covers that too.
Potential deep dives
How do we stop two guests from booking the same table?
Picture a popular place that opens Friday bookings at 10am. There are 20 tables and four seatings, so 80 bookable table times, and 3,000 people hit the page at once. Hundreds of them tap the same half past seven slot within a second. Every one of those requests runs the availability query, sees a free table, and tries to book it. Exactly one should win each table.
Approach
Run the availability query, pick the first free table, then insert a reservation for it. Two statements, each perfectly correct on its own.
Challenges
Postgres runs at read committed by default, so two transactions can both run the check before either inserts. Both see table 12 free, both insert, and both guests get a confirmation for one table. Tests on a laptop never catch it, because the race needs two requests in the same few milliseconds. At a popular opening it happens every time. Wrapping it in a transaction doesn't help on its own, because neither transaction sees the other's uncommitted row.
Approach
Inside the transaction, lock the candidate table's row with select for update before checking for overlaps. A second request for the same table waits on that lock. When the first commits, the second rechecks, sees the new reservation, and moves to the next table. Bookings for different tables never wait on each other. When one booking needs two tables pushed together, lock them in table id order so two requests can't deadlock.
Challenges
Correctness depends on every code path remembering to take the lock. The guest flow will. The host stand's walk-in button, an admin script, or a bulk move when a table breaks are easy to miss. One forgotten lock and the double booking is back. Under a hot opening, hundreds of requests also queue on a handful of locked rows, each holding a database connection while it waits.
Plenty of systems ship the Good tier and run fine for years. The case for going further is that forgotten code path. A rule enforced by Postgres holds for every writer, including ones written next year by someone who never read this design.
Approach
Add an exclusion constraint on reservations: no two live rows may share a table id with overlapping time ranges. Booking just tries the insert. If another live booking overlaps, Postgres rejects it with an exclusion violation, and the service tries the next fitting table, or tells the guest the time just went. Changes are covered too, because an update that moves a booking onto a busy range fails the same way.
Challenges
The constraint can only filter on stored columns, never the current time, so an expired hold still blocks until something marks it expired. The booking transaction therefore first expires stale holds on its candidate tables, and the sweeper does the rest. It needs the btree_gist extension. On MySQL or DynamoDB, model each table and 15-minute slot as its own row with a unique key, and insert all of a booking's slots at once.
ALTER TABLE reservations ADD CONSTRAINT no_double_booking EXCLUDE USING gist (table_id WITH =, tstzrange(starts_at, ends_at) WITH &&) WHERE (status IN ('held', 'confirmed'));A range built this way is half open by default, so back-to-back bookings pass, matching the availability query. Then answer the hot opening directly. Each booking transaction is a few milliseconds, so even 500 attempts on one table settle in about a second, and 499 of them get a clean "just taken." If an opening is known to be huge, put a short virtual queue in front of the hold call so the database sees a steady stream. The handling contention lesson compares locks, optimistic checks and constraints in general.
How do holds work, and what stops them from going stale?
Without a hold, the guest picks 7pm, spends two minutes typing their details, hits confirm, and learns the table is gone. With a hold, the table is theirs for a few minutes. The cost is that an abandoned hold blocks a real table, and at a popular opening many holds get abandoned. Five minutes is a reasonable starting point. It is long enough to type a name and phone number, and short enough that a lost table comes back quickly.
A hold is a reservation row
It has status held and an expiry time. It passes through the same overlap constraint as a confirmed booking, so a held table really is off the market. There is no separate lock service to keep in sync.
Confirm checks the clock in the database
The confirm is a single update that only succeeds while the row is still held and the expiry is in the future. If no row changes, the hold lapsed and the guest searches again. Using the database's clock avoids arguing with app servers whose clocks drift.
Expired holds stop blocking right away
The availability query ignores holds past their expiry, so the table shows as open the moment the hold lapses. The booking transaction expires stale holds on the tables it is about to use, so the constraint doesn't trip on them.
Limit holds per guest
Allow one live hold per guest per restaurant and date, so a script can't park itself on a dozen tables. A new hold from the same guest replaces the old one in the same transaction.
UPDATE reservations SET status = 'confirmed', guest_id = :guestWHERE reservation_id = :id AND status = 'held' AND hold_expires_at > now();-- zero rows updated means the hold expired or was never thereIdempotency closes the last gap. A guest on a train taps confirm, the response is lost, and the app retries. The second confirm finds the row already confirmed. Treat that as success and return the same booking, rather than an error that makes the guest think it failed. Holds work the same way: a repeated hold with the same idempotency key returns the reservation it already created.
How do changes and cancellations stay safe?
A guest booked for four at 7pm now wants six at 8pm. The obvious build is cancel then rebook, and it has a nasty failure. If the cancel commits and the rebook finds nothing, the guest has lost both. A change should be one transaction that either lands the new booking or leaves the old one exactly as it was.
Approach
Compute the new turn time from the new party size and find a fitting table. Then update the existing reservation's table, start, end and party size in one statement. The exclusion constraint checks the new range against everyone else's bookings. The row being updated doesn't conflict with itself, because Postgres checks the new version of the row against the other rows. If it fails, nothing changed and the API returns "that time isn't available" with nearby options.
Challenges
Because the reservation id stays the same, confirmation links and the host stand view keep working. You do lose the history. A restaurant might want to know a party grew from four to six, so write a row to a small change log in the same transaction. If the new time needs a different table and the old table is also free at the new time, prefer keeping the old table, since staff may have planned around it.
Cancelling is the simple case. Set the status to cancelled and the constraint stops counting the row, so the table is bookable the instant the transaction commits. The outbox row from that transaction clears the cached open times, so the freed slot appears in searches within a second or two. Keep cancelled rows instead of deleting them. Restaurants care about no-show and late-cancel history, and a deleted row can't answer "did this guest cancel last time?"
How do we keep availability fast without showing taken tables?
Search outnumbers booking by about 20 to 1, and searches bunch around the same restaurants and evenings. At 10,000 searches a second, each running the availability query for 16 or so start times, the database would run 160,000 small queries a second. Each one is cheap, but that is a lot of connections for an answer that barely changes. The open times for one restaurant, date and party size make a perfect cache entry: a few dozen times, read constantly, changed only by a booking.
Approach
Cache each restaurant's open times for an hour, and let the booking page treat the cached answer as the truth.
Challenges
A popular restaurant fills in minutes, so an hour-old answer shows slots that went long ago. Guests tap them, fail, and tap again. Worse, if any booking path skips the database check because the cache said yes, the cache becomes a way to double book.
Approach
Cache open times per restaurant, date and party size with a 30-second expiry. On a miss, run the query and fill the entry. The hold call ignores the cache entirely and lets the database constraint decide. A stale entry costs a guest one "just taken, here are nearby times" message, never a double booking.
Challenges
Thirty seconds is a long time at a busy opening, and in the other direction a cancelled table stays hidden for up to 30 seconds. When a hot entry expires, hundreds of concurrent searches miss at once and all hit the database together. That is a cache stampede.
Approach
Keep a version number per restaurant and date. Every booking change bumps it in the same transaction, and the cache key includes the version, so an entry built before a booking is never read again. The outbox event also deletes the old entries, and the expiry stays as a safety net. On a miss, one request rebuilds the entry while the others wait a few milliseconds for it.
Challenges
The version read is one extra cache round trip per search, which is cheap. Clearing by restaurant and date drops every party size for that evening, but rebuilding them is a few hundred rows. The cache is now a few seconds behind at worst, and the booking path still rechecks in the database, so a cache bug can only cost speed.
Say the rule out loud. Guests browse from the cache, but every hold and confirm is checked against Postgres. Read replicas are the other lever. Availability queries can run on replicas a fraction of a second behind, for the same reason the cache can be stale. The scaling reads lesson covers cache-aside, stampedes and replicas in general.
How does it scale to every restaurant on the platform?
Be honest about the write rate first. Five hundred bookings a second at peak, each a short transaction, fits on a single well-sized Postgres primary. The reasons to partition are the read load, storage that grows by a few hundred gigabytes a year, and limiting the damage when one database has a bad day.
Partition by restaurant id. Every booking, change, cancel and availability query is about exactly one restaurant, so every transaction lands on one shard. The exclusion constraint keeps working, because a table and its reservations always live together. A router maps restaurant id to shard. Start with a lookup table instead of a plain hash, so a very busy restaurant group can be moved to its own shard later without rehashing everyone. Within a shard, partition the reservations table by month. Last year's dinners are read rarely, and old months can move to cheaper storage or an archive.
A hot restaurant is a hot row, never a hot shard. Three thousand people fighting over one restaurant's Friday is still one restaurant's handful of rows, and the constraint resolves it in about a second. Cross-restaurant search, like "any table for four near me at half past seven," is the one query that doesn't fit this partitioning. It needs its own index built from booking events, which is a separate design and usually below the line.
Practice the core in code
The heart of the design fits in one class. It keeps the tables, places holds on the smallest table that fits and is free, confirms a hold only before it expires, frees a table on cancel, and answers the availability question. The database, the cache and the clock are gone. Time is a plain number of minutes, passed in on every call.
Table book: holds, confirms and no double booking
Problem
start up to but not including end. A table seats any party from its minimum to its maximum size.Write a class
TableBook(hold_minutes). add_table(table_id, min_seats, max_seats) adds a table and returns true, or false if it already exists. hold(reservation_id, party_size, start, end, now) places a hold that expires at now + hold_minutes. It picks the fitting free table with the smallest maximum, breaking ties by the smaller table id, and returns that id, or null if none is free.If the reservation id is already known, it books nothing and returns that reservation's table while it is still live, or
null otherwise.A reservation is live while it is confirmed, or while it is held and
now is before its expiry. A table is free for a range when no live reservation on it overlaps the range.The method
confirm(reservation_id, now) confirms a live hold and returns true. It also returns true for a reservation that is already confirmed, and false in every other case. The method cancel(reservation_id, now) frees a live reservation and returns true, or returns false otherwise. Last, available(party_size, start, end, now) returns the ids of fitting free tables, in the order hold prefers them.Input encoding. A test case is a JSON array of operations. The first entry is
["TableBook", [hold_minutes]] and each later entry is [method, [args]]. The expected array holds each operation's return, with null for the constructor.- TableBook(5)
- add_table("T1", 1, 2)→ true
- add_table("T2", 2, 4)→ true
- hold("r1", 2, 1140, 1230, 1100)→ "T1"
- hold("r2", 2, 1140, 1230, 1101)→ "T2"
- hold("r3", 2, 1140, 1230, 1102)
The couple gets the two-top first. The second couple gets the four-top, and a third couple at 7pm finds nothing free.
Keep each reservation with its table, range, status and hold expiry. Free means no live reservation on the table overlaps, where two ranges overlap when each starts before the other ends.
Table book: holds, confirms and no double booking
Click "Run" to execute your code
change(reservation_id, party_size, start, end, now) that moves a live booking all or nothing, keeping its table when that table is still free. Then add tables that combine for large parties, where a booking must check every table in the combination. Finally, talk about where this state lives once it leaves memory: the reservations table, the constraint and the confirm update.Follow-ups to be ready for
Large parties and combined tables. A party of ten needs tables 4 and 5 pushed together. Model a combination as its own bookable entry that lists its member tables. A booking for it writes one row per member table, all inside one transaction, so the per-table constraint still guards every seat.
Time zones and daylight saving. Store times in UTC and the restaurant's time zone on the restaurant. Build the evening's start times in local time and convert, or on the nights the clocks change a late slot can show up twice or vanish.
Waitlist. When nothing is open, let the guest join a waitlist for that evening. A cancellation event can offer the freed time to the first person in line, as a hold with a short expiry, so they have to confirm.
Deposits and no-shows. For busy nights a restaurant may want a card on file. That fits the hold step: the guest authorizes a card during the hold, and confirm only succeeds once the payment side says yes. Key the payment call on the reservation id so a retry can't charge twice.
What is expected at each level
Software Engineer II
Design rounds show up at Senior and above in every report that names a level, and recent SWE I and II loops mostly don't mention one. Still, a June 2026 US software engineer loop with no level given had a reservation booking prompt as its one design round, so be ready. Aim for about 80% breadth and 20% depth. You should produce the tables, the API and a working availability query, and spot the double-booking race when the interviewer hints at it. The bar: a complete MVP you can walk through one booking at a time.
Senior
Roughly 60% breadth and 40% depth. You raise the race yourself, write the overlap condition correctly the first time, and reach a database-enforced rule before being asked. You handle holds with expiry and a change that can't lose the old booking. The bar: the exact SQL, the constraint, and a clear reason the cache can never cause a double booking.
Staff and Principal
Closer to 40% breadth and 60% depth, and you set the direction. Start from the MVP the way the 2022 "you are the CTO" prompt asked, then decide what to build next and why. Be honest that one Postgres primary carries the writes, and partition by restaurant for reads, growth and blast radius. The bar: you lead, and the interviewer redirects you instead of rescuing you.
Key Takeaways
- ✓Get the MVP working first: tables, reservations and one availability query, as Toast candidates in 2022 and 2026 reported.
- ✓Write the overlap rule exactly: each booking starts before the other ends, and only confirmed or unexpired held rows count.
- ✓Let Postgres refuse overlapping live bookings with an exclusion constraint, so every writer, host stand included, is covered.
- ✓Cache open times per restaurant and date, but check every hold in Postgres. Partition all data by restaurant id.
Toast interview guideKnow what Toast asks before you walk in.
24 coding · 3 system design · 17 behavioral questions
Get their questions first.
InterviewLegend is independent and not affiliated with or endorsed by any company it covers.