Design a hotel search and booking system
RipplingSoftware Engineer · OnsiteLast updated
This question tests the ability to design a distributed, high-concurrency reservation system that handles inventory management, consistency, and search efficiency.
System Design: Hotel Search and Booking Platform
Design a global hotel booking system (similar to Expedia or Booking.com) that allows users to search for hotels based on location, dates, and amenities, and securely book rooms.
Requirements
Functional Requirements:
- Search: Users can search for hotels by city, date range, and guest count.
- Inventory: System must show real-time availability and pricing.
- Booking: Users can reserve rooms, ensuring no double-booking occurs.
- Management: Hotel owners can update room inventory and pricing.
Non-Functional Requirements:
- Scale: Support millions of searches per day and handle high traffic spikes during holidays.
- Consistency: Strong consistency is required for the booking process (avoid overbooking).
- Latency: Search results should be returned in under 200ms.
Scope of Answer
Provide a high-level design that addresses:
- API Design: Define key endpoints for search and booking.
- Data Model: Propose a schema strategy for hotels, room types, and bookings. Consider how to handle partitioning/sharding.
- Concurrency: Explain how to handle the 'race condition' when two users try to book the last available room simultaneously.
- Architecture: Describe the services (e.g., Search Service, Booking Service, Inventory Service) and data storage choices (SQL vs. NoSQL, caching strategies).
Constraints
Assume a read-heavy workload (100:1 ratio of search to booking). Data should be globally accessible but localized for low latency.
Hints
Hint 1
Consider using an inverted index or a specialized search engine like Elasticsearch for the search functionality to meet latency requirements.
Hint 2
For the booking flow, discuss the trade-offs between pessimistic locking (database level) and optimistic locking (versioning) when managing inventory.
Hint 3
Think about how to handle inventory updates from third-party hotel systems, which may involve asynchronous communication or webhooks.
Follow-up questions
- How would you handle a distributed transaction if the booking requires payment processing through a third-party gateway?
- If you needed to cache search results, how would you manage cache invalidation when room prices change frequently?
- How would you modify the system to handle 'flash sales' where millions of users try to book rooms at the exact same time?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.