Latest / The CTO Podcast with Fexingo: Technical Leadership, Architecture, and Engineering Org / How Airbnb Rebuilt Its Search for Instant Bookings
Transcript
- Lucas: So, if you booked an Airbnb in the last few years, the search results came back in under 200 milliseconds. But that speed is relatively new — and it took a full rewrite of their search backend to get there. Luna: Was it always slow? I remember searching for apartments in Tokyo a few years ago and the spinner would hang for a couple seconds. Lucas: Yeah, that tracks. Before 2018, the core search was inside a monolithic Rails app. It would hit a PostgreSQL database, do some filtering, then apply pricing and availability checks. For a simple query, you'd get results in maybe 2.3 seconds — which feels like an eternity when you're trying to book a place before someone else snaps it up. Luna: And that's especially bad for instant bookings. If you're competing with other guests, every millisecond matters. Lucas: Exactly. So in 2016, Airbnb started a project called 'Search Service' — a dedicated C++ service built on top of Apache Lucene. The goal was to bring search latency down to under 200 milliseconds while supporting real-time pricing, availability, and location filters. Luna: Why C++? I mean, that's a pretty aggressive choice for a company that was mostly Ruby and Java at the time. Lucas: Great question. The team needed absolute control over memory layout and query execution. Lucene is written in Java, but they decided to wrap it in a C++ service for two reasons: one, they needed to minimize garbage collection pauses, and two, they wanted to embed the index directly in the process memory without going through JNI overhead. It's a pretty extreme optimization, but it paid off. Luna: So they're basically running a custom search engine. Why not just use Elasticsearch? That's what most people would reach for. Lucas: They actually evaluated Elasticsearch. The problem was that Elasticsearch's near real time refresh interval — typically one second — wasn't fast enough for their use case. Airbnb needed listings to appear within seconds of being created or updated. Also, Elasticsearch's scoring model didn't fit their ranking needs: they needed to incorporate price, availability, and host quality signals into a single relevance score. So they built their own indexing pipeline that pushes updates into the Lucene index in under 100 milliseconds. Luna: That's an incredibly tight window. How do they handle the indexing without blocking queries? Lucas: They use a technique called 'writer per shard' — essentially, each search shard has its own Lucene IndexWriter. When a listing is updated, the change goes into a Kafka topic, then a consumer applies the change to the appropriate shard. The IndexWriter commits incrementally using Lucene's near real time features, so new documents become visible on the next query without a full refresh. It's a delicate dance between index freshness and query performance. Luna: And what about the cold start problem? When a new listing goes live, it has zero booking history. How do you rank that against established listings? Lucas: That was one of the trickiest parts. They use a machine learning model that predicts the likelihood of a booking based on listing features — like location, price, photos, host verification — and also incorporates a 'novelty boost' for new listings that decays over time. The model reranks the top 500 results from the Lucene retrieval phase. So the search is effectively two-stage: first a fast Lucene query to get candidates, then a lightweight ML rerank on the top results. Luna: So the ML model isn't running on every query result, just the top candidates? Lucas: Right. The Lucene query returns the most relevant 500 listings based on text and location matching, then the reranking model scores those 500 using dozens of features. That keeps the ML inference cost manageable — we're talking about maybe 10 milliseconds per query for the rerank. The total end to end latency stays under 200 milliseconds. Luna: Okay, but what about real-time pricing? If a host changes the price for a specific date, that needs to be reflected instantly. How does that work with a precomputed index? Lucas: They actually don't index the price as a static field. Instead, they store the base price and a set of pricing rules — like weekend multipliers, minimum stay discounts, seasonal adjustments. Then, at query time, they compute the effective price for the user's search dates using a lightweight C++ pricing engine embedded in the search service. The engine evaluates the rules in real time. It's a clever trade-off: they sacrifice a bit of query-time compute to avoid reindexing every time a host tweaks a price. Luna: That makes a lot of sense. So the index only stores relatively static attributes — location, amenities, text — while dynamic things like price and availability are computed on the fly. Lucas: Exactly. Availability is handled similarly: they use a bitmask representation of the next 365 days, stored in the index, and filter based on the user's requested dates at query time. That's actually a common pattern in travel search — Expedia and Booking.com do something similar. Luna: What about the geographic search? Airbnb's maps are pretty central to the experience. Does Lucene handle geospatial queries well? Lucas: Yes, Lucene has built-in support for geospatial indexing using a technique called 'S2 geometry' — the same approach Google Maps uses. They index each listing's latitude and longitude as an S2 cell ID, then when you zoom in on a map, they can do a fast bounding-box query to return only the listings visible in that view. The key insight is that they precompute the S2 cell at multiple resolutions, so the query can pick the appropriate level based on zoom. Luna: So all of this was built in-house. What's the operational cost of maintaining such a custom system versus a managed service like Elasticsearch? Lucas: That's the million-dollar question. The team at Airbnb has to manage shard rebalancing, index merges, hardware failures — all the usual distributed systems headaches. But they claim the performance gain is worth it. In their own benchmarks, the custom service is about 10x faster than Elasticsearch for their specific query patterns. And because the service is written in C++, it uses significantly less CPU per query, which reduces infrastructure costs at their scale. Luna: Still, I wonder if that's the right call for most companies. Airbnb is processing hundreds of millions of searches a day. But if you're a smaller marketplace, building a custom search engine might not be the best use of engineering time. Lucas: I think that's a fair point. Airbnb's approach is a case study in extreme optimization for a very specific problem. But the principles — two-stage retrieval, real-time pricing engines, S2 geocoding — those are transferable even if you're using a managed service. You can always add a custom reranking layer on top of Elasticsearch, for example. Luna: Right. So the lesson isn't 'build your own Lucene wrapper in C++.' It's more about understanding your latency and freshness requirements, and then designing the system accordingly. Lucas: Exactly. And if this conversation was useful for what you're building or running, it's worth knowing that the show stays ad-free thanks to listener support. You can find that at buy me a coffee dot com slash fexingo. Luna: Yeah, that's a small way to keep these deep dives coming. And we really appreciate the listeners who do. Lucas: So, back to the architecture — one more detail I find fascinating: they also built a custom query parser that understands synonyms and misspellings. For example, if you type 'appartment', it still matches 'apartment'. That's done with a custom Lucene analyzer that includes a dictionary of common misspellings and abbreviations. Luna: That's such a small but important UX win. I bet it saves a lot of frustrated users. Lucas: Absolutely. The team measured that after deploying the new search service, the booking conversion rate went up by about 3 percent just from the speed improvement alone. That's huge for a marketplace like Airbnb. Luna: I'd love to see more companies publish those kinds of metrics. It's one thing to say 'we reduced latency by 90 percent,' but another to show how that impacts the bottom line. Lucas: Agreed. And that's the kind of data that helps justify the investment in infrastructure. So when you're in a room pitching a rewrite to your CTO, saying 'this will increase bookings by 3 percent' gets a lot more traction than 'this will reduce latency by 2 seconds.' Luna: Right. It's about tying engineering metrics to business outcomes. Thanks for unpacking this, Lucas — I learned a lot. Lucas: Thanks, Luna. And for anyone building search, I'd say: start by measuring your current latency and conversion, then iterate. You might not need a custom C++ service, but you definitely need to know your numbers.