Design Facebook Ad Click Prediction

Free with account Updated Nov 16, 2026 · 18 min read
On this page

    Problem Description

    In this interview, we're going to design click prediction for the ads in a social app's feed, similar to ads on Facebook or Instagram. Advertisers create ads, choose who should see them, set how much they will pay for a click, and set a daily budget. As people scroll their feed, every few posts there is a slot for an ad. For each slot, the system picks one of the ads whose audience fits this person and whose budget isn't used up, giving the slot to the ad with the highest expected value: what the advertiser pays for a click times the chance this person clicks it. The advertiser pays only when someone clicks, and the auction sets that price. People click on ads or hide them, and the system keeps learning from what they do, including from ads launched today. You can use existing building blocks: an ads manager that stores every ad with its audience, bid and budget and pauses campaigns whose daily budget is spent; the feed service, which asks for an ad whenever it reaches a slot; and the company's event stream, where the app already reports which ads people saw, clicked or hid. This interview is about predicting clicks and choosing the ad, not about the feed or billing.

    Not the same as Design an Ad Click Aggregator, which is about counting clicks for advertisers' reports.

    Out of Scope

    • Billing advertisers and spreading a budget across the day – billing charges for clicks; the ads manager pauses spent campaigns.
    • Predicting purchases after a click – a separate model with labels that arrive days later; a good follow-up question.
    • Reviewing ads for policy – ads reach us already approved.
    • Ranking the feed's posts – the feed service owns it; we only fill the ad slots.
    • Creating ads and choosing audiences – the ads manager's tools.

    Good Clarifying Questions

    1. How many ad slots, and how many ads compete for each? – About 1B daily users with about 20 ad slots each: 20B ad requests a day, about 600,000 a second at peak. About 2,000 ads fit a typical person's targeting.
    2. How are the winner and the price decided? – Highest bid × predicted click chance wins. The winner pays per click just enough to beat the runner-up, which divides by its own predicted chance, so the predicted number sets the price, not only the order.
    3. How fast? – The ad must be chosen within 100 ms at p99, of which about 30 ms can go to the models.
    4. How fresh? – New ads launch all day. An ad's own clicks should affect its predictions within 15 minutes; the model is retrained daily.
    5. What if prediction fails? – The feed never waits for an ad. The slot shows a post instead, or an ad chosen with a simpler estimate.

    Requirements

    Functional Requirements

    1. Choose the Ad for Each Slot – When the feed asks for an ad, the system picks, among ads whose audience fits and whose campaign isn't paused, the one with the highest bid × predicted chance of a click, and sets its price per click.
    2. Record Ads Seen and Clicked – The system records which ad was chosen for whom, in which slot, with what prediction and price, and whether the person saw it, clicked it or hid it.
    3. Keep Learning – The system trains a new model from these records at least daily and uses it only after its predictions prove at least as accurate as the current model's.

    Non-Functional Requirements

    1. Scale – 1B users × 20 slots = 20B ad requests a day: about 230K/s on average, 600K/s at peak, each with about 2,000 eligible ads.
    2. Latency – Ad chosen within 100 ms at p99, with about 30 ms for the models.
    3. Freshness – A new ad's own clicks affect its predictions within 15 minutes; a new model at least daily.
    4. Availability – 99.9%. If prediction fails, the slot shows a post or an ad chosen by a simpler estimate; the feed never waits.