Design AirBnB or a Hotel Booking System

Design AirBnB or a Hotel Booking System

Requirements

Guests

  • search rooms by locations, dates, and number of guests

  • get room details(like picture, name, review, address, etc) and prices

  • pay and book room from inventory by date and by room_id

    • checkout as a guest

    • user is logged in already

  • notification via Email and mobile push notification

Hotel or Rental Admin

  • manage room inventory and help the guest to check-in and check out

  • housekeeper: clean up rooms routinely


High-level architecture


Detailed Design

Data Structure for User, Room and Booking

Ref: Designing a Data Model for a Hotel Room Booking System

  • The basic tables are: reservation, guest and room.

  • use status to represent the status of a room: EMPTY, RESERVED


How to find available rooms?

Method 1: By location

Method 2: By room metadata

  • apply filters or search conditions when query the database

Method 3: By data-in and data-out availability

  • option 1(recommended): for each room_id, create an entry for an occupied day. It will be easier to query unavailable slots by dates

  • option 2: for each room_id, check all occupied_room from today.

    • transform the data structure to an array of occupied days

    • keep searching until got the available slots

    • this is time-consuming, so we can build the availability index


External Hotel Supplier

  • provide webhook callback APIs to external vendors to update status in the internal system


Payment

Ref: Stripe Idempotency

  • retry with idempotency to improve the success rate of the external calls and ensure no duplicate orders

Bookkeeping


Notification

The notification system is essentially a delayer scheduler (priority queue + subscriber) plus API integrations.

  • For example, a daily cronjob will query the database for notifications to be sent out today and put them into the priority queue by date.

  • The subscriber will get the earliest ones from the priority queue and send out if reaching the expected timestamp.

  • Otherwise, put the task back to the queue and sleep to make the CPU idle for other work, which can be interrupted if there are new alerts added for today.

Last updated