SD-54 · Back to the write-up
Design a Ads Management and Delivery
Choose ads from an in-memory index with two-stage ranking and a second-price auction, spend leased budget slices, and bill each impression once from a deduplicated stream.
Follow a request
Serve ads in the feed
Count an impression
A retried beacon
Budget runs out
Launch a campaign
Read results
Clients
Services
Models, money and data
AdvertiserCampaigns
Phone appFeed + beacons
Event collectorChecks tokens
Ads managerCampaign API
Feed service80 ms timeout
User featuresFeatures + caps
Event logBy campaign
Campaign DBSource of truth
Ad serversIndex + auction
Budget serviceLeases + pacing
Stream processorDedupe + spend
Index builderDelta every 5 s
Ranking modelGPUs
Billing ledgerAppend-only
ReportsColumn store
The numbers, at a glance
200 scored on GPUs1,800 cut by the light model
5 msFeatures
5 msRetrieve
2 msFilter
5 msLight
20 msHeavy
1 msAuction
10 msNetwork
2% repeats98% billable
An ad decision, in order
The beacon comes later, from the phone, through the collector and the log.
Feed service
Ad server
User features
Ranking model
Budget service
1 ad request, 2 slots
2 GET u_81
3 features + caps
4 score 200
5 pCTR × 200
6 2 ads + tokens
7 lease when slice low
RequestResponseAsync, does not block
How budgets are enforced
The decision this question is really about.
Serve ad
INCR spend:c_19
Big campaign = hot key
+ Exact.− 420,000 updates/s on the path.
Serve ad
Stream sums spend
Pause after $10,000 over
+ Nothing on the path.− Stops seconds too late.
Lease $5 slice
Spend locallyStream counts views
Refuse leases at budget
+ ≈ 420 calls/s; under 1% over.− Leased and spent to reconcile.
How it grows
Add a box only when a number forces you to. Highlighted boxes are new at each stage.
AdvertiserPhone + feed
Ads managerAd servers
Campaign DBBudget counter
AdvertiserPhone + feed
Ads managerAd servers + index
Campaign DBIndex builderFeaturesRanking model
Phone + feedEvent collector
Ad servers + indexEvent log
Budget leasesStream processorLedger
Phone + feedEvent collectorAd review
Ad servers + indexEvent log
Budget leasesProcessor + dedupeLedgerReports warehouse
Was this walkthrough useful?Your vote tells us what to improve next.