System DesignSep 20, 2026⏱️ 3 min read
Design a Hotel Reservation System: Concurrency Control, Optimistic Locking & Overbooking

Design a Hotel Reservation System: Concurrency Control, Optimistic Locking & Overbooking

Preventing Double-Booking Under Flash Traffic

In hotel and travel booking systems, a user searches available rooms, locks in a rate, and submits payment. While overall QPS is moderate compared to social feeds (~5,000 hotels × ~1,000 rooms = ~5M records—fits cleanly in a single primary relational DB with read replicas!), race conditions during flash sales or holiday peaks cause two critical failures:
  1. Two guests book the last remaining room simultaneously (double-booking).
  2. Clicking "Confirm Booking" twice on flaky mobile Wi-Fi charges the guest twice (duplicate reservation).
Hotel Reservation Concurrency Architecture

Hotel Reservation Concurrency Architecture


1. Key Data Modeling Choice: Reserve Room Types, Not Physical Room Numbers

Guests don't pick "Room #402" online; they book "Deluxe King Bed". Modeling room_type_inventory tracks (hotel_id, room_type_id, date, total_inventory, total_reserved) rather than individual room rows—shrinking table size by 20× and simplifying range updates cleanly.

Supporting Controlled Overbooking (e.g., 10%)

Hotels routinely allow ~10% overbooking to absorb cancellations:
sql
CHECK (total_reserved <= FLOOR(total_inventory * 1.10))

2. Three Ways to Solve Double-Booking Concurrency

StrategyMechanismProsCons
Pessimistic Locking (SELECT ... FOR UPDATE)Holds DB row lock during transactionSimple, impossible to overshootContention / deadlocks under slow clients
Optimistic Locking (version column)UPDATE ... SET reserved = reserved + 1, version = version + 1 WHERE version = :vZero long-held locks; fast under low/medium contentionNeeds client retry on 0 rows affected
Database Constraint (CHECK + Atomic UPDATE)UPDATE room_type_inventory SET total_reserved = total_reserved + 1 WHERE ... AND total_reserved + 1 <= total_inventorySingle atomic SQL statement; ultra-fastCoupled to SQL row update

Recommendation for Production

Combine an atomic conditional SQL UPDATE / Optimistic version lock for the reservation step with an Idempotency Key (reservation_id UUID generated on the checkout screen) enforced via a UNIQUE index on reservations(reservation_id) so network retries never create duplicate bookings!

3. Caching Room Search Without Stale Inventory Disasters

Search traffic is 100× higher than booking traffic:
  • Serve hotel search (GET /v1/hotels/search) from read replicas + Redis Inventory Cache synced asynchronously via Change Data Capture (Debezium + Kafka) from the primary Reservation DB.
  • If a room shows available in Redis from a 500ms stale cache just as someone else grabs the last unit, the final ACID check in the primary DB rejects the checkout cleanly with "Room just sold out"—never risking an inconsistent write!

Share this article

Comments