Airbnb

Home rental marketplace

Design a marketplace where hosts list homes and guests search by place and dates, book without ever double-booking a night, pay, and review each other.

Overview

A home rental marketplace connects hosts, who list homes, with guests, who search for a place to stay on particular dates. Unlike an online store, the inventory is not a count of identical items: each home on each night is unique, and it can be sold exactly once. Two guests must never both be confirmed for the same night.

That makes the design split cleanly. Search must answer 'what is free near here on these dates for four people?' over millions of listings, quickly, while hosts keep changing prices and calendars. It can be slightly stale, because nothing is sold from a search result. Booking must be exactly right, but it is a small, per-listing workload. The interviewer will test whether you keep the two apart and still make them agree.

Questions to ask first

Before you design anything, agree on the scope. Here is each question, with the answer this design assumes.

  • How many listings, searches and bookings? 7 million listings, 200 million searches and 400,000 bookings a day.
  • How do guests search? By a map area or a place, check-in and check-out dates, the number of guests, and filters.
  • Can a guest book at once? Yes for Instant Book listings. Otherwise the host approves a request.
  • When is money moved? The guest pays when the booking is confirmed, and the host is paid after check-in.
  • Reviews? Both sides review each other after the stay.
  • How fresh must search be? Seconds behind is fine, because booking rechecks everything.

The design at a glance

Guests and hosts reach every service through an API gateway. Behind it, three services split the work. The search service reads a search index that holds a geo grid and one calendar bit per night. The listing service writes hosts' changes, and the booking service sells nights, both into the calendar database of listings and nights. That database is the only place a night is ever sold. The booking service also calls a payments service, which tracks idempotency keys and calls the payment processor.

The two halves are joined by a change stream. Every change in the calendar database flows through it to an indexer, which updates the search index within seconds. So search reads a derived copy that trails the truth a little, and booking writes the truth itself. The sections below take search first, then booking and payment.

What you will be able to do

  • Answer a map-plus-dates search with a geo index, precomputed availability and a final exact check.
  • Keep the search index fresh from a change stream, and say why booking never trusts it.
  • Make double-booking impossible with a database constraint on listing-nights.
  • Design Instant Book and booking requests, including holds that expire.
  • Take payment exactly once and pay hosts later; run double-blind reviews.

Key concepts

  • Geo search
  • Availability calendar
  • Two-stage retrieval
  • Search index freshness
  • Double-booking prevention
  • Booking requests with expiry
  • Idempotent payments
  • Delayed payout
  • Double-blind reviews

Functional requirements

  • Hosts create listings with photos, capacity, price and a calendar
  • Guests search by map area or place, dates and number of guests, with filters
  • Guests see a listing page with its calendar and the total price for their dates
  • Guests book instantly or send a request the host accepts or declines
  • Guests pay at confirmation; hosts are paid after check-in
  • After the stay, guest and host review each other

Non-functional requirements

  • Search returns in under 500 ms at p99 (a target we chose)
  • A night is never confirmed to two guests
  • Search reflects calendar and price changes within seconds
  • A guest is never charged twice for one booking
  • Booking stays available during the busiest travel seasons, at a few times average load

Interview questions

  • How do you prevent double-booking?
  • How does search handle dates as well as location?
  • How do you keep the search index fresh with thousands of updates a second?
  • How does a booking request that needs host approval work?
  • How do you avoid charging a guest twice?
  • When is the guest charged and when is the host paid?
  • How do reviews stay honest?
  • How do you shard the data?

Sign up free to read the full topic

More System Design topics

Start free on Cariara · Coding problems · System design studio