Hotel Reservation System (Airbnb, Booking.com)

Blog / Hotel Reservation System (Airbnb, Booking.com)
Blog hero image

Overview

Introduction

Designing a hotel reservation system is a very popular system design interview question. While it is certainly not the most complex system design interview question, most interviewers will want to see specific problems addressed. Knowing what these problems are and how best to tackle them is critical in the interview setting and is exactly what we're going to cover in this solution.

Requirements

  • Functional Requirements
    • Hotel Management: Hotel Managers should be able to add and remove hotels, as well as add and remove rooms of given room types. They should also be able to update the pricing and inventory of room types to reflect changes in availability or rates.
    • Search and Reservation: Users should be able to search for hotels and rooms using various filters such as location, number of beds, price range, and check-in/check-out dates. The system should display available hotels and room types that match their search criteria. Users should be able to create and cancel reservations as needed.
    • Reservation History: Users should have access to view their past reservations, allowing them to review previous reservations and details.
    • Notifications: Users should receive notifications for important events, such as successful creation of a reservation or cancellation confirmations.
  • Non Functional Requirements
    • Consistency: The system must handle concurrent requests efficiently to ensure that no two customers can book the same room on a particular day, maintaining high data consistency.
    • Low Latency: The platform should provide quick responses to user actions, ensuring a smooth and responsive user experience.

Data Model

This is a basic outline of some of the core tables that could be included in a hotel reservation system data model.

  • Users: Stores information about all users, including hotel managers and customers.
  • Hotels: Contains details about hotels managed by hotel managers.
  • RoomTypes: Defines different types of rooms available in each hotel.
  • Rooms: Represents individual rooms under each room type.
  • RoomPricing: Manages dynamic pricing for room types on specific dates.
    • Composite Primary Key: Combination of room_type_id and date to uniquely identify each pricing entry.
  • RoomInventory: Tracks the number of available rooms for each room type on specific dates.
    • Composite Primary Key: Combination of room_type_id and date to uniquely identify each inventory entry.
  • Reservations: Stores booking details made by users.
  • Notifications: Manages notifications sent to users regarding their reservations.
  • Amenities: Stores a list of possible amenities that a hotel or room type can offer.
  • HotelAmenities: Associates amenities with hotels.
  • RoomTypeAmenities: Associates amenities with specific room types.

API Design

For a hotel booking system we will use a classic RESTful API to interact with the data. RESTful APIs are simple, widely used, stateless, and support caching which make it a good candidate for our system.

Our REST API will comprise of four main endpoints:

  • POST: /api/hotels
    • Description: Allows a hotel manager to add a new hotel to the platform.
    • Params: name, description etc.
  • POST: /api/{hotel_id}/room-types
    • Description: Allows a hotel manager to add a new room type to a hotel.
    • Params: hotel_id, name, description etc.
  • GET: /api/search
    • Description: Allows users to search for hotels and room types based on filters and view available options.
    • Params: location, check_in_date, check_out_date, num_guests, num_beds etc.
  • POST: /api/reservations
    • Description: Allows a user to create a new reservation for a room type.
    • Params: hotel_id, room_type_id, check_in_date, check_out_date

Adding Hotel Flow

  • Admin App
    • Action: The hotel manager (admin user) sends a POST request to the Admin Service API endpoint with hotel and room details, including images and amenities.
    • Data Validation: Client-side validation ensures all required fields are filled and data is in the correct format.
    • Authentication & Authorization: The request includes an authentication token (e.g., JWT) verifying the user's identity and permissions.
  • API Gateway
    • Routing: The request reaches the API Gateway which analyzes the request and routes it to the appropriate microservice, in this case, the Admin Service.
    • Additional Functionality: Performs authentication, authorization, and implements rate limiting. Also handles load balancing by distributing incoming connections and requests to maintain optimal performance.
  • Admin Service
    • Server-Side Data Validation: Ensures that all mandatory fields are present and correctly formatted and validates image files (type, size limits).
    • Image Handling: Extracts images from the request, uploads images to the Object Storage Service (e.g., AWS S3, Azure Blob Storage), and retrieves URLs or keys for the uploaded images. Images uploaded to Object Storage are distributed via a Content Delivery Network. CDN Edge Servers cache the images to reduce latency for end-users.This offloads traffic from the origin server and enhances image load times globally.
    • Message Creation: Prepares a message containing hotel data, room details, amenities, and image URLs. The formatted data is then published to a messaging system like Kafka. This decouples the request-response cycle from heavy processing tasks and promotes scalability. Messages can be partitioned by Hotel ID (or a hash of the Hotel ID) for scalability and ordered processing. Returns a response to the client indicating that the hotel addition request has been received and is being processed.
  • Admin Consumer
    • Background Worker Service: A horizontally scalable service that listens to the Kafka topic and pulls messages from the topic.
    • Database Transaction: Begins a Transaction in the relational database (e.g., PostgreSQL, MySQL) and inserts the data into the appropriate tables (Hotels, RoomTypes, Amenities etc.). Relational databases like PostgreSQL or MySQL provide strong Atomicity, Consistency, Isolation, and Durability guarantees, which are crucial for transactional operations like hotel additions. If successful the transaction is committed.
    • Update Elasticsearch Cluster: Indexes the new hotel and room data into Elasticsearch for search functionality. Given that Elasticsearch does not support ACID transactions in the same way as relational databases we could implement a two-phase commit. While a two-phase commit could theoretically synchronize the database and Elasticsearch, it's impractical due to complexity and performance overhead. Here we are willing to accept eventually consistency as search functionality is not as critical as reserving a room. Therefore, if indexing fails a message can be placed on message queue for further review and retries and the use of idempotency keys would be useful to prevent duplicate processing of the same data.
    • Error Handling: If an error occurs rollback the database transaction, log the error with details for debugging, implement retry logic with exponential backoff, and move the message onto a Dead Letter Queue if retries fail.
  • Notification
    • Notification Queue: Once the hotel is successfully added the Admin Consumer adds a message onto the Notification Queue.
    • Notification Service: Pulls messages off the Queue and notifies the user via the relevant third party providers channel (e.g. Mailjet for email, APNs (Apple Push Notification Service) for iOS, and FCM (Firebase Cloud Messaging) for Android).

Creating Reservation Flow

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet.

Complete Architecture

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet.

Additional Discussion Points

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet.

Master System Design Interviews

Get ready for the exact system design questions top tech companies are asking right now. Read comprehensive editorial write-ups and practice with our AI whiteboard that simulates a real, step-by-step interviewer experience.

See All System Designs →