All system design challenges
#45 Candidate Generation/Ranking

Social Feed Ad Management

Choose which advertisement to show in each slot of a feed in a few tens of milliseconds, from millions of candidate ads.

Asked at Meta Google

What is being asked

Design the ad serving system of a social feed: advertisers create campaigns with targeting and budgets; for each feed request the system picks the best ads, charges correctly and never overspends a budget.

Requirements

Functional

  • Campaigns with targeting, bids and budgets.
  • Select and rank ads per request; record impressions and clicks.
  • Pace spending through the day.

Non-functional

  • A decision within about 50 ms.
  • Millions of ads, billions of requests.
  • Budgets must not be significantly overspent; billing must be accurate.

Design

Feed requestAd serverCandidate retrieval(targeting index)User feature storeRanking: predictedclick and conversionAuction + pacingEvent log:impressions, clicksBudget service
Boxes are services; rounded shapes are data stores and queues.
  1. Retrieval. An inverted index maps targeting attributes (country, age band, interests) to ads. The request's attributes select a few thousand eligible ads, removing those out of budget.
  2. Ranking. A model predicts for each candidate the probability of a click or conversion. A cheap model narrows thousands to hundreds; a heavier one scores the rest.
  3. Auction. Ads are ordered by expected value, bid × predicted probability, adjusted for quality. The winner pays just enough to beat the runner-up.
  4. Pacing throttles each campaign so the budget lasts the day.
  5. Impressions and clicks are logged; a stream job updates spend and feeds model training.

Key decisions and trade-offs

  • A funnel of increasingly expensive stages is the only way to consider millions of ads within the time limit.
  • Budget accuracy against speed. Checking a central budget on every request is too slow, so servers work from spend figures a few seconds old and accept a small overshoot, which the platform absorbs.
  • Feedback delay. A conversion may arrive days after the click, so models train on incomplete labels and must correct for it.
  • User experience. Ad load and relevance limits protect the feed; revenue is not the only objective.

Follow-up questions

  • How do you avoid showing one user the same ad twenty times?
  • How would you detect invalid clicks before charging the advertiser?
  • How does a brand-new ad with no history get shown at all?
  • What happens to pacing if the event pipeline is an hour behind?
Log in to tick off the challenges you have worked through. Log in