Skip to content
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

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
1user → gateway · POST /holdsThe guest picks a Double for 12 to 15 June and taps Reserve. The app sends an Idempotency-Key.1 / 8

The numbers, at a glance

For every booking……there are about 100 searches
1 booking ≈ 12/s100 searches ≈ 1,160/s
A flash sale is 10× the peakSearches per second
The cache takes the readsAvailability reads at 60,000 searches/s
So the shards spend their time on bookings, not on page views.

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.

Read, then write
Double books
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.
Lock the rows
Correct, slow
A: SELECT … FOR UPDATE
B waits
A commits, B re-checks
+ Correct.− Long locks, queues and deadlocks in a sale.
Conditional update
Our pick
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.

Stage 1 · ≈ 100 searches/sMake it work
Guest
App server
SQL database
One server, one database. Searches scan room counts; bookings read, then write.
Stage 2 · ≈ 5,800 searches/sSplit search off
Guest
API gateway
Search serviceBooking service
Search indexAvailability cacheInventory DB
Event workers
Search goes to an index and a cache, fed from the change stream.
Stage 3 · ≈ 60,000 searches/s, 600 bookings/sBook safely
Guest
API gateway
Search serviceBooking service + holdsPayment provider
Search indexAvailability cache8 inventory shards
Event workers
Holds with one conditional update, payments, 8 shards by hotel.
Stage 4 · 60,000 searches/s + 5,000 updates/sSell everywhere
GuestHotel partners
API gateway
Search serviceBooking service + holdsPayment provider
Search indexAvailability cache8 inventory shards
Event workers + partner push
Channel managers push rooms in; our bookings go out within seconds.
Was this walkthrough useful?Your vote tells us what to improve next.