SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 55
Design ad delivery for a social feed
Businesses create ad campaigns with a daily budget, a bid, a target audience and a creative. As people scroll their feed, every few posts there is an ad slot, and the system has to choose which ad (if any) to show, charge the right advertiser for what was actually seen, and keep each campaign spending smoothly through the day.
Requirements
- Advertisers create and edit campaigns: daily budget, schedule, bid per thousand impressions or per click, targeting (location, age range, interests) and creatives that pass review.
- When the feed requests ads for a viewer, return eligible ads ranked by an auction that combines bid and predicted engagement, within the latency budget.
- Enforce frequency caps (for example at most 3 impressions per user per campaign per day) and pace spend so a daily budget lasts the whole day.
- Record impressions and clicks once each for billing, and show advertisers their spend within minutes.
Constraints and assumptions
- 1 million active campaigns with 5 million ads; targeting and budgets change many times a day.
- Peak 200,000 ad requests per second, each filling 2 to 3 slots; ad selection p99 under 50 ms.
- Peak 300,000 impressions and 3,000 clicks per second.
- A campaign may overspend its daily budget by at most 2%, and anything beyond the budget is never billed.
- Advertiser reports may lag by up to 5 minutes; billing must be exact.
Out of scope for the first sketch
Training the click prediction model · Invoicing and payment collection · Conversion tracking beyond clicks
Draw your design
Rough math and notes
SYSTEM DESIGN SKETCHBOOK / FOLLOW-UPS
Design ad delivery for a social feed
Finish your first sketch before answering these. Cross out freely.
- A campaign with a $100 daily budget is eligible for millions of users. How do you stop it from spending everything in the first ten minutes?
- The ad server picks an ad, but the viewer scrolls past before it ever appears on screen. When exactly do you charge?
- How do you enforce "at most 3 impressions per user per campaign per day" across hundreds of ad servers without a network call per candidate?
- The impression stream is replayed after a consumer crash. How do you avoid billing an impression twice?
- An advertiser pauses a campaign. How quickly does it stop serving, and what can it still be charged for?
Compare afterwards: worked approaches and reading at sketchbook /questions/feed-ads/review