Question presented to candidate:
"Design the reservation system for a hotel chain like Marriott, or a booking site like Booking.com: guests search for hotels by city and dates, see prices, and book a room type for several nights. Make sure we never sell more rooms than we have, unless we decide to overbook on purpose."
What a strong answer should cover:
Inventory modelled as counters per (hotel, room type, date), not individual rooms: guests book a type, the front desk assigns the room number at check-in
The double-booking race (two guests, one room left) and how to prevent it: a conditional UPDATE ... WHERE reserved + n <= total, optimistic versioning, or row locks, with the trade-offs
A multi-night stay updates several date rows in one transaction, all or nothing
The reservation lifecycle (pending, paid, confirmed, cancelled), holds that expire during payment, and an idempotent reserve call
Overbooking as a business setting (for example accept 110% of rooms) with the no-show arithmetic behind it
Scale: writes are tiny (a few per second), reads are large (search and availability); cache and replicate reads, shard by hotel
Clarifying questions expected:
One chain or an aggregator of many hotels? How many hotels and rooms?
Do guests book a room type or a specific room?
Is overbooking allowed, and by how much? Pay now or pay at the hotel?
Code / implementation expected: Optional โ the example reproduces the double-booking race and shows conditional updates, all-or-nothing multi-night bookings, idempotent retries and the overbooking curve.
system-design
case-study
2
Try it yourself
Sketch your approach before you read the solution. That is what the interview tests.
Stuck? Get a hint.
A short nudge toward the approach. It will not give the answer away.
3
Solution
Target Audience: Backend engineers preparing for "design a booking system" rounds, and anyone who wants to see why "check, then insert" is the most expensive bug in reservations.
Difficulty: Hard
Verified with: Node 22.22 and Python 3.12 (identical output). The race and the fixes are simulated in-process; the SQL statements shown are the standard PostgreSQL and MySQL forms of the same logic.
How to read this doc: Every idea is explained in plain language first, then tagged with ๐ Interview term: so you also learn the words an interviewer expects. Every number comes from running the example; the Verified section quotes its full output.
1. Why This Even Matters โ A Story First
A small hotel has 10 king rooms and a paper diary at the front desk. On Christmas Eve, 9 are already written in. Two phone lines ring at the same moment. Two receptionists each look at
The solution is hidden so you can try first
9 min read ยท 16 sections
4
Read the code
Hotel inventory counters: the double-booking race, conditional updates, all-or-nothing multi-night stays, retries and overbooking