Learning path: Prepare for ML Engineer Interviews · Step 7 of 13
ML System Design Interview: Ad Click Prediction, Sparse Features, Calibration and Late Clicks
A design-only answer to "predict whether someone clicks an ad": the auction multiplies the predicted chance, so the number itself must be right. Sparse hashed features, calibration beyond AUC, late clicks and training on a stream.
What you will learn
- Start the ad click design from how the number is used: chance of a click times the value of a click
- Explain sparse features and the hashing trade-off between clashes and memory
- Show why a ranking metric misses a model that runs high, and how to check calibration
- Handle late clicks and training on a stream, with a check before each version ships
Before you start
- The ML System Design Framework
- Probability Calibration: Platt and Isotonic
The question: predict whether someone clicks on an ad. This is a system we haven't built in the course, so it's all design thinking, and every number here is for illustration. It's worth your time because four problems show up sharply: sparse features, calibration, late clicks and training on a stream.
Start from how the number gets used
An ad slot opens on a page, and we have to choose which ad to show. Think of an auctioneer in a hurry. Every time a slot opens, the guess has to come back in milliseconds, before the page finishes loading. Each bidder offers an amount per click, so the auctioneer multiplies:
score = chance of a click x value of a click
Ad A: 2% x 50 points = 1.0
Ad B: 1% x 80 points = 0.8 -> A wins (for illustration)
Notice this. The predicted chance goes straight into a multiplication, so sorting the ads isn't enough. The number itself has to be right. Everything else in the answer follows from that.
Hard part 1: huge, sparse features
We know the user, the ad, the site, the device and the hour. Each of those has a huge number of possible values. Picture one switch per value: there could be millions of switches, and for any one request only a handful are on. That's what sparse means. The useful signal often sits in combinations too, like this kind of ad on this kind of site, and combining them multiplies the switches again.
To hold all that, we hash: each value drops into one of a fixed number of buckets, so the size stays under control. The cost is that two values can land in one bucket and share a weight. More buckets means fewer clashes and more memory. Say that trade-off out loud.
That's also why logistic regression over these switches is a sensible baseline: it's quick to score and easy to update.
Hard part 2: can we trust the number?
Calibrated means that when the model says 4%, about 4% really do click. We check it by grouping. Take a thousand times the model said about 4%: that predicts 40 clicks. Say only 20 came, so the model is running two times too high in that group.
Look what that does to the auction. Suppose ad B's true 1% gets reported as 3%. Then 3% x 80 = 2.4, so B now beats A's 1.0, even though A was the better choice.
Here's the trap. A ranking metric like area under the curve only looks at order. Double every prediction, the order stays the same, and that metric doesn't move (more in ROC and AUC). So you also report log loss and a calibration chart, predicted against actual. If it's off, add a small correction step after the model, fitted on recent rows the model didn't train on. That's exactly what Platt and isotonic calibration do.
Hard part 3: the click that comes late
We show an ad and write down a row: did they click? At that moment, nobody knows. A click can arrive seconds later or minutes later, so we have to wait before we call any row a "no".
Call it too soon, and late clicks get counted as no click. For illustration, if 70 of every 100 clicks have arrived when we freeze the label, the model learns a click rate about 30% too low. Wait longer? Then the data is older, and this model needs fresh data.
A common answer: pick a wait that catches most clicks, measure how many come after it, and correct for that share. And give your check data a longer wait, so you aren't grading with the same wrong labels. The same late-label thinking applies to fraud: When Labels Arrive Weeks Late.
Hard part 4: training on a stream
New ads appear all day, and a model trained last week has never heard of this morning's ads. So rows flow in, wait for their labels, and the model takes small updates, often.
But a stream can carry bad data too, so nothing goes straight from training to production. Each new version is checked on the most recent rows against the current model, and if it's worse it doesn't ship. You can always go back to the last good one (a quality gate does this job).
One more thing: the model only sees clicks on ads it chose to show, so it can't learn about the ones it kept out. That's a feedback loop. Give a small slice of traffic to trying other ads, especially new ones. It costs a little now, and it's how the model keeps learning.
Follow-ups and a rubric
- How would you handle a brand new ad with no history?
- How do you keep scoring inside a few milliseconds?
- What would you do if clicks suddenly drop everywhere?
- How do you know a new model is better? Give it a small share of traffic and compare it against the current one.
Mark yourself, one point each, out of 5:
| Row | You get the point if you... |
|---|---|
| Use | said how the number gets used |
| Features | named sparse features and the cost of hashing |
| Calibration | said how you'd measure it |
| Time | covered late clicks and updates |
| Limit | said where your design stops working |
Recap
- Ad click prediction feeds an auction, so the number itself has to be right.
- The features are huge and sparse. Hashing keeps them small, at the cost of clashes.
- Check calibration as well as order; a ranking metric won't catch a model that's running high.
- Clicks come late and the world keeps moving: choose a label wait, take small updates, check each version, and keep trying a few other ads.
Try it yourself
Answer "design ad click prediction" out loud in five minutes, starting from how the number gets used.
Related course on Udemy
Machine Learning Engineer: From First Model to ML Engineer
Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (paid course, opens in a new tab)Related posts
The ML Engineer Interview Loop: Five Rounds, What Each One Looks For, and a Simple Rubric
The rounds you go through for one ML engineer job: recruiter screen, coding, ML depth, ML system design and behavioural. What each round looks for, the follow-up it brings, and a four-check rubric for your own answers.
The Answer Framework for Technical Interviews: Five Moves, Scored Out of 24
Good interview answers share one shape: a 30-second answer, the mechanism, the trade-off, the metric and the failure test. Worked on one question about a batch job starving everyone else, with a 24-point example rubric.
From Symptom to Pattern: How to Answer "Which Pattern Would You Use?" in an Interview
Start from what you can see, not from the pattern you know. A four-step rule (symptom, cost, metric and failure test, ship first), a symptom table, one worked answer for 429s at peak, and the trap of using a prompt as a lock.
The ML System Design Framework: Eight Steps, in Order, on a Spam Filter
One repeatable route through any ML system design question: goal, metric, data, features, model, serving, monitoring and failure. Worked on an email spam filter, with the follow-ups and a three-check rubric.