SDE & MLE Prep

Hotel Reservation (Booking / Airbnb)

Requirements: search availability, reserve rooms without double booking, payment, cancellation; moderate QPS but high correctness; allow some overbooking policy.

search -> search svc -> availability cache / search index (eventually consistent)
reserve -> reservation svc -> SQL: room_type_inventory(hotel, room_type, date, total, reserved)
              BEGIN; SELECT ... FOR UPDATE  (or UPDATE ... SET reserved = reserved + 1
                                             WHERE reserved < total * 1.1)   -- 10% overbooking
              INSERT reservation (idempotency key); COMMIT
           -> payment svc -> confirm / timeout releases inventory

Deep dives: inventory is per room type per date (not per room); concurrency via row locks, optimistic locking (version column) or conditional updates; idempotency key for the reserve call (users double-click); sharding by hotel_id; availability served from caches with short TTL while the final check hits the DB; holds with expiry for unpaid bookings.