Ranking metrics (NDCG) and position bias (IPS)
- Score a ranked list with DCG, a gain of 2^grade - 1 over a discount of log2(rank + 1), and say when linear gain fits better
- Build NDCG's ideal from every judged item, sorted before the cut at k, and handle nothing relevant, k past the end and ties
- Compute precision@k, recall@k, MRR and MAP on one list, and say which items count as relevant
- Pick a metric per stage, recall for retrieval and NDCG for the ranker, with bookings deciding the launch
- Say why raw clicks undercount items shown low, and undo it by dividing each click by its position's propensity
- Estimate propensities with swaps or harvested interventions, clip when data is thin, and compare rankers with interleaving
Grade a ranked list
Search and ranking design rounds keep asking two things: how you grade a ranking, and why that grade can lie. The practice problem puts both in code, in four levels. Level 1 reads like this:
Each search returns a ranked list of results, and a judge grades each result from 0 to 3, where 3 is exactly right. Write two functions in NumPy.
dcg_at_k(rels, k)is the discounted cumulative gain of the topkresults, whererelsholds the grades in ranked order. Give each result a gain of2^rel - 1, divide it bylog2(position + 1)with positions counted from 1, and add them up.ndcg_at_k(rels, k)divides that by the DCG of the best possible order of the same items. A list with nothing relevant scores 0.
Call Returns, rounded dcg_at_k([3, 1, 2], 3)9.1309dcg_at_k([3, 1, 2], 1)7.0ndcg_at_k([3, 1, 2], 3)0.9721ndcg_at_k([1, 3], 1)0.1429ndcg_at_k([0, 0, 0], 3)0.0
Level 2 corrects click data for position bias, the extra clicks a result gets just for sitting on top. Level 3 measures how much attention each position gets, from a slice of traffic where the top results were shuffled. Level 4 caps the correction when the data is thin.
You don't write it yet. First you build each piece by hand: the gain, the discount, the best possible order and its edge cases, then the click model behind levels 2 to 4. At the end you solve the whole problem, level by level, in an interview simulation with a 50-minute timer.
A ranking system has two stages, and each needs its own number
NDCG grades the ranker. Before you build it, see where it sits: a search system ranks in two stages, and each stage needs its own number.
Retrieval cuts millions of listings to a few hundred. The question there is whether the good ones survived the cut. The ranker orders those few hundred. The question there is whether the best ones sit at the top.
Then comes the catch. The labels you'd grade with come from clicks and bookings on what the old ranker showed. And people click what's on top.
Search and recommendation design rounds keep coming back to this. The reports:
- In one Airbnb senior MLE loop, reported in August 2026, the design prompt was a user embedding plus a two-stage semantic retrieval and ranking system (1 report).
- In that same loop, the interviewer pushed hard on position bias (1 report).
- One OpenAI MLE candidate reported a recommendation and search design question in the phone screen (1 report).
- A prep site lists a Netflix data science onsite question on planning a ranking A/B test (1 source).
Airbnb has written about this exact shape. Its embedding-based retrieval builds a pool of candidates that heavier models score later in the search ranking (1 source). Its 2018 KDD paper describes the listing and user embeddings it deployed for real-time personalization in search ranking.
In the editor, write recall_at_cut(retrieved, relevant): the share of the relevant listings that made it into retrieval's cut. retrieved holds the 300 listing ids retrieval kept out of a million, and relevant holds the four listings judged good for this search.
DCG adds up gains, and lower ranks count for less
Grading a ranked list needs two ideas: how much each result is worth, and how much its position counts.
A better grade is worth much more
Results get grades from human judges or from what users did. A common scale runs from 0 to 3, where 3 is exactly right and 0 is wrong.
The gain turns a grade into points. With the points roughly double with each grade, so one perfect result beats several decent ones.
Each rank down counts a little less
| Rank | Weight 1 / log2(rank + 1) | Weight 1 / rank |
|---|---|---|
| 1 | 1.00 | 1.00 |
| 2 | 0.63 | 0.50 |
| 3 | 0.50 | 0.33 |
| 4 | 0.43 | 0.25 |
| 5 | 0.39 | 0.20 |
| 10 | 0.29 | 0.10 |
A result further down is worth less, because the user is less likely to ever look at it. The discount says how much less. DCG divides each gain by , so each rank keeps a weight of one over that: the left column.
The weight falls fast at first, then flattens. Rank 2 keeps 63% of its gain, and rank 10 still keeps 29%.
That's on purpose. Järvelin and Kekäläinen, who defined these measures in a 2002 paper on cumulated gain, wanted a discount that falls, but not as steeply as dividing by the rank. Users do keep reading. Dividing by the rank, the right column, would leave rank 10 with 10%.
In the editor, write gains(grades): the gain 2^grade - 1 of every grade. Then write weights(n): the weight 1 / log2(rank + 1) that each rank from 1 to n keeps. Both return NumPy arrays.
DCG is the sum of gain over discount for the top k
Put the two together, and you have DCG.
| Rank | Grade | Gain | Discount | Gain / discount |
|---|---|---|---|---|
| 1 | 3 | 7 | 1.00 | 7.00 |
| 2 | 1 | 1 | 1.58 | 0.63 |
| 3 | 2 | 3 | 2.00 | 1.50 |
| DCG@3 | 9.13 |
Take three results with grades 3, 1 and 2, in ranked order. Each row divides a gain by its rank's discount, and DCG@3 adds the rows: 9.13. At only the first row counts, so DCG@1 is 7.
In symbols:
In words: for each of the top results, divide its gain by its discount, then add them up. is the rank, counting from 1 at the top. is the grade of the result at rank . is the cutoff: only the top results count.
In NumPy it's one line:
import numpy as np
def dcg_at_k(rels: list[int], k: int) -> float:
"""rels: grades in ranked order. The DCG of the top k, with gain 2^grade - 1."""
r = np.asarray(rels, dtype=float)[:k]
return float(np.sum((2 ** r - 1) / np.log2(np.arange(2, r.size + 2))))
print(round(dcg_at_k([3, 1, 2], 3), 4))
print(dcg_at_k([3, 1, 2], 1))
print(round(dcg_at_k([3, 1, 2], 5), 4))
The first two lines print the table's 9.1309 and 7.0. The list holds only 3 grades. What does the last line, at k = 5, print?
Rank 1 divides by log2 of 2, and an off-by-one breaks DCG
The one-line dcg_at_k has one easy place to slip: the discount at rank 1.
In the editor, write dcg_rows(rels, k): dcg_at_k for many queries at once, with the discount right. rels is a 2-D array with one row of grades per query, in ranked order, and you return the DCG@k of every row.
Write dcg_rows(rels, k). rels is (n_queries, n_items), each row one query's grades in ranked order. Return the DCG@k of every row, shape (n_queries,), with gain and discount for ranks counted from 1.
Exponential or linear gain is a product choice
The gain doesn't have to be exponential, and the choice changes what the score rewards. Take the grades [3, 1, 2] again, with discounts 1, 1.58 and 2. With exponential gain, DCG@3 is 9.13.
The same grades with linear gain, the grade itself instead of 2^grade − 1. What is DCG@3?
Your labels are graded 0 to 4, and a 4 is a perfect match. Which gain rewards putting the 4 first most?
NDCG divides by the best order of everything you judged
Raw DCG has no fixed scale. A query with ten grade-3 results can reach a DCG@10 of 31.8, and a query with one can't pass 7. So an average of raw DCG over queries mostly measures which queries had many good results.
NDCG fixes that. It divides by the DCG of the ideal order, the best order possible:
IDCG@k is the DCG@k of the ideal order. Every query now scores between 0 and 1, and a perfect ranking scores 1.
Sort every item, then cut at k
def ndcg_at_k(rels: list[int], k: int) -> float:
"""DCG@k over the DCG@k of every item, sorted. 0 when nothing is relevant."""
# every item, sorted
ideal = dcg_at_k(sorted(rels, reverse=True), k)
return 0.0 if ideal == 0 else dcg_at_k(rels, k) / ideal
print(round(ndcg_at_k([3, 1, 2], 3), 4))
print(round(ndcg_at_k([1, 3], 1), 4))
The first line: NDCG@3 for [3, 1, 2], where the ideal is [3, 2, 1]. About what?
Nothing relevant is 0 over 0, so pick a rule
One input breaks the division: a list where nothing is relevant.
print(ndcg_at_k([0, 0, 0], 3))
Nothing is relevant: [0, 0, 0]. What does ndcg_at_k return?
What do ndcg_at_k([2, 1], 10) and ndcg_at_k([], 5) return?
Ties in the scores need a fixed rule
A ranker gives each item a score, and the page sorts by it. When two items tie, which one goes first is arbitrary, and the metric moves with it:
print(round(ndcg_at_k([3, 0, 2], 3), 4))
print(round(ndcg_at_k([3, 2, 0], 3), 4))
Items score 0.9, 0.5 and 0.5, with grades 3, 0 and 2. What is NDCG@3 with the grade 0 first among the tie, then with the grade 2 first?
A worked example
Six listings come back for a search, judged 0 to 3. In the order your ranker showed them, the grades are [2, 3, 0, 1, 2, 3]. Score the top 5.
shown = [2, 3, 0, 1, 2, 3]
print(f"{dcg_at_k(shown, 5):.2f}")
print(f"{dcg_at_k(sorted(shown, reverse=True), 5):.2f}")
print(f"{ndcg_at_k(shown, 5):.2f}")
The ranker showed grades [2, 3, 0, 1, 2, 3]. What is NDCG@5?
Build the ideal from the top 5 only, so the grade 3 at rank 6 never counts. What does NDCG@5 become?
Swap ranks 1 and 2, so the grade 3 comes first: [3, 2, 0, 1, 2, 3]. What is NDCG@5?
NDCG@k can go down as k grows
You might expect NDCG to rise as k grows, since more results count. It doesn't have to.
print([round(ndcg_at_k(shown, k), 2) for k in range(1, 7)])
NDCG@k for k = 1 to 6 on that list. Does it only go up as k grows?
Precision, recall, MRR and MAP need yes-or-no labels
NDCG uses graded relevance. Four other common metrics need a plain yes or no.
First decide which items count as relevant
rel = relevant(shown, 2)
print(rel)
Relevant means grade 2 or more. What is rel for [2, 3, 0, 1, 2, 3]?
4 relevant items in all, and 3 of them in the top 5. What are precision@5 and recall@5?
Reciprocal rank stops at the first relevant item
Some products care only about the first good result.
queries = [rel, [0, 0, 1, 1], [0, 0, 0]]
print([round(reciprocal_rank(q), 2) for q in queries])
print(round(np.mean([reciprocal_rank(q) for q in queries]), 2))
Three queries: the first relevant item at rank 1, at rank 3, and none at all. What is the MRR?
Average precision takes the precision at every relevant item
Average precision rewards every relevant item near the top, not only the first.
Walk down the list and count the relevant items as you pass them. At each relevant item, take the precision of the list down to that rank: the count so far over the rank. Add those precisions up, and divide by the number of relevant items. Take rel from before, [1, 1, 0, 0, 1, 1], with 4 relevant items in all.
Relevant at ranks 1, 2, 5 and 6, with 4 relevant in all. What is the average precision, and with the list cut at rank 5?
Pick the metric by the stage
With five metrics in hand, the interviewer will ask which one you'd use.
| Metric | Use it when |
|---|---|
| Recall@k | you're judging retrieval: did the good items survive the cut? |
| Precision@k | there's a fixed number of slots and each counts the same |
| MRR | there's one right answer: a known item, a navigational query, the listing they booked |
| MAP | labels are yes or no, several items are relevant, and the whole order matters |
| NDCG@k | labels are graded and the top matters most |
With one booked listing, NDCG and MRR differ only in the discount
Say the only relevant item is the listing that got booked. Both metrics then depend only on its rank:
for r in [1, 2, 3, 5, 10]:
booked = [0] * (r - 1) + [1]
print(r, round(reciprocal_rank(booked), 2), round(ndcg_at_k(booked, 10), 2))
One booked listing, at rank 5. What are its reciprocal rank and NDCG@10?
Offline numbers inherit the old ranker's habits
So far the grades came from judges. When they come from logs, the old ranker leaves its mark on them.
Offline metrics are computed before anything ships, on a fixed set of queries: NDCG on judged results, or on logged searches with the booked listing as the relevant one. They're fast, cheap and repeatable.
Online metrics come from real users in a live test, such as bookings, clicks and revenue. They're closer to the truth, and much slower.
Teams use them in that order. In 2022 Airbnb called interleaving, the fast online check covered in Part 6, the main evaluation technique before the A/B test (1 source).
Logs only hold what the old ranker showed, where it showed it
| Listing | A | B | C | D | E, F, G |
|---|---|---|---|---|---|
| the old ranker showed it at | 1 | 2 | 3 | 4 | not shown |
| clicks | most | fewer | fewer | fewest | none, so no label |
A to D carry position bias. E to G carry selection bias.
Offline numbers built from logs inherit the old ranker's habits in two ways:
- Selection bias. You only have labels for what was shown. A listing the old ranker never showed has no clicks, which is not the same as being irrelevant.
- Position bias. Among what was shown, the top got the most attention, so it got the most clicks, whatever it deserved.
Selection bias is a big reason offline and online numbers disagree, which comes up again under the follow-ups. Position bias is what that Airbnb interviewer dug into.
In the editor, write click_labels(log, catalog). log maps each listing the old ranker showed to its impressions and clicks: the table above, in numbers. Return each listing's click rate, or None for a listing it never showed.
Clicks measure where an item sat, not just how good it is
Clicks are the cheapest labels, and the most biased.
A click needs a look first
An item sits at position 4, where 1 user in 5 looks. It's exactly as good as the one on top. How does its click rate compare?
Inverse propensity scoring divides each click by its chance of being seen
If you know how often each position gets a look, you can correct for it.
def ips_relevance(
clicks: np.ndarray, positions: np.ndarray, propensity: np.ndarray
) -> float:
"""The click rate, with each click divided by its chance of being seen."""
clicks = np.asarray(clicks, dtype=float)
# per impression
p = np.asarray(propensity)[np.asarray(positions)]
return float(np.mean(clicks / p))
rng = np.random.default_rng(0)
propensity = np.array([1.0, 0.6, 0.35, 0.2])
positions = rng.integers(0, 4, size=200_000)
clicks = (rng.random(positions.size) < propensity[positions] * 0.3).astype(float)
print(round(clicks.mean(), 4))
print(round(ips_relevance(clicks, positions, propensity), 4))
200,000 impressions, and the raw click rate is 0.1617. Every click was drawn at 0.3 times its chance of a look. What does IPS estimate?
Raw click rates by position are 0.30, 0.18, 0.11 and 0.06. What are they after dividing by each position's chance of a look?
Why it's unbiased
An impression at position is clicked with chance . Divide by , and is what's left:
is the expected value: the average over many impressions. That holds at every position, so any mix of positions averages to .
It needs one condition. Every position the item was shown at must have . A position nobody ever looks at tells you nothing, and no weight can fix that.
Here's what 1,000 simulated logs give, each built like the practice test's:
| Estimator | Code | Expected | Mean of 1,000 logs | Spread (sd) |
|---|---|---|---|---|
| Raw click-through rate | mean(c) | 0.161 | 0.161 | 0.0008 |
| IPS | mean(c / p) | 0.300 | 0.300 | 0.0019 |
| Multiplied by propensity | mean(c * p) | 0.114 | 0.114 | 0.0006 |
IPS landed within 0.01 of 0.3 in all 1,000 logs. It pays for that with a spread a bit over twice as wide as raw click-through rate's. That's the variance question under the follow-ups.
The same weight fixes offline scoring on clicks. To score a new ranker on old logs, count each logged click toward its metric, divided by the propensity of the slot where the click happened. Joachims, Swaminathan and Schnabel prove this estimate is unbiased.
A real log mixes many items. In the editor, write ips_by_item(items, clicks, positions, propensity): items[j] is the item id shown at impression j, and you return each item's IPS click rate, indexed by its id.
The log now mixes items. Write ips_by_item(items, clicks, positions, propensity): for each item id from 0 to items.max(), the mean of clicks / propensity[positions] over that item's own impressions, as an array.
Harrie Oosterhuis, who researches unbiased learning to rank, on position bias in rankings and how inverse propensity scoring corrects clicks for it.
Production click rates by position aren't the propensities
The practice problem's levels 3 and 4 are the first two follow-ups: where the propensities come from, and what IPS does to variance. The third is offline against online. Comparing two rankers live and questioning the click model come right after.
First: where do the propensities come from? Not from production click-through rate by position. That number mixes examination with relevance, because the ranker put better items on top.
In one simulation, with random relevances, a ranker sorting by a noisy estimate of them, and true propensities of [1.0, 0.6, 0.35, 0.2], production click-through rate by position came out like this, relative to the top:
| Position | 0 | 1 | 2 | 3 |
|---|---|---|---|---|
| true propensity | 1.00 | 0.60 | 0.35 | 0.20 |
| production click rate | 1.00 | 0.38 | 0.14 | 0.04 |
At position 3 that says 0.04 where the truth is 0.20. Dividing by it would weight those clicks about five times too heavily.
You need variation in position that has nothing to do with relevance. Three ways to get it:
- Randomize the top results. For a small slice of traffic, shuffle the top few. Every position then gets the same mix of items, so click-through rate by position is proportional to the propensity.
- Swap two results. Joachims, Swaminathan and Schnabel's intervention swaps two ranks before the user sees the page. Swap the top result with the one at a random rank .
- Harvest the interventions you already ran. Most systems log several rankers, from A/B tests and model updates. When two rankers put the same item for the same query at different positions, that's a swap you didn't have to run.
A swap shows one listing at two ranks, so only the look changes
Of those three ways, the swap is the one to explain at the board.
| Rank | Most traffic | A small slice, swapped with rank 3 |
|---|---|---|
| 1 | listing A | listing C |
| 2 | listing B | listing B |
| 3 | listing C | listing A: the same listing, now at rank 3 |
It's the same listing at two positions, so the same relevance. A's click rate at rank 3 over its rate at rank 1 estimates , and a swap with any rank gives .
Agarwal and coauthors show how to harvest that kind of swap from the logs of several past rankers, with no new experiment. The condition is that which ranker served a query must not depend on the query. An A/B test guarantees that by randomizing.
In the simulation, shuffling the top 4 and swapping both came back within 0.01 of the true propensities. Both cost something while they run: about a fifth fewer clicks on the queries in the experiment, because worse items moved up. Keep the slice small.
Swaps and harvested data give each propensity relative to the top, . The practice uses the same scale: propensity[0] is 1.0. So the estimate is the click rate the item would get if every impression sat at the top. To compare items or rankers, the scale does not matter. Scaling every propensity by the same number scales every estimate the same way.
In the editor, write swap_propensities(log). log holds one (rank, clicked) pair for every impression of one listing: rank 1 on most traffic, and ranks 3 and 4 on the swapped slice. Return its click rate at each rank over its click rate at rank 1.
Airbnb scores every listing as if it sat in the same spot
Airbnb's 2020 paper skips the propensity model altogether:
- Their ranking network got the position as an input during training, and they set it to 0 when scoring. Every listing is then scored as if it sat in the same spot, so only relevance separates them.
- Dropout on the position input keeps the relevance part of the network from leaning on it.
- It needs no randomized traffic, because positions shift on their own as listings get booked and drop out of search.
They reported a 0.7% gain in bookings in the online test. Under the hood it makes the same assumption as IPS: position's effect is one factor shared by every item.
The editor holds a small model like that network. score(listing, position) adds what it learned about the listing, relevance, to what it learned about the position, effect, and logged says where the old ranker showed each listing. Write logged_order, which scores each listing at its logged position, and serve, which scores every listing at position 0.
What does IPS cost in variance?
Each click is weighted , so one click at a rarely seen position swings the estimate. For a single impression at a position with propensity :
is the variance, how much one impression's weighted click spreads around . At that's 0.21 at the top, 2.91 at and 29.91 at . So data from a position seen 10% of the time needs about 14 times as many impressions to pin down as data from the top.
Clipping caps the weight. Divide by instead of , where (tau) is the smallest propensity you allow:
| Propensity p | 1.0 | 0.5 | 0.2 | 0.1 | 0.01 |
|---|---|---|---|---|---|
| weight 1 / p | 1 | 2 | 5 | 10 | 100 |
| clipped at τ = 0.1 | 1 | 2 | 5 | 10 | 10: capped |
Joachims, Swaminathan and Schnabel clip small propensities to a threshold to trade bias for variance. Clipped clicks are undercounted, so the estimate is biased low. At every weight is 1, and you're back to raw click-through rate.
Whether it pays depends on how much data you have. Here's one item with a true rate of 0.3, shown evenly at ranks 1 to 10, with :
| Clip at | Mean estimate | Error (RMSE), 50 impressions | Error (RMSE), 1,000 impressions |
|---|---|---|---|
| none | 0.300 | 0.177 | 0.039 |
| 0.2 | 0.247 | 0.142 | 0.061 |
| 0.3 | 0.200 | 0.142 | 0.103 |
| 0.5 | 0.146 | 0.169 | 0.155 |
| 1, raw CTR | 0.088 | 0.216 | 0.212 |
With 50 impressions, clipping at 0.2 cuts the error by a fifth. With 1,000, the bias outweighs the variance it saves, and plain IPS wins. The paper found the same: clipping improves performance on small datasets. Pick on held-out data, and report it with the estimate.
Errors in the propensities themselves aren't symmetric either. The same paper found that overestimating small propensities is tolerable, while underestimating them can hurt, because an underestimate inflates the weights. Clipping is a deliberate overestimate.
In the editor, write variance(r, p): the variance of one weighted click, from the formula above. Then write clipped_weight(p, tau): the weight after clipping at tau.
The offline metric and the online metric disagree
A reported Airbnb ML experience round asked exactly this: "What do you do when the offline metric and the online metric disagree?" (1 report). Work through the likely causes before you pick a side:
- The offline set only covers what the old ranker showed. Offline you re-rank logged results, and online the model ranks everything. Airbnb's 2020 paper describes hitting this. A model with an extra price objective, tuned until its offline NDCG matched the baseline, lost 0.67% of bookings online. Their offline analysis had only re-ranked the top results that were in the logs.
- The labels carry position bias. Clicks from the top of the old ranking look like relevance. Weight them by propensity, or evaluate on randomized traffic.
- The offline metric isn't the goal. NDCG on clicks can rise while bookings don't move. Label with the action you care about.
- The online test is the noisy one. Check its power and its duration, and look for novelty effects, before you blame the offline metric.
Then say what you'd do: trust the online result for the launch, and fix the offline setup until it agrees with the online results you already have.
Before you trust an offline number, check how much of the new page your logs can grade. In the editor, write judged_share(ranking, labeled, k): the share of the new ranker's top k that has a label in the logs.
Two rankers, one test
An A/B test splits traffic: some users see ranker A, some see B, and you compare bookings. The first decision is the unit you randomize. A prep site lists a Netflix data science question built around that choice: user-level, session-level or query-level randomization (1 source).
| One user's five searches | Units | Spill-over | |
|---|---|---|---|
| query-level | A B B A B | most | A can change how they use B |
| user-level | A A A A A | fewer | none |
Query-level gives the most units, but one person sees both rankers, and their behavior on one can spill into the other. User-level keeps each person on one ranker, at the cost of fewer units. Whatever you randomize, compute the standard errors at that unit.
The editor holds arm(unit_id), a stable coin flip: it hashes the id, so the same id always lands in the same arm. Write assign(searches, unit), which flips that coin on the user id or on the query id, and n_units(searches, unit), the number of independent units. searches holds one (user, query id) pair per search: two users with five searches each.
Interleaving puts both rankers on one page
Interleaving is faster. Each user sees one list that merges both rankers, and each click is credited to the ranker that contributed the clicked item. Radlinski, Kurup and Joachims's team-draft interleaving works like picking teams for a game. Each round a coin decides which ranker picks first, and each picks its best item that hasn't been taken:
import random
def team_draft(a: list[str], b: list[str], k: int) -> tuple[list[str], dict[str, str]]:
"""Interleaves rankings a and b into k items. Returns the shown list and each item's team."""
shown, team = [], {}
while len(shown) < k:
n_a = sum(t == "A" for t in team.values())
n_b = len(team) - n_a
a_picks = n_a < n_b or (n_a == n_b and random.random() < 0.5)
ranking, name = (a, "A") if a_picks else (b, "B")
pick = next((d for d in ranking if d not in team), None)
if pick is None:
break
shown.append(pick)
team[pick] = name
return shown, team
Read the loop body from the top:
teammaps each shown item to the ranker that picked it, son_aandn_bcount each side's picks.a_picksis true when A is behind, or when the sides are even and the coin,random.random() < 0.5, falls to A. Every even score starts a new round with a fresh flip.- The next line takes the picker's list and name together.
next((d for d in ranking if d not in team), None)is the first item on that list nobody has taken yet, orNonewhen there isn't one.
Here are two rounds, where A ranks h1, h2, h3, h4, and B ranks h3, h1, h6, h2:
| Round | Coin | First pick | Second pick |
|---|---|---|---|
| 1 | A first | A takes h1 | B takes h3 |
| 2 | B first | B takes h6, since h3 and h1 are gone | A takes h2, since h1 is gone |
Shown: h1 from A, h3 from B, h6 from B, then h2 from A.
Two coin flips give four possible lists, each with probability 1/4:
| Coin flips | Interleaved list, with each item's team |
|---|---|
| A first, A first | h1 (A), h3 (B), h2 (A), h6 (B) |
| A first, B first | h1 (A), h3 (B), h6 (B), h2 (A) |
| B first, A first | h3 (B), h1 (A), h2 (A), h6 (B) |
| B first, B first | h3 (B), h1 (A), h6 (B), h2 (A) |
Whichever ranker's items get more clicks wins the query. The share of wins over many queries says which ranker users prefer.
Airbnb credits bookings rather than clicks (1 source). In 2022 it reported a 50x speedup over an A/B test at the same traffic (1 source).
The speed comes from pairing. Every query compares both rankers on the same person at the same moment, so differences between people cancel. On arXiv's search engine, Radlinski and coauthors found that paired tests like these give substantially more accurate and sensitive results than absolute usage metrics. The coin flip matters as much. If one ranker always picked first, position bias alone would hand it more clicks.
Interleaving tells you which ranker users prefer, not how much bookings will move. The A/B test still makes the launch call.
In the editor, write winner(team, clicked): A, B or tie, by whose items got more clicks. team is the list shown in the example above, each item with the ranker that picked it. Then write preference(winners): A's share of the wins, leaving out the ties.
When one position curve isn't enough
The position-based model is a model. Push on it when:
- The page isn't a list. On a map, Airbnb notes, there is no ranked list and no decay of attention by rank (1 source). Grids and carousels have their own patterns, so estimate examination for each layout.
- What's above changes what's seen. In a cascade model, users go down the ranking in order and click a result if it is relevant. Whether anyone reaches position 4 then depends on what sits at 1 to 3.
- The user changes attention. Airbnb's 2020 paper notes the examination probability may depend on the user: people on mobile may favor the top results more. Fit separate propensities by device or query type when you have the data.
In the editor, write cascade_seen(relevance) for the cascade model: users read down in order and stop at their first click. relevance[i] is the chance the item at position i gets clicked once it is seen. Return the chance that each position is seen.
The practice problem, start to finish
That's every piece the practice problem needs. It asks for the four levels from the start of the lesson, from a blank file, and the interviewer follows up after each one.
1.Your ranker shows grades
[1, 3]and you compute NDCG at k = 1. What's the right value?2.Your labels are binary, booked or not. Does it matter whether the gain is
2^rel - 1orrel?3.An IPS function multiplies each click by its propensity instead of dividing. On the practice log, where the true top-position rate is 0.3, what does it return?
4.Some impressions sit at a position with propensity 0.01, and you clip propensities at 0.1. What changes?
5.Why can't you take propensities from production click-through rate by position?
Where this shows up
The reports behind this lesson, each with its source.
ML system design in the same loop: user embeddings plus two-stage semantic retrieval and ranking.
The interviewer pushed hard on position bias.
Same MLE report: the phone screen ML design question was about recommendation and search.
Netflix DS onsite question on the prep site (posted 2025-10-13): plan a ranking A/B test, choosing user, session or query randomization.
Embedding-based retrieval (Mar 2025) produces a candidate pool that more compute-intensive ranking models score later.
“which can then be scored by more compute-intensive machine learning models later in the search ranking process.”
Interleaving is the main evaluation step before an A/B test.
“Interleaving is currently part of our experimentation procedure, and is the main evaluation technique before the A/B test.”
ML experience round: what to do when offline and online metrics disagree.
Interleaving for search ranking (Oct 2022, older): a 50x speedup over an A/B test at equal traffic.
“We achieve a 50x speedup over an A/B test given the same amount of traffic.”
Interleaving credit is assigned by bookings, a downstream action.
“we assign credits by bookings, which is a downstream activity”
Map ranking differs from list ranking: attention does not decay with rank position.
“There is no ranked list, and there is no decay of user attention by ranking position.”
Practice
Sources (10)
- Real-time Personalization using Embeddings for Search Ranking at Airbnb · KDD 2018 · Jul 19, 2018
“In this paper we describe Listing and User Embedding techniques we developed and deployed for purposes of Real-time Personalization in Search Ranking and Similar Listing Recommendations, two channels that drive 99% of conversions.”
- Cumulated Gain-Based Evaluation of IR Techniques · ACM Transactions on Information Systems 20(4) · Oct 1, 2002
“Note that the ideal vector is based on the recall base of the search topic rather than on the result of some IR technique.”
- Learning to Rank using Gradient Descent · ICML 2005 · Aug 7, 2005
“We chose to compute the NDCG at rank 15, a little beyond the set of documents initially viewed by most users.”
- sklearn.metrics.ndcg_score · scikit-learn 1.9.1 documentation · Sep 10, 2026
“Sum the true scores ranked in the order induced by the predicted scores, after applying a logarithmic discount.”
- Parameters: label_gain · LightGBM 4.7.0 documentation · Jul 18, 2026
“relevant gain for labels. For example, the gain of label 2 is 3 in case of default label gains”
- rank_metric.hpp, the NDCG evaluation metric · LightGBM 4.7.0 source code · Jul 18, 2026
“if all doc in this query are all negative, let its NDCG=1”
- Improving Deep Learning For Airbnb Search · arXiv 2002.05515 (KDD 2020) · Feb 10, 2020
“Using NDCG to quantify the position of the booked listings in search results has been the most reliable gauge of model performance for us.”
- Unbiased Learning-to-Rank with Biased Feedback · arXiv 1608.04468 (WSDM 2017) · Aug 16, 2016
“position bias in search rankings strongly influences how many clicks a result receives, so that directly using click data as a training signal in Learning-to-Rank (LTR) methods yields sub-optimal results”
- Estimating Position Bias without Intrusive Interventions · arXiv 1812.05161 (WSDM 2019) · Dec 12, 2018
“we show how to harvest a specific type of intervention data from historic feedback logs of multiple different ranking functions”
- How Does Clickthrough Data Reflect Retrieval Quality? · CIKM 2008 · Oct 26, 2008
“We conclude that both paired comparison tests give substantially more accurate and sensitive evaluation results than absolute usage metrics in our domain.”