#68 Inventory Calendars/Range Queries
Hotel Availability Service
Answer "which hotels have rooms on these dates?" for millions of hotels, fast, while availability changes every second.
What is being asked
Design the availability service that hotel search depends on. Each hotel has room types; each room type has a number of rooms per night. A stay of four nights is available only if every night has a free room.
Requirements
Functional
- Given a city and a date range, return hotels and room types available for the whole stay.
- Accept availability and rate updates from hotels and channel managers.
- Support minimum-stay and closed-to-arrival rules.
Non-functional
- Very read-heavy: thousands of queries per second, each covering many hotels.
- Updates must show up in search within seconds.
- The booking path must use the authoritative count, not the search copy.
Design
- The source of truth is a table keyed by
(hotel, room_type, date)with total and booked counts. - Every change is published to a stream (change data capture).
- A search-optimised index stores, per hotel and room type, a compact calendar: for example a bitmap of available nights for the next 365 days.
- "Available for 12–15 March" becomes a bitmap AND across the four nights, which is extremely fast.
Key decisions and trade-offs
- Two copies on purpose. The search index may be a few seconds behind; the booking service always re-checks the database. Showing a room that just sold out is acceptable; selling it twice is not.
- Bitmaps vs rows. One row per night is simple but scanning 30 nights × 5,000 hotels is slow. Bitmaps make range checks cheap but need careful updates.
- Partition by city/region. Most queries are "hotels in one city", so co-locating a city's hotels keeps a search on one shard.
- Rate limits for channel managers, which can send bursts of thousands of updates.
Follow-up questions
- How do you handle a 2-night minimum stay in the bitmap model?
- How would you show "only 2 rooms left"?
- A hotel sends the same update twice, out of order. How do you stay correct?
- How far ahead do you store availability, and why?