List functional requirements for the system (Ask the chat bot for hints if stuck.)...
List non-functional requirements for the system...
Estimate the scale of the system you are going to design...
Max number of users browsing or viewing rooms per second = 10K
Max number of users viewing a room per second = 5K
Max number of users trying to book a room per second = 1K
Reads are much more than writes so this is a read-heavy system.
Total number of hotels in the system = 1K
Total number of rooms maintained in the system = 50K
Given that the data and number of concurrent users is not very high, an SQL Database like MySQL or Postgres will be suitable. SQL DB also provides transaction support and ACID properties which meet our requirements.
Define what APIs are expected from the system...
GET https://
Returns array of JSON responses
GET https://
POST https://
Response type: 201 (success) with reservation id or
40x(error) or 50x(error)
DELETE https://reservation?id=x
Response type 201 (success) or 40x(error) or 50x(error)
Defining the system data model early on will clarify how data will flow among different components of the system. Also you could draw an ER diagram using the diagramming tool to enhance your design...
Hotels
======
HotelId
Name
Location
Address
Rating
RoomType
=========
Type -- Primary Key
HotelId -- Foreign Key
Name
NumOccupants
TotalRooms
FeatureA
FeatureB
...
Rate
======
Date --- Primary Key
RoomType --- Primary Key
HotelId
Rate
Rooms
========
RoomId --- Primary Key
HotelId
Type
Status (InMarket/OffMarket)
Number
Location
RoomTypeAvailability (used for conflict detection in concurrent booking)
======================================================
RoomType --- Primary Key
Date --- Primary Key
NumAvailable (unreserved) --- Primary Key
HotelId --- Foreign Key
Reservation
==========
ReservationId ---- Primary Key
Name
RoomType
HotelId. ----- Foreign Key
NumGuests
Start Date
End Date
Status (complete/pending/canceled)
Payment
========
PaymentId. ---- Primary Key
ReservationId --- Foreign Key
Amount
Status
Notes
You should identify enough components that are needed to solve the actual problem from end to end. Also remember to draw a block diagram using the diagramming tool to augment your design. If you are unfamiliar with the tool, you can simply describe your design to the chat bot and ask it to generate a starter diagram for you to modify...
External User: End-users which use the booking system for viewing rooms, booking, cancellation, feedback etc.
Admin User: Internal Hotel Mgmt Staff has access to certain APIs for adding/removing a hotel, adding/removing rooms, rates of rooms etc.
Hotel Data: Aggregator which accepts rooms and other data from hotels. The booking system has several hotels as external partners and it can show/book rooms for these hotels.
User Mgmt: User sign up, sign-in, login etc.
Rate: Rates of rooms are decided by the Rate Service. The rates can be changed dynamically based on peak season, location etc.
Rooms: Management of rooms and Rooms table
Reservation: Room reservation, booking and cancellation.
Payment: Accepts payments for booking. It interfaces with an external Payment Service Provider(PSP) which does the actual transaction.
Feedback/Rating: Takes user feedback or rating for a hotel, room etc.
Recommendation: Recommends rooms, hotels and destinations based on past bookings and popular reviews. Can use Clustering Algorithms or Collaborative Algorithms for recommendation.
Cache: Frequently used and static data can be in a cache implemented in Redis or a similar technology. For example, Rate information for the next 2 months can be in the cache.
Notification Service: Used to notify users of rate changes for a room, upcoming and successful reservations etc. Also notifies individual hotels about new bookings and cancellations.
These services are stateless and can be deployed as microservices to support higher scale.
Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...
User searches for rooms based on location, dates and num guests
=================================================
The booking system performs the following DB queries:
View a given room type
==================
Make a reservation
================
Concurrency in booking the same room should not lead to data inconsistency. To avoid this, the RoomTypeAvailability table is used.
update RoomTypeAvailability set numAvailable = numAvailable-1 where roomType = t && date = d
Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...
When a booking is done, this table is updated as follows for each date:
update RoomTypeAvailability set numAvailable = numAvailable-1 where roomType = t && date = d
As numAvailable is a primary key, concurrent updates to the table will not be allowed.
Atomically, the Reservation table is also updated in the same transaction.
Explain any trade offs you have made and why you made certain tech choices...
Try to discuss as many failure scenarios/bottlenecks as possible.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?