Katkat

Design a hotel search and booking system

RipplingSoftware Engineer · Onsite

Last 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:

  1. Search: Users can search for hotels by city, date range, and guest count.
  2. Inventory: System must show real-time availability and pricing.
  3. Booking: Users can reserve rooms, ensuring no double-booking occurs.
  4. Management: Hotel owners can update room inventory and pricing.

Non-Functional Requirements:

  1. Scale: Support millions of searches per day and handle high traffic spikes during holidays.
  2. Consistency: Strong consistency is required for the booking process (avoid overbooking).
  3. Latency: Search results should be returned in under 200ms.

Scope of Answer

Provide a high-level design that addresses:

  1. API Design: Define key endpoints for search and booking.
  2. Data Model: Propose a schema strategy for hotels, room types, and bookings. Consider how to handle partitioning/sharding.
  3. Concurrency: Explain how to handle the 'race condition' when two users try to book the last available room simultaneously.
  4. 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?