# How to design an ad serving system

Source: https://systemdesignsim.com/system-design/ad-serving

System design · Candidate retrieval, eligibility, ranking and pacing

Separate candidate retrieval from expensive ranking: filter eligible ads, score a small candidate set within a latency budget, and record outcomes asynchronously. The cache-money challenge covers a related read path, but does not model an auction or campaign budgets.

Updated October 28, 2026 · 5 min read

[Take the cache money challenge](https://systemdesignsim.com/challenges/cache-money)

![Ad Serving System architecture diagram](https://systemdesignsim.com/diagrams/ad-serving-system-design-diagram.svg)

Requests pass through retrieval, eligibility, ranking and pacing before response.

## The short version

* Retrieve a bounded candidate set first, then filter, rank and pace. Never score every active creative on every request.
* Policy and privacy checks run before ranking and fail closed. Returning no ad is a valid answer.
* Regional spend tokens keep pacing fast but can drift. Strict global reservations are exact but cost latency or availability.
* Impressions, clicks and conversions go to a durable stream. Reporting and billing reconcile later, never on the response path.

## Clarifying questions to ask first

* What placement is served? (Assume a feed placement with a response target below 150 ms at the service boundary.)
* Which campaigns enter the auction? (Assume schedules, targeting, creatives and budgets, with mandatory policy checks.)
* What is the objective? (Assume advertiser value balanced with relevance and user experience. Click prediction alone is not the product goal.)
* Can the system return no ad? (Assume yes. An empty result is safer than bypassing eligibility or privacy checks.)
* How fresh must budget and targeting be? (Assume campaign updates reach serving nodes within seconds, and any spend overshoot needs an explicit product limit.)

## Numbers that shape the design

These are sizing assumptions, not actual traffic.

| Quantity           | Assumption                                                            | Result                  |
| ------------------ | --------------------------------------------------------------------- | ----------------------- |
| Candidates checked | 20,000 requests/s × 100 retrieved                                     | 2 million/s             |
| Candidates ranked  | eligibility removes 90%                                               | 200,000 scores/s        |
| p99 budget, 150 ms | 20 parse and response, 30 retrieval, 20 policy, 60 ranking and pacing | 20 ms margin            |
| Decision events    | 20,000/s × 500 bytes                                                  | 10 MB/s, 864 GB/day raw |

Replace the latency split with measurements. The event volume is before replication, indexes, compression and derived aggregates.

## API

```
POST /ad-decisions
{ requestId, placement, pageContext, viewerContext }

200 { decisionId, creativeId, trackingToken, expiresAt }
204 No eligible ad
```

The client never sends a candidate list or budgets. A repeated requestId is idempotent for a short interval. Keep sensitive context out of URLs and logs. The impression event later carries the tracking token, because a decision does not prove the ad appeared.

## Data model

Keep campaign configuration (the control plane) apart from what serving reads (the data plane). A campaign has owner, schedule, budget, bid strategy, targeting and status. A creative has format, content reference, review state and allowed placements. A serving snapshot is an active campaign version with only the fields online filters need, pushed to serving nodes so no request reads every campaign row.

The decision log stores request, campaign and creative IDs, policy result, model version, time and a bounded feature summary. Don't copy raw personal data into it when coarse features will do. Impression, click and conversion events carry the token and a stable event ID. That history is not the live budget counter: reporting can be eventual, spend control needs a faster estimate.

## High-level design

A router sends requests to a stateless serving API that reads a local or regional active-campaign index. Pacing drops campaigns that can't safely spend more, and the best candidate (or no ad) goes back. A durable event stream feeds reconciliation and reports.

## Retrieval and eligibility

Retrieval returns a bounded set from placement and coarse indexes. Partitioning by region or format helps but creates hot keys, so measure per-key load and have a way to split a key. Meta publicly describes Andromeda as an early retrieval stage that narrows a much larger set before ranking. This is a sourced example, not a claim that this guide reproduces Meta's architecture: https\://engineering.fb.com/2024/12/02/production-engineering/meta-andromeda-advantage-automation-next-gen-personalized-ads-retrieval-engine/

Mandatory policy and privacy checks run before ranking. Log why a candidate was removed without copying sensitive values. Cache only fields whose staleness is safe: stale creative imagery may be fine, stale consent or review status may not. If the policy service can't answer, fail closed.

## Ranking and budget pacing

A score can combine estimated action probability, bid and quality constraints. Keep inputs bounded, versioned and inspectable by operators. Give ranking a deadline. On expiry, fall back to a simpler model over the same eligible set or return no ad; a timeout must never skip eligibility. Measure any fallback that changes campaign order, since it moves both user experience and advertiser spend.

Pacing stops a budget running out early. One approach gives regional cells conservative spend tokens and replenishes them centrally. Cells decide fast and reconciliation catches drift, trading exact global ordering for latency. If budgets must never be exceeded, strict reservations add latency or lose availability during partitions.

The cache-money challenge practises a cache-backed read path, not auctions, targeting, scoring or budget accounting.

## Common traps

* Scanning all creatives instead of bounding candidates first.
* A skewed placement key overloading one partition while average traffic looks healthy.
* Treating a cache as the authority on budget or campaign state. A paused campaign stays eligible; bound propagation and fail closed when required.
* Failing open when privacy or policy checks are unavailable.
* Putting analytics on the response path, or counting every event delivery. Events arrive late or twice; dedupe by event ID and reconcile.
* Regional budget tokens drifting during network trouble with no cap on allocations.

## Follow-up questions interviewers ask

* "A campaign is paused during a regional partition." Name the propagation target and when the region refuses to serve.
* "How do you stop overspend?" Compare regional token allocations with centralised reservations.
* "Ranking times out." State the deadline and fallback, with policy filters still applied.
* "How do conversions affect billing?" Separate decision, impression, click and conversion events, then reconcile them.

## Frequently asked questions

### Why split retrieval from ranking?+

Retrieval narrows a large inventory to a bounded set, so more expensive ranking fits predictable latency and compute budgets.

### Can campaign budgets be exact across regions?+

Strict global reservations coordinate spend but add latency or reduce availability. Regional tokens are faster but need bounded allocation and reconciliation.

### Should click reporting block the ad response?+

No. Persist events durably and reconcile duplicates and late delivery downstream.

### Does the cache-money challenge model auctions?+

No. It demonstrates a cache-backed read path, not ad evaluation, budgets, eligibility or auction outcomes.

## More system design guides

[All 76 guides](https://systemdesignsim.com/system-design)

* [Design a Recommendation SystemCandidate retrieval, staged ranking and freshness](https://systemdesignsim.com/system-design/recommendation-system)
* [Consistent Hashing explainedRebalancing with minimal movement](https://systemdesignsim.com/system-design/consistent-hashing)
* [Networking Basics explainedNetworking Basics](https://systemdesignsim.com/system-design/networking-basics)
* [Design a Search Autocomplete (Typeahead)Tries, top-K per prefix, caching](https://systemdesignsim.com/system-design/autocomplete)
* [Fault Tolerance explainedNines, retries, circuit breakers, chaos](https://systemdesignsim.com/system-design/fault-tolerance)
* [Design a Payment Fraud Detection SystemRisk scoring, delayed labels and payment review](https://systemdesignsim.com/system-design/payment-fraud-detection)

## Now fix it yourself.

Run the design under real traffic and see what breaks first. No signup.

[Take the cache money challenge](https://systemdesignsim.com/challenges/cache-money)
