Design an Ad Targeting Platform
Design an ad targeting platform: CTR prediction, real-time bidding, and ML optimization.
What is an ad targeting system?
An ad targeting system decides which eligible advertisement to show for one opportunity, such as an ad slot in an app or on a web page. It first removes campaigns that are not allowed to compete, then predicts useful outcomes, chooses a winner through an auction, and records what happened for measurement and future training.
This is an ML systems problem because a high score is never enough. The serving path must meet its deadline while enforcing consent, campaign budget, frequency limits, and fairness rules. The core invariant is simple: do not serve an ad unless its hard constraints can be verified.
Correctness
Eligibility is a gate
Consent, inventory rules, budget, frequency caps, and policy exclusions run before a model score can influence the auction.
ML task
Ranking is a prediction
Estimate a calibrated probability of a useful outcome from approved context and features, then combine it with a bid under explicit pacing rules.
Operations
Logging closes the loop
Log the candidate set, positions, decisions, and outcomes asynchronously so measurement does not hold the user-facing response open.
Start with one decision, not a vague personalization goal
For every eligible impression, choose at most one campaign and return a bid before the exchange deadline. The advertiser wants efficient spend and reach; the publisher wants relevant, policy-compliant ads; and the person viewing the page expects their choices and limits to be respected.
In scope
- Consent-aware contextual and first-party audience targeting.
- Campaign eligibility, frequency caps, daily pacing, ranking, and a second-price-like auction with a transparent reserve policy.
- Impression, click, and conversion logging for reporting and controlled model updates.
Out of scope for the first version
- Cross-site identity graphs built from unconsented data.
- Automatic creative generation or unconstrained reinforcement learning on live spend.
- A claim that clicks alone prove incremental business value.
Name the costly mistakes
- Serving without verified consent is a privacy and policy failure, not a relevance trade-off. Fail closed for the affected targeting signal.
- Overspending a campaign breaks the advertiser contract. A late budget update must never become permission to keep bidding.
- Optimizing click-through rate alone can overexpose a group, reward misleading creative, or concentrate impressions in a narrow audience.
- Timing out an auction loses the opportunity. A bounded contextual fallback is acceptable only after the same hard gates pass.
Before discussing models, write down the auction deadline, the regions where data may be processed, the daily budget rule, the frequency-cap window, and the protected or high-risk slices that require separate evaluation. These are product requirements that the architecture must preserve.
Model serving for real-time bid scoring
A real-time bidding system must return a bid response within ~100ms at massive QPS, scoring each impression for click/conversion likelihood. How should you serve the scoring model on the bid hot path?
Constraint: Hard sub-100ms bid latency at very high QPS — the auction drops late responses, and per-request compute is multiplied across millions of QPS.