TSTier SlateAll templates
  1. Home
  2. Templates
  3. Ad serving

Data & analytics

Ad serving - an auction inside a page load

Why a system with eighty milliseconds to decide must spend money it cannot yet count.

  • System design
  • deep
  • 9 step walkthrough
  • 5 tables
Own this board 800 creditsPractise as an interview

The first act plays here. Owned once with credits, never a subscription.

Share

  • Facebook
  • X

What this board gets wrong on purpose

The tension

THE BUDGET COUNTERS ARE APPROXIMATE ON PURPOSE AND THE ERROR IS DENOMINATED IN MONEY. A consistent decrement across four hundred ad servers cannot fit in an eighty millisecond budget, so each server holds a local allowance and syncs every two hundred milliseconds - which means a campaign near its cap over-delivers by a few tenths of a percent, and over-delivery is served, measured, reported and then WRITTEN OFF, because an advertiser is never billed past their budget. Tightening the sync interval costs latency and infrastructure; loosening it costs revenue directly; and nobody on either side of that argument is wrong. The second unresolved thing is that the auction clears on a PREDICTED click-through rate, so the ranking is only as honest as a model trained on yesterday, and a new creative with no history is priced by a prior that is confidently wrong in whichever direction the prior happens to lean. And the pacer's own input is stale spend, so it is steering a car using a speedometer that reports what was happening two seconds ago - which is fine at a steady pace and oscillates badly whenever traffic moves.

Practise this as an interview

Take Ad serving - an auction inside a page load as a timed system design interview on a blank board - on your own, with the requirements to check yourself against, or with a candidate you invite.

Practise this as an interview

Start here

Why this design

Ad serving is the clearest case of a latency budget dictating architecture: an auction over two million campaigns has to finish inside about eighty milliseconds of a page load, so nothing on the serving path may block on anything it cannot bound. Interviewers use it to probe whether you can do latency arithmetic, keep databases off a hot path, and reason about counters that cannot be both fast and consistent. Real ad teams live with the consequence every day, because the error in those counters is denominated in money - over-delivery that is served, measured and written off.

What you will learn

  • How to spend an 80 ms p95 budget line by line - 9 ms in, 11 ms out, parallel fan-out - and why that leaves no room for a single database read.
  • Why the campaign index is held in memory on every ad server and accepted as 30 seconds stale, and what a paused campaign that keeps serving costs.
  • How local budget allowances synced every 200 ms trade over-delivery for latency, and why that interval is a revenue parameter worth tens of millions a year.
  • How pacing works as a control loop on stale spend, and why it oscillates when traffic moves quickly.
  • Ranking on bid x predicted CTR with a second-price clear, and the cold-start bias a creative with no history introduces.
  • Why the spend ledger is the only lossless component, kept off the serving path, with the write-off recorded as a column rather than a difference.

How to read this board

  1. Diagram, left to right: THE PAGE (the 80 ms clock starts here), ELIGIBILITY (2,000,000 campaigns down to 5,000), PACE & PREDICT (decisions on stale numbers), THE AUCTION (15 ms of arithmetic).
  2. Then AFTER THE PAGE on the right: impressions, the spend ledger, billing and the budget sync wire that carries allowances back. Press play for the walkthrough.
  3. Page 1 · Requirements - the questions to ask first, and the latency and over-delivery targets.
  4. Pages 2 and 3 · Capacity and Storage - the 80 ms budget table, the fleet and counter sizes, and what over-delivery costs in dollars.
  5. Page 4 · Availability - why failing fast is right here, and what degrades rather than dies.
  6. Page 5 · How it works - one ad request end to end, then Page 6 · Deployment - regional budget splits, rollout by revenue per request, rollback.
  7. Finally the DATA MODEL at the bottom: cents as integers, a sampled auction log, and the spend ledger as system of record.

1 · Requirements

Ask these before drawing anything

  • What is the latency budget, and who enforces it? If the publisher drops the slot at 100 ms, then 100 ms is a correctness requirement and not a performance goal, and every design decision below follows from it.
  • Is the advertiser billed per impression or per click? Per click means the auction must rank on predicted click-through rate times bid, which introduces a model into the money path and makes prediction quality a revenue number.
  • What happens when a campaign goes over budget? "It cannot happen" is not an answer at this latency. The real question is how much over-delivery is acceptable and who absorbs it, and it should be a written number.
  • Must a paused campaign stop immediately? Immediately is expensive. Thirty seconds is nearly free. Somebody has to pick, and they should know they are picking.
  • Is this a first-price or second-price auction, and are there external demand partners? A real-time bidding call to an external exchange spends half the budget on somebody else's network.
  • What are the brand safety and legal constraints, and are they hard filters? An ad shown next to the wrong content is not a quality problem, and it must be filtered before the auction, never scored inside it.

Functional

  • Fill an ad slot within 80 ms at p95, or return empty rather than late.
  • Select from roughly two million active campaigns by targeting rules - geography, device, audience segment, context, frequency cap.
  • Run a second-price auction on expected value: bid times predicted click-through rate, with a floor price.
  • Pace each campaign so that its daily budget is spent roughly evenly across the day rather than by mid-morning.
  • Never bill an advertiser more than their budget, even when more than their budget was delivered.
  • Log every impression and click with the auction that produced it, and reconcile against the spend ledger hourly.
  • Give the advertiser reporting that is at most a few minutes behind, and a final billable number that is stable once a day closes.

Non-functional

  • p95 80 ms, p99 120 ms, measured at the ad server including its dependencies. Any dependency without a timeout is a bug, not a risk.
  • No component on the serving path may perform an unbounded read. The campaign index is in memory, the counters are local, and the model is co-located.
  • Over-delivery under 0.5 percent of spend, measured daily. It is never zero, and a target of zero produces a design that under-delivers instead, which is worse.
  • The spend ledger is the financial system of record and must lose nothing. It is the only component here with that property, and it is deliberately off the serving path.
  • Availability 99.95 percent for serving. An empty slot is lost revenue for that impression only, which makes this one of the few systems where failing fast is genuinely the right call.

Out of scope

  • Creative rendering and viewability measurement, which happen in the browser and have their own unpleasant realities.
  • Fraud and invalid traffic detection. It is essential, it is a whole system, and it sits between the impression log and billing rather than inside the auction.
  • Attribution and conversion tracking, which run on an entirely different clock - days, not milliseconds.

The rest of this board

Preview of the Ad serving system design board: 16 components joined by 17 connections. The labelled board opens in Tierslate.
Board preview

Available on Tier Slate

This page publishes the question. The answer — 5 more written pages, a 9-step narrated walkthrough and a 5-table schema — is the board itself, and it opens in Tierslate.

  • 5written pages
  • 9walkthrough steps
  • 5tables43 columns

5 pages behind this one

  • Capacity estimation
  • Storage estimation
  • Availability
  • How it works
  • Deployment plan
Open this board in TierslateBrowse every board

Related system design templates

Pipelines, metrics and the lag between event and answer. 11 more data & analytics templates:

  • Analytics pipeline system design - Why a click takes ten seconds to reach one dashboard and until tomorrow to reach the one people trust.
  • Log aggregation system design - Why searching your logs costs thirteen times more than keeping them, and what you can no longer ask once you sample.
  • Metrics and monitoring system design - Why one label with unbounded values takes down the system that was supposed to explain the outage.
  • Recommendation engine system design - Why the feed is computed in a hundred milliseconds by a model that is a day out of date.
  • Leaderboard system design - How a sorted set answers top ten and my rank in milliseconds, and why rank is computed rather than stored.
  • Search autocomplete system design - Why suggestions come from a precomputed prefix index, and why freshness is traded for speed on every keystroke.
  • View counter system design - Why a counter on a hot row is batched in memory, and how much of the count you may lose on a crash.
  • Uptime monitor and status page system design - Why uptime is measured from many regions outside your network, and why the status page must not share its fate.
  • A/B testing platform system design - How users are bucketed deterministically, and why exposure logging and metric pipelines decide whether a result is real.
  • ETL and the data warehouse system design - Why batch loads trade freshness for correctness, and how late data and reruns are made safe.
  • Full-text search system design - How an inverted index answers a query across shards, and why the slowest shard sets every response time.
Open the Ad serving board in TierslateAll data & analytics templatesAll 100 system design templates
Tierslate

tierslate.com

HomeTemplatesGuidesCompareAboutUI mockupsPrivacyTerms