Chapter Deepread · ML System Design Interview · Chapter 8

Ad Click Prediction: you think it's ranking, but it's quoting a price

Machine Learning System Design Interview · Ch 8 · Ali Aminian & Alex Xu · 2023

中文 →

What is this chapter about?

As you scroll a social app, every dozen or so posts an ad slides in. This chapter is about how that one ad got picked — why that ad, and why for you.

A strange thing first

You probably assume the system is picking "the one you're most likely to find interesting." Order does matter, but there's a layer here that other recommendation settings don't have: money is divided by this judgment. Advertisers pay per click, and the platform has to do arithmetic between "who bid more" and "who will actually get clicked." So the system can't just say "this one is more likely than that one" — it has to name an accurate number.

Weather forecasts are the useful comparison. If all you want to know is whether tomorrow is rainier than the day after, ordering is enough. But if somebody charges insurance premiums by the chance of rain, then "70%" had better mean it really rains seven times out of ten. Ads are the second kind.

Why the old world struggled

Almost everything the system knows arrives as labels: which city you're in, what phone you use, who placed this ad, what hour you're scrolling. Any one of them is weak on its own — "lives in Shanghai" predicts nothing.

The forceful clues are combinations: somebody who bought bananas and a cookbook is more likely to want a blender. But a system that scores each clue separately and adds them up can never see a signal that only exists when two things are true at once. And there are absurdly many combinations — a few hundred clues paired up is tens of thousands of pairs, far more than people can curate by hand.

The core mechanism: let the machine do the pairing

The trick is to give every label a business card — a short string of numbers the machine works out for itself. Bump two cards together and you get a score for "how well do these two go together." The machine runs every pair, and the data decides which combinations matter. Nobody has to name them in advance. That's the chapter's first move.

The second move is how often it studies. An ad pool isn't like a film library — new ads go live every hour and what's hot changes daily. A judge trained last week hasn't seen half of what's in front of it this week. So it doesn't sit one exam a week; it studies on the job, continuously nudging itself toward the present using the impressions and clicks that just happened.

The third move is that accurate number. The system checks itself against history: of all the ads it called 2%, did about 2% actually get clicked? If not, the whole dial gets twisted back. That step is called calibration, and without it the ordering can look fine while every invoice is wrong.

How to read this approach

What's worth remembering is where the effort goes: how the machine finds combinations, how often it studies, and whether the numbers are honest. Eighty percent of the chapter lands on those three. The model itself is not the star.

What it costs

A judge that studies on the job slowly forgets what it once knew — and a version that learns something wrong can reach everybody within hours. Fast iteration and a big blast radius are the same property seen from two sides.

Remember this one line

What separates ad click prediction from every other recommendation problem is that its output goes on to divide money. It has to get the order right, say the number honestly, and keep up with a market that changes hourly. Drop any one of the three and the system starts quietly losing money.

Want the mechanisms, notation and diagrams? → Switch to the deep read