System Design: Hotel Booking

preview_player
Показать описание
System design (HLD) for a hotel booking service by a FAANG Senior Engineer that has reviewed over 100 design documents. 📚
This video will cover the complete high-level design and data flow diagrams for the software architecture entailed by this common system design interview question.

Common names for this system design interview question:
- Hotel reservation service
- Hotel booking service
- Airbnb

Examples of real world implementations of this:
- Expedia
- Airbnb

Request other problems for me to cover here:

Here's a link to our discord channel where I organize the live discussions every weekend:

#systemdesign #programming #technology
Рекомендации по теме
Комментарии
Автор

NOTES & CORRECTIONS:
---
• I have come to find that this is actually Square's ONLY system design interview question for at least L5 and L6!
• Files:

I've gotten a lot of feedback that the scale I designed for was very unrealistically high (which was kind of the point, because none of the 4-6 system design books that I own actually cover distributed transactions all that well...) AND a viewer has found a phenomenal way to do manual sharding that would avoid having to do distributed transactions at all, so:
• Approach 3 is probably all that you'd ever need for the scale that this problem would usually be presented with
• Approach 4 uses the sharding idea that was found for scaling up writes without adding distributed transactions
• Approach 5 through 8 are completely unnecessary but demonstrate ideas and approaches for handling distributed transactions that I wish was more accessible in the materials that currently exist for system design interviews (I literally have 20 books on system design, and I'm still not happy with what I've been able to find)
• The biggest piece of content that's missing from the infographic of 8 approaches is currently the pros & cons of each approach.

I'd actually like to do a much more cleaned up and thorough recording of this video at some point, and it will be driven off the infographic of 8 different approaches attached above in this comment that's currently a draft.

SDFC
Автор

I used this in an interview for L5 at square, and they told me I failed because my SD was too advanced for the requirements and they didnt think the db datastructure would work well. I guess it really depends on how the interviewer is feeling on the day.

TheChrool
Автор

Really good content, glad you went into the details that a lot of system design seem to skip!

StyleTrick
Автор

Thank you for the video! My brain is stuck on one thing :) I see you would want to use a string for the price so you don't have to worry about overflow depending on the currency, but I think what you lose may be more than you gain. Assuming your database supported a reasonable range of costs (64bit integers would for sure, 32 most likely would unless it's a hotel on the moon :)). It would make more sense to store a common currency (e.g. dollars) and do any conversions per customer? You could store cents instead of dollars if you're concerned with floating point errors.

Using a string would mean you wouldn't be able to do very useful things like ask the database "Give me all rooms which are available and cost < $40". If you store a string then you would be doing a lexicographic comparison and "40" > "200". If you stored a string you would have to pull all available rooms into memory, convert the price to a string and then filter. This would be way more expensive in time, processing power, and bandwidth than pushing the query down to the database.

Storing a string makes more sense to me on the payment side. Depending on the conversion you may have to support fractional cents. But, you also aren't as likely to do as many queries for ranges for payments than you are to query against room cost. I'm curious what others think and thank you again!

DavidBarnett-pf
Автор

Super high quality content! Thanks for sharing. Would be great to see a video on Zookeeper and how exactly it helps with distributed TXs.

blumaukko
Автор

Thanks for the explanation! This was great!

yunaf
Автор

Why have a separate inventory and reservations DB?

LiuLutetium
Автор

first, you don't need to update both inventory and reservation. inventory can be inferred from the reservations. secondly, it's okay for inventory to be out of sync sometimes - the user might see something as available but the booking can fail. that happens occasionally on real websites and it's acceptable.

ZhiminHe
Автор

Quite informative, I willl suggest some minor timestamps for these long form of videos.

aaryanbhagat
Автор

Thanks, buddy,

this helped me a lot with my first ever system design interview. I got an L5 top band offer from Square. Let me know if and how I can buy you a beer!

planschmuh
Автор

Thanks for the great tutorial! I think DynamoDB supports ACID with Transactions operations which can perfectly handle the all-or-nothing.

kinako.omochi-
Автор

Extremely good content. I think an improvement area could be deep diving into actual reservation with some state management - like reserved, blocked, booked, canceled etc.

boombasach
Автор

In some system design videos, I see multiple services talking to a common DB which is usually a big NO NO going by microservices best practices. Any opinions on that?

abhishekdhillon
Автор

Why are the inventory table and reservations table on different databases? If they were on the same database could we avoid the need to do 2PC? Is it because of the sizes of the tables?

alicezhang
Автор

For Inventory DB, why not use some unique Id as PK and set it as UUID? Why date in inventory DB, is it not better to have a from and to fields in reservation DB? Isn't it better to check if room is available by checking the dates you want reservation for with the reservations inside Reservation DB? Btw, great video, learned some new things, and to what details I need to pay attention. Thank you!

stefancovic
Автор

For the inventoryDb, how many different date entries does a single room have? Does it have one row for each date for the next two years?

John-nhoJ
Автор

Just one consideration: page view != reads as much as reservations != writes. A reservation would include a few reads along with some upserts.

vhmolinar
Автор

20:54 I don't understand how paxos or Raft consensus algorithms fit into the picture here? In this scenario we have to use 2 phase commit because we are writing different data to 2 entirely different databases, it's not like consensus algorithm which is used for transaction writes among equivalent nodes for the same database, in those cases, paxos/raft achieve even better reliability but functionally equivalent to 2PC, but not in this heterogenous distributed transaction case, right? Consensus algorithm relies on tolerance of partial failure, which is not the case here --- all participants have to succeed or fail together.

Also after you mentioned outsourcing to those consensus algorithms, you then mentioned "outsourcing to Zookeeper", my understanding though now you're just coming back to 2PC but just saying to make Zookeeper to do the coordinator job for you, so it doesn't have anything to do with paxos/raft any more, is that right?

ziggyzhang
Автор

Instead of trying to do atomic transactions across different database nodes, could we instead shard the data by a shared id? For example sharding by roomTypeId. That way the Inventory and Reservations can be stored on the same database node and we wouldn't need to use ZooKeeper to coordinate transactions across nodes for booking rooms.

simonhuang
Автор

What are the resources without links? Grokking and Alex Xu?

nikolai.x