5/36
Part 2 of 5 · Stages and retrievalLearn and do

Narrow millions of listings to one page, in stages

With the label settled, turn to the numbers that shape the system.

Scoring every listing takes seconds, so narrow in stages

The main ranker on all 10,000 eligible listings, at 200 µs each
budget
250 ms
needed
2,000 ms

Do the numbers before you draw boxes. Assume 7 million active listings, a figure for this exercise: Airbnb's retrieval post says only that search covers millions of homes. A search for a city might cover 50,000 listings. 10,000 of them are free on the dates and fit the party. The guest sees a first page of about 20.

Can the best model score all 10,000? Assume the main ranker costs 200 µs a listing. A µs is a microsecond, a millionth of a second, and 200 µs is the time per listing after batching on the serving machines. 10,000 × 200 µs is 2 s, against a budget of a few hundred milliseconds. On all 7 million listings it's 1,400 s.

Listings left after each stage
all listings
7,000,000
filter
10,000
retrieve
2,000
first pass
300
main ranker
300, in order
re-rank
a page of 20

So the system narrows in stages. Each stage costs more per listing than the one before it, so the expensive model sees only a few hundred listings. The filter isn't a model at all: it's lookups in the search index. The retrieval stage runs on two-tower vectors and an ANN index, a nearest neighbor index.

The time budget, stage by stage

Here's that funnel against a 250 ms p99 budget. p99 is the time that 99 of every 100 requests finish within. Push the main ranker's items toward 10,000 and watch it blow past the line. Then see how much of the first-pass ranker you can afford.

Stays search, p99Interactive
Parse query and geocode10 ms
Location and availability filter30 ms
Embedding retrieval20 ms
Feature fetch30 ms
First-pass ranker20 ms
Main ranker60 ms
Diversity and rules15 ms
Total185 ms of 250 ms
budget 250 ms
Fits, with 65 ms to spare

First-pass ranker: 10 µs per item. Main ranker: 200 µs per item.

As set, the request takes 185 ms: 20 ms for 2,000 first-pass scores, 60 ms for 300 main-ranker scores, and 105 ms for everything else. With the main ranker on all 10,000 eligible listings, it's 2,125 ms, 1,875 over budget.

In the editor, write request_ms(fixed_ms, scored), the widget's total for one request, and room_for(budget_ms, used_ms, us_per_item), how many listings one stage can still score in the time left. Model stages cost microseconds per item, so divide by 1,000 to get milliseconds.