"Design Airbnb" has an easy first half and a trap in the second. Search by place is a familiar geo-search problem. The trap is that a guest does not search for a place, they search for a place on specific dates, and whether a home is free on those dates lives in a calendar that changes whenever anyone books.
The interviewer is checking whether you notice that a search result is only useful if it is available, and that availability does not fit neatly in a search index. We will keep this question distinct from its neighbors: the nearby-search mechanics are in Design Yelp, and the concurrency of selling the last room is in Design a Hotel Reservation System. Here the focus is searching listings against availability calendars at scale.
Background on indexes lives in search systems and spatial indexing.
Clarify the requirements
Functional requirements:
- Guests search by destination, check-in and check-out dates, number of guests, and filters (price, type, amenities).
- Search results show listings that are available for those dates, with prices.
- A listing page shows details, photos, reviews and a live calendar.
- A guest books a listing for a date range.
- Hosts create listings and manage their calendar (block dates, set prices).
Out of scope, said aloud: payments (see Design a Payment System), messaging between host and guest, reviews, trust and safety, photos pipeline.
Non-functional requirements: these shape the design.
- Search must be fast and filtered by availability. Showing a home that turns out to be booked is the worst experience in the product.
- Search can be slightly stale, booking must not be. A calendar a few seconds old is fine in a result list. Selling the same nights twice is not, so the booking write is checked against authoritative data.
- A listing is a single unit. Unlike a hotel with 200 identical rooms, one home can be booked once per night. That simplifies concurrency and makes the calendar the unit of truth.
- Hosts' edits show up soon. Blocking dates should stop appearing in search within seconds to a minute.
Estimate the scale
Assume 5 million listings and 20 million daily users who each run 5 searches a day. Assume 500,000 bookings a day.
Search: 20M × 5 = 100M a day ÷ 86,400 ≈ 1,160 searches per second, with a peak of about 3,500 per second.
Bookings: 500,000 ÷ 86,400 ≈ 5.8 per second. Booking is a tiny write load.
Calendar size: a listing has a night for each of the next 365 days: 5M × 365 ≈ 1.83 billion listing-nights. Stored as one row of about 50 bytes per night, that is roughly 91 GB. Stored as a bitmap with one bit per night, one listing's year is 365 bits ≈ 46 bytes, so 5M × 46 B ≈ 230 MB, which is small enough to hold in every search node's memory.
Search index: a listing document of 2 KB (location, filters, rating, price, plus the bitmap) × 5M ≈ 10 GB.
Booking records: 500,000 × 2 KB = 1 GB a day, about 1.8 TB over five years.
"Bookings are 6 a second, so the booking path is not a throughput problem. The search path is 3,500 a second and the availability of 5 million listings fits in 230 MB as bitmaps. That tells me availability can live inside the search index, if I accept staleness and double-check at booking time."
The capacity estimator reproduces the rates and the booking storage.
API and data model
GET /v1/search?place=&checkIn=&checkOut=&guests=&priceMax=&filters=&cursor=
-> { results[{ listingId, price, ... }], nextCursor }
GET /v1/listings/{id}?checkIn=&checkOut= -> details, price quote, calendar
POST /v1/bookings { listingId, checkIn, checkOut, guests } (Idempotency-Key header)
PUT /v1/listings/{id}/calendar { dates[], status, price? }listings (id PK, host_id, location, attributes, base_price)
calendar (listing_id PK, night SK, status: open|blocked|booked, price, booking_id?)
bookings (id PK, listing_id, guest_id, check_in, check_out, status, total)
index doc { id, location, cell_id, filters..., price, open_nights: bitmap(365) }The calendar row per night is the source of truth, and open_nights is a derived summary the index carries. A search checks the summary, a booking checks the rows.
High-level design
The slice worth running is search: a load balancer, a stateless search API, a search index of listings and a calendar database that answers the authoritative availability question.
- Clients reach the search API through a load balancer.
- The API queries the listing index for candidates, then confirms their dates against the calendar store.
Describe this diagram
Components
- clients (Client)
- lb (Load balancer)
- search api (Service)
- listing index (Search cluster (Elasticsearch))
- calendar store (PostgreSQL)
Connections
- clients sends to lb
- lb sends to search api
- search api sends to listing index
- search api sends to calendar store
Run it, then try raising the load and compare the index with the calendar store. The calendar lookups are the second step and the likely cost.
The read path: the API geocodes the destination to a bounding box or map viewport, queries the index for listings in that area that match the filters and whose availability bitmap is open for all nights in the range, ranks them, and returns a page. The top results may then be checked against the calendar rows before display.
The write path: a booking or a host edit writes the calendar rows in the database (conditional, below), then a change feed updates the listing's bitmap in the index within seconds.
The interesting problem: filtering by dates
A guest wants a home in Lisbon from the 10th to the 14th. How does the search honor the dates?
Approach A: search first, then check each calendar
Find the 2,000 listings in Lisbon from the index, then query the calendar database for each to see if the dates are free.
Good: the calendar stays the only source of truth, and the index holds no availability.
Bad: it asks 2,000 questions to show 20 results. At 3,500 searches a second that is millions of calendar lookups a second, and most of them return "not available" for popular dates. Pagination makes it worse, since each next page needs more checks.
Approach B: put availability in the index
Store each listing's open nights in its index document, as one document per listing with a bitmap or a list of available dates. The query then filters on "all nights from the 10th to the 14th are open" along with location and the other filters.
Good: one query returns only available listings, and pagination is exact. The data is small, as we saw: 230 MB for every listing's year.
Bad: the index lags the calendar, so there are windows where a result is shown that was just booked. Every booking and host edit also re-indexes a document.
Approach C: index for candidates, calendar for confirmation
Use B for the bulk filter, then verify the top page of results against the calendar before the page is returned or when the guest opens a listing.
Good: fast search with a final correct check on only about 20 listings, and stale index entries are caught before the guest sees them.
Bad: a verified page may have fewer than 20 results after removing booked listings, so the API must fetch a few extra.
The recommended answer is C. State the principle: the index is allowed to be wrong, the booking write is not. A stale search result costs one disappointed click, while a double booking costs a guest their trip. The authoritative check always happens at booking, whatever the search showed.
Diagram, as text
- Guest searches place and dates leads to Index: location, filters, open nights
- Index: location, filters, open nights leads to Verify top results against calendar rows
- Verify top results against calendar rows leads to Result page
- Result page leads to Guest books: conditional write on calendar rows
- Guest books: conditional write on calendar rows leads to Change feed updates index bitmap
- Change feed updates index bitmap leads to Index: location, filters, open nights
The second decision: how to store and update the calendar
The authoritative calendar needs a model, and the choice affects booking correctness.
- One row per listing per night: simple. A booking for four nights updates four rows in one transaction, each with a condition that its
statusisopen. If any fails, nothing commits. 91 GB is easily handled. Hosts can price each night. - One row per booked range: compact (one row per booking), but "is this range free" becomes a range-overlap query. Some databases enforce non-overlap directly with an exclusion constraint on a date range, which gives you the correctness for free in a single table.
- A bitmap per listing: the smallest form and ideal for the index, but a poor source of truth because per-night prices and booking ids do not fit.
The recommended split: rows per night in the database as the truth, a bitmap per listing in the index as the summary. To book, use a single transaction:
UPDATE calendar SET status = 'booked', booking_id = ?
WHERE listing_id = ? AND night BETWEEN ? AND ? AND status = 'open';
-- if the number of rows updated is not the number of nights, roll backThe conditional update is the whole concurrency story for a single-unit listing, the same atomic claim used elsewhere in this course. Two guests booking overlapping dates race on the same rows, one commits and the other sees fewer rows updated and gets "no longer available". Pair it with an idempotency key so a retried request cannot create two bookings. The harder case of many identical units is the hotel design.
Partitioning: shard the calendar by listing_id. Every booking touches one listing, so a transaction stays on one shard, and a hot city spreads across many listings.
Bottlenecks and failures
Hot destinations. New Year's Eve in a popular city sends a flood of searches to the same area. Cache result pages for the common query shape (place, dates, default filters) for a short time, and let a stale cache entry get corrected by the verify step.
Index lag. If the change feed backs up, search shows stale availability. Alert on lag, and rely on the confirmation check so the harm is limited to wasted clicks.
Calendar database down. Search can still return candidates from the index, flagged as unverified, but booking must fail clearly. Never accept a booking without the authoritative write.
Big hosts. A property manager with thousands of listings may update their whole calendar at once. Batch the writes, rate-limit per host and update the index in bulk, not one document per night.
Map searches. Panning a map fires many searches. Debounce on the client, and let the cell-based cache absorb repeated nearby viewports.
Fake or duplicate listings and scraping. Rate-limit search per client, and require verification of hosts. Treat the calendar as a target for abuse, since blocking dates on a competitor's listing is possible only with a stolen account.
Trade-offs to name aloud
- Availability in the index: fast filtered search, in exchange for an eventually consistent copy and re-indexing on every booking.
- Verify the top page: a few extra calendar reads per search, in exchange for never showing a booked listing as free for long.
- Rows per night over ranges: more rows and room for per-night prices, in exchange for simple conditional updates.
- Sharding by listing: transactions stay on one shard, but a very large host's calendar sits on one node.
What interviewers listen for
- A working answer: a listing index with geo and filters, a calendar table, and a booking that checks the calendar.
- A strong answer: sees that filtering by dates breaks "search then check each", proposes availability in the index as a derived summary, and keeps the authoritative check at booking time.
- A standout answer: sizes the calendar to show bitmaps fit in memory, uses a conditional multi-row update with an idempotency key, explains the index lag window and why it is safe, and separates this design from hotel-style inventory.
Check your understanding
Common mistakes
Ignoring dates in the search design. A destination-only search returns places a guest cannot book. Dates are part of the query, so availability is part of the index.
Making the index the source of truth. The index lags and can be rebuilt. The calendar rows decide whether a booking succeeds.
Checking then booking in two steps. Read-then-write leaves a race. Use a conditional update inside one transaction.
Copying the hotel design. A home has one unit per night. Reaching for room-type counters and overbooking policies here adds complexity the problem does not have.
Forgetting host-driven writes. A host blocking a month changes 30 rows, and a manager with many listings changes thousands. Batch these and re-index in bulk.
Treating price as static. Prices vary by night, season and length of stay. Store per-night prices and quote the total from the calendar rows at booking time.
Practice
A host reports that her listing was shown as available in search for a night that she had blocked ten minutes ago. How do you investigate, and what do you change?
Write your own answer first, on paper or in a note. Then compare.
Show a hint
Follow the change from the host's edit to the index and decide whether the lag is a bug or by design.
Show a strong answer
Trace the edit. The block wrote calendar rows, then a change feed should update the listing's bitmap. Check each hop's timestamp: the row commit, the feed consumption, the bulk index request and the index refresh. Ten minutes means the feed or the refresh is badly delayed.
Separate harm from the lag. Even with a stale index, a guest could not have booked the blocked night, because the booking write checks the rows. The harm is a wasted click and a confused host, not a double booking. Say that.
Fix and monitor. Alert when feed lag exceeds a threshold such as a minute. Use the verify step for the top results, so even a stale index entry is caught before display. Tell hosts in the UI that search may take a short while to reflect edits.
The pattern worth keeping: accept that a derived index is late, bound the lateness with an alert, and make sure the authoritative write is where correctness is enforced.
The interviewer asks you to support 'flexible dates': show listings available for any 3 nights next month. How does the design change?
Write your own answer first, on paper or in a note. Then compare.
Show a hint
Think about what the bitmap makes cheap, and what it would cost to ask the same question of a database.
Show a strong answer
The bitmap makes this a mask scan. Looking for any window of 3 consecutive open nights in a 30-day range is a bit-pattern test on 30 bits, such as ANDing the bitmap with itself shifted by one and two positions and checking for a nonzero result. It runs inside the index at roughly the same cost as an exact-date filter.
Return the matching windows. The result should say which dates matched, so the card can show "Mar 3 to Mar 6". Compute the first matching window in the index, and verify that window with the calendar rows.
Watch the cost. A broader filter returns many more candidates, so cap the candidate count before ranking and prefer a short, cached result for common flexible queries.
The pattern worth keeping: a compact summary that supports cheap bitwise tests turns many query shapes into the same fast scan, which is the payoff of choosing the representation by the queries you need.
Key takeaways
- A search result is only useful if it is available, so dates are part of the query, not a post-filter.
- Carry availability in the index as a compact bitmap: 5 million listings for a year is about 230 MB.
- The index may be wrong, the booking may not: verify at the end and enforce correctness with a conditional write on the calendar rows.
- One row per listing-night as the truth, summarized into a bitmap for search.
- A single-unit listing is simpler than hotel inventory: one conditional multi-row update plus an idempotency key is enough.
- Alert on index lag, because it is the bound on how stale search can be.
Further reading
- PostgreSQL documentation, "Range Types" and "Exclusion Constraints": enforcing non-overlapping date ranges in the database.
- Elasticsearch Reference (Elastic): the geo-distance query and the geo point field.
- Martin Kleppmann, "Designing Data-Intensive Applications" (O'Reilly, 2017): secondary indexes and derived data.