Design a home rental marketplace like Airbnb
hard 60 minGuests search homes by place and dates, hold some nights, pay, and stay.
Video lesson · Chapter 1 of 5
A Paris apartment can be nearby and still be unavailable
Theory
Read or listen first. About 2 min.
What it is
A home rental marketplace lets hosts offer a room or a home for chosen nights, and lets guests find, book and pay for a stay. The service is in the middle: it keeps the calendar, takes the money and passes it on.
What is sold is not a home but a night in a home. Each night exists once. A stay is several nights in a row that must all be free together, and all be taken together.
Why it exists
Hosts and guests do not know each other. The service gives them one trusted calendar, one price, one payment and one place to settle a problem.
For a designer it is a lesson in two opposite loads. Thousands of people look each second and can live with a list that is a few seconds old. A few people book each second, and for them nothing but the truth will do.
A short history
1995
Vrbo starts in Colorado: holiday homes listed online by their owners.
2008
Airbnb is founded in San Francisco.
September 2009
RFC 5545 defines the iCalendar format that hosts use to share free and busy dates between sites.
September 2012
PostgreSQL 9.2 adds range types, so a constraint can forbid two overlapping stays.
October 2018
Airbnb engineers publish a paper about deep learning in their search ranking.
Words to know
- Night
- The unit of sale: one listing on one local date.
- Half-open stay
- Check-in night included, check-out date not. March 15 to 20 is five nights, the 15th to the 19th.
- Hold
- Nights reserved for one guest for a short time while they pay.
- Availability bitmap
- One bit per night: 1 is free, 0 is taken.
- Candidate
- A listing that might fit, before dates, price and ranking are checked.
- Ledger
- A list of money movements that is only added to. Every movement has two sides that sum to zero.
- Outbox
- A table of events written in the same transaction as the data, then published.
Solve it like an interview
New to it? Start with Approach. Revising? Go straight to the mock.
- 1ApproachWhat this question tests, where it gets hard, and how to spend the time.
- 2ScopeAsk what changes the design, then commit to a short list.
- 3NumbersWork out a number when the answer changes what you build.
- 4API and dataThe contract first, then the data that serves it.
- 5DesignStart with the smallest system that works. Change it only when something breaks.
- 6Deep divesCompare the options before you open them, then say which you would pick.
- 7Explain your choicesAnswer first. Then compare your reasoning.
- 8By levelThe same question is judged differently for mid, senior and staff.
- 9MockAnswer against the clock, then score yourself.
How it works
Step through the idea, or press Play.
Search. Place, dates and guests: candidates from the index, free nights from bitmaps
Understand it
The board helps you choose a shed. Only the door can lend it.
Scope
What are we building?
A service where hosts list homes, guests search by place, dates and number of guests, and a guest can book and pay. Hosts are paid after the stay begins. Both sides can write to each other and review each other.
Search
Place, dates, guests and filters, ranked, in under 200 ms.
Book
Hold nights, pay, confirm. One night is never sold twice.
Pay
Take money from the guest now, pay the host later, refund by rule.
List
Photos, house rules, prices, and a calendar shared with other sites.
Similar applications
| Product | The twist |
|---|---|
| Vrbo | Whole homes |
| Booking.com | Hotels: many equal rooms, so a count can replace a calendar for each room |
| Hotels.com | Hotel rooms with a reward scheme |
| Expedia | Flight, hotel and car in one trip: several suppliers must all agree |
| TripAdvisor | Reviews first, booking second |
| Agoda | Hotels and homes, strong in Asia |
The finished system
Where the design ends up
This is the last version. Design begins with one service and one database, and names the break that forces each box.
The whole system
Where to read what
| Question | Interview tab | Concept page that owns the idea |
|---|---|---|
| What must it do? | Scope | Scoping |
| How big is it? | Numbers | Numbers that decide |
| What is the interface? | API and data | Idempotency, pagination |
| How does it grow? | Design | Change data capture, CQRS |
| What is hard? | Deep dives | Concurrency control, full-text search |
| How does money move? | Deep dives | Digital wallet, saga |
| Can I do it aloud? | Mock | 45 minutes |
Summary
The whole topic in one minute.
Looking and booking are two systems. Search uses an index by place plus a bitmap of free nights, both slightly behind. Booking takes the nights in one database transaction, and that transaction is the only thing that decides.
Money follows a fixed path: hold the nights, mark the booking as paying, charge once with an idempotency key, confirm, record both sides in a ledger, and pay the host a day after check-in. Anything unclear is asked again, never guessed.
- Sell nights, not date ranges: one row for each listing and night.
- A stay is all or nothing, so take its nights in one transaction.
- Bookings are few (17 a second at peak). The problem is correctness, not write volume.
- 365 nights fit in 46 bytes, so all availability fits in one machine's memory.
- A hold has an expiry. A payment in progress is not allowed to expire silently.
- Charge once, record both sides, pay the host later, and compare with the provider every day.