CSE Roadmap

Core tier · about 5 hours · 8 parts

Part 3 of 8 · 2 min read

Design

Microservices and tables.

APIs (simplified). Hotel and room info: get, add, update, delete. For reservations: look up a reservation, make one (with the hotel, room type, dates and a reservation id), and cancel one.

Services. The book uses microservices (Level 7):

  • Hotel service: hotel and room details.
  • Rate service: prices for each room type and day.
  • Reservation service: takes bookings and tracks inventory.
  • Payment service: takes the payment (Level 12).
  • Hotel management service: for staff, to edit hotels and rooms.

Data. The data is relational: hotels, room types, rooms, guests and reservations are linked, and money is involved. A relational database with ACID transactions (Level 5) is a good fit, because it keeps application code simpler.

The key table is the inventory:

Column Meaning
hotel_id, room_type_id, date Together the primary key
total_inventory Rooms of this type, minus those taken out of service
total_reserved Rooms already booked for this date

There is one row for each room type and date. A booking for several nights changes several rows. A reservation table holds the reservation id, hotel, room type, dates, guest, status and the number of rooms. The status moves through states such as pending, paid, refunded, canceled or rejected.

Checking availability. Look up the rows for the dates and test, for each row:

total_reserved + rooms_wanted  <=  110% of total_inventory

The 110% is the overbooking rule. If the test passes for every night, add the rooms to total_reserved.

A worked example (made up). A room type has total_inventory 100 and total_reserved 108 for a night. A request for 2 rooms: 108 + 2 = 110, which is at most 110, so it is allowed. A request for 3: 111 is over 110, so it is refused.

Inventory row

An inventory row records, for one room type on one date, how many rooms exist and how many are already reserved.

Example: hotel 7, room type "double", 14 March: total 100, reserved 98.

Check yourself: 1. Why one inventory row per date? 2. What does the 110% test do? 3. Why is a relational database chosen?