# For hotels
POST /hotel/ -> Hotel-ID
Request: Hotel-Data
Hotel-Data
Room-Groups
# For hotels
PUT /hotel/:hotel-ID
Request: Hotel-Data
GET /hotel/:hotel-ID -> Hotel-Data
POST /search/hotels?page=xxx -> HotelResult
Request: HotelQueryParams
HotelQueryParams
Clause
HotelResult
GET hotel/:hotel-ID/occupancy?From-Date=x&To-Date=y -> HotelOccupancy
HotelOccupancy:
Occupancy-Room-Groups:
POST /hotel/:hotel-ID/book -> BookingID
Request:
POST /hotel/:hotel-ID/cancel -> True/False
Request:
# For users
GET /hotel/bookings -> UserBooking[]
UserBooking
# For hotels
GET /hotel/:hotel-ID/bookings -> HotelBooking[]
HotelBooking
Use Postgres
Hotel:
RoomRate
Room
User
Booking
We have two services behind the load balancer . one is the hotel service which is used to edit create and change the hotel metadata corresponding to the hotel and room rate objects. The other is the hotel service used to do the bookings.
The room objects are used to create locks in post progress to prevent double booking. There is one lock for every room for every day. We will always acquire these locks in order from earliest day to later day to prevent dead locks.
In addition, we also want to give people a few minutes to book rooms. To achieve this, we have a redis booking cash. We create a key representing the room and date with the TTL when a user starts a booking flow. When a user confirms they want to book we extend the TTL for five minutes before we acquire the lock in postgres.
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...
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...
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?