System Design/Architecture of Airbnb

Do not miss this exclusive book on Binary Tree Problems. Get it now for free.

In this article at OpenGenus, we will try to understand the basics of system design and architecture of a hotel renting platform namely Airbnb and do a high level design of Airbnb.

Table Of Contents:

  • What is System Design?
  • Functional requirements.
  • Non-Functional requirements.
  • Designing.
  • Thinking about components.
  • Design.
  • Database Design.
  • Explanation.
  • Disclaimer.

Let's start with basics.

What is System Design?

System is the collection of components that are working together to solve a problem at hand for the users. The end goal of a system is to fulfill the requirements of the users.

System Design is the art of designing systems based on requirements even though the basic building blocks-the components, which are well known like servers, databases, caches, messaging queues. A system design can vary with the other based on many functional and non-functional factors. For an engineer to design a system, he has to have understanding on relevant technologies, should be able to dissect the requirements and think about possible complexities that may arise when using a component.

Functional requirements are the requirements which are shared by the client. These are the features which needs to included in the system as we plan it. The intended audience of the particular system has to be known.

Non-Functional requirements are the those set of concepts which aren't mentioned by the clients but is needed by the system to deliver it to the intended audience. It's the quality attributes of a software system. It can include concepts like availability, performance, latency etc.

Depending on the type of system the clients want it's actually much easier to define the functional requirements than non functional requirements. Testing for both should be done to check the features and the quality of the architecture before going into design, it's a crucial step as it helps not to waste any resources.

For an engineer to design a system the tradeoffs of a particular system should be know. If a technology is used it should be in such a way that it aids to the final requirements demanded by the clients.

Enough with the introductions, let's dive right in.

Airbnb is a online marketplace for homestays. They act as brokers between the owners and the tenants(lessor and lesse) which is for a very short duration. Now, Airbnb is quite popular in almost all the countries. If a system needs to be designed it should be able to cater to the needs of hotels and users alike.

Functional requirements

As a hotel you need,

  • yourself to be onboarded easily.
  • Able to Update the bookings.
  • View Bookings

As a user one needs,

  • Able to search hotels.
  • Book hotels.
  • View Bookings.

Because this is a very basic introductory system design article, we will not take other requirements into consideration. If not, we would like to add data analytics as a requirement for the hotel.

Non Functional requirements

  • For a system of this quality our basic needs would be low latency for users and hotels to access.

  • The system should be readily available without single point of failure.

  • There should be consistency for users and hotels.

  • Let's discuss about scale,

    We will assume we are building this to serve to around 100 Million users and there are around 17.5 million rooms( according to a quick google search).
    Now, obviously we exaggerated the number of users who are trying to book.

Designing

  • If this is the scale, our primary requirement would be availability
    then consistency and then latency in order.
  • To Ensure availability, we need a cluster of databases where there is a master and slave relation.
  • Consistency in case of availability is so-so, one can't get an immediate consistency but rather eventual consistency in a sytem.
  • Because we are emphasised on availability and consistency there would be an eventual tradeoff of latency. To complete a particular task it would take a lot of time.

Thinking about components

  • From a hotel's standpoint we need a room management, booking management and view booking services.
  • From a user's view we need search, booking and payment services.

Room Management service: This would aid the hotels to be easily onboarded onto the platform. This services ensures that the hotels are easily able to update the status of their rooms.

Booking Management service: This would aid hotels in marking the rooms as booked or blocked based on the successful or unsuccessful completion of payments.

View Booking service: To aid the recepionists and the managers, bookings of the respective rooms is made available to the hotel authorities. To help users, the same is given to the users.

Search service: This helps the user to search for a room based on his search criteria.

Booking service: This would help in communication between users and hotels and acting as a flag maker, blocking rooms when there is an ongoing transaction and also if the payment is complete send the required information to the messaging queue.

Payment service: As the name suggests, it helps user to easily pay for a room by integrating a payment gateway.

Design

Explanation:

Load balancers are used to maintain the rate at which requests are being sent. This helps to the system to maintain without crashing. Sometimes due to overloaded requests a system might fail.

Messaging queue helps in communication between several components in the system, Its helps to aid the information about whether a room is booked or not and block it by letting the search consumer know it.

MySQL clusters are used because the data which needs to be added to the database needs to queried and they can be complex at scale. We can choose Nosql but the data demands there should be structure. We need ACID properties, so we are going with SQL cluster. We are horizontally scaling as there should be no single point failure with master and slave databases.

DynamoDB- We are using Amazon's DynamoDB to store the data from the search consumer and perform frequent reads. We are using it because scaling is done automatically horizontally as an when required by amazon. To enable fuzzy search for users we are configuring amazon cloud search.

MongoDB- The successful bookings and their related information can be easily stored in a NoSQL database. It doesn't demand any structure to be followed. This coupled with Redis gives a combo which is irresistable. The Redis helps in caching frequent queries to the database thereby saving a lot of work put on the DB. Because of it's scaling abilities MongoDB is a good option to consider.

Database Design of Airbnb

We are using two types of databases- SQL and NOSQL to improve the efficiency of the system at hand.

The SQL database consists of the following major tables and have represented them:

  • hotel
  • rooms
  • room_facilities
  • facilities
  • area
  • available_rooms

The main attributes of all the tables are below

hotel table consists of:

  • id (primary key)
  • name
  • area_id(foreign key)
  • description
  • images
  • status

rooms table consists of:

  • id (primary key)
  • hotel_id(foreign key)
  • type
  • status
  • quantity
  • price

rooms facilities table consists of:

  • id (primary key)
  • room_id (foreign key)
  • f_id (foreign key)

facilities table consists of:

  • f_id (primary key)
  • name

area table consists of:

  • area_id
  • city
  • state
  • country
  • zip

available_rooms table consists of:

  • room_id
  • initial_qty
  • remaining

Brief:

Each hotel in a given country can have many rooms,so we have a one to many relationship.
Every hotel can have many facilities- one to many relationship.
An area can have many hotels- one to many relationship.
A facility can be present in many rooms - many to many relationship.
A room can have many facilities- one to many relationship.

The NOSQL database has the following collections:

Customer collection consists of:

  • Customer_id
  • phone
  • address
  • country

Booked collection which has the following information:

  • Booking_id
  • Hotel_id
  • Room_id
  • type
  • quantity
  • area
  • country

Brief:

Every customer in the system should be stored, we store it in a customer collection with the important details from them. The booked collection is essential to track the bookings done by a particular customer. The booking collection stores a reference of customer id so that there is a link for each booking to a customer.

Disclaimer:

The above system is a polyglot which I as a beginner thought and finalized. I would have no problem with anyone reading it agreeing or disagreeing with it. If you can improve the system, please send the necessary suggestions. I am still learning.

Sign up for FREE 3 months of Amazon Music. YOU MUST NOT MISS.