SD-28 · Back to the write-up
Design a Hotel Booking
Search from an index and a cache that may be seconds stale; book with one conditional update in the hotel’s own shard, held for 10 minutes while the guest pays.
Follow a request
Search hotels
Hold the rooms
Pay and confirm
Race for the last room
A hold runs out
Hotel updates rooms
Clients
Edge
Services
Data
GuestWeb or app
Hotel partnersChannel managers
API gatewayAuth, limits
Payment providerCards, refunds
Search serviceStateless
Booking serviceHolds, bookings
Event workersIndex, cache, holds
Search indexHotels and prices
Availability cacheFree rooms per night
Inventory DB8 shards by hotel
The numbers, at a glance
1 booking ≈ 12/s100 searches ≈ 1,160/s
1,160/sAverage
5,800/sPeak
60,000/sSale
5% reach the shards95% from memory
A booking, in order
Hold first, pay second. If payment never comes, a worker expires the hold after 10 minutes.
Guest
Gateway
Booking service
Inventory shard
Payment provider
1 POST /holds
2 route
3 UPDATE nights … free ≥ 1
4 3 of 3 rows
5 201 hold, 10 min
6 POST /bookings
7 route
8 authorise, idem key
9 authorised
10 held → sold, confirmed
11 committed
12 201 confirmed
RequestResponseAsync, does not block
How a booking claims its rooms
The decision this question is really about.
A: SELECT free = 1B: SELECT free = 1
A: INSERT bookingB: INSERT booking
2 guests, 1 room
+ Simple.− Two guests read “1 left” and both book.
A: SELECT … FOR UPDATE
B waits
A commits, B re-checks
+ Correct.− Long locks, queues and deadlocks in a sale.
UPDATE … WHERE free ≥ 1
A: 3 of 3 rowsB: 0 rows → 409
Hold for 10 min, then pay
+ Check and write in one statement.− Count the rows changed per stay.
How it grows
Add a box only when a number forces you to. Highlighted boxes are new at each stage.
Guest
App server
SQL database
Guest
API gateway
Search serviceBooking service
Search indexAvailability cacheInventory DB
Event workers
Guest
API gateway
Search serviceBooking service + holdsPayment provider
Search indexAvailability cache8 inventory shards
Event workers
GuestHotel partners
API gateway
Search serviceBooking service + holdsPayment provider
Search indexAvailability cache8 inventory shards
Event workers + partner push
Was this walkthrough useful?Your vote tells us what to improve next.