Design an Ad Click Prediction System
Run this for someone else. You hold the answers; they do not. Read the prompt, keep the clock, and use the probes below when an answer is thin. Do not show them this page.
Open with this
The model that predicts whether a user clicks an ad: 150 M calibrated predictions a second inside a 100 ms auction, retrained every hour. Take a couple of minutes on requirements, then we will do some numbers, then the design. I will interrupt to keep us moving.
The clock
- 4 min: functional requirements and scope
- 4 min: non-functional requirements, with numbers
- 5 min: back-of-envelope estimates
- 16 min: high-level design and one or two flows
- 16 min: deep dives and the close
Move them on out loud when a section overruns. The commonest failure is spending twenty minutes on requirements and never reaching a deep dive, and preventing that is your job as much as theirs.
Requirements · 8 min
Listen for: a scoped set of capabilities, an explicit out-of-scope list, and numeric targets rather than adjectives. Prompt with “what are you not building?” if they never scope, and “what number would make that requirement real?” if they say “fast” or “highly available”.
Functional (9)
- Predict a click probability for every candidate in an auction: About 300 ads per request, after the ad server’s pre-ranker, each with a pCTR for the slot it would fill, returned inside the auction’s deadline. The auction multiplies it by the bid and prices clicks from it, so it must be a probability, not just a good ordering.
- Log exactly what the model saw: Every served ad carries the inputs and versions used to score it, so its training row can be rebuilt bit for bit and any prediction explained later. Logged once per request, not once per candidate.
- Label impressions with clicks that arrive later: A click arrives seconds to hours after its impression, on another stream. Each impression becomes one example, clicked or not, after a defined wait, with clicks flagged as invalid traffic removed.
- Build training data without leakage: Every feature in a row is the value serving could have read at that moment. That includes features added later and backfilled over past weeks, which is where leakage usually gets in.
- Fresh features online, their history offline: Counters under 30 s old at millisecond latency for scoring, and every past value with its timestamps for training, both written from one definition per feature.
- Refresh the model continuously: Thousands of new ads an hour and click rates that move within a day. Routine refreshes ship without a person approving each one; architecture and feature changes go through a full experiment.
- Keep predictions calibrated: Predicted clicks equal observed clicks per placement, country and ad format, measured continuously, with a correction that does not wait for a retrain.
- Ship and roll back models safely: Shadow, canary and an online A/B test for new models; automatic gates and a short canary for hourly refreshes; rollback in one step to a version that is still loaded.
- Out of scope: Retrieval, targeting, the auction itself, budgets and pacing (the Ad Serving design), billing-grade click counting (the Ad Click Aggregator), the choice of network architecture, and conversion prediction beyond how it would reuse this pipeline.
Non-functional (8)
- Scoring latency (p99 < 30 ms for 300 ads): The model’s share of a 100 ms auction. This drives the hardest trade-off in the design: model size and feature count against a fixed budget per request, at 150 M scores a second.
- Throughput (150 M scores/s at peak): 500 k requests a second × 300 candidates. Capacity is counted in candidates scored, not requests, and GPUs are the largest cost in the design.
- Calibration (predicted ÷ observed 0.95 to 1.05): Per placement, country group and ad format, because errors cancel in the global average. Prices and pacing are computed from predictions, so a 5 % bias is a 5 % mispricing.
- Freshness (model < 2 h · counters < 30 s): New ads and campaigns move click rates by the hour. Minute-level freshness comes from features, hour-level from retraining; the model’s age is the time from an impression to a published model that learned from it.
- Training and serving parity (replayed score = served ± 1e-4): Re-scoring a sample of served requests offline must reproduce the served raw score. It is the only check that covers the transform code as well as the stored values.
- Label correctness (no invented negatives): A delayed or stalled click stream must delay labels, never turn real clicks into non-clicks, and invalid clicks never become positives. A bad hour of labels is a bad model an hour later.
- Always a score (100 % of auctions scored): Degrade by scoring fewer candidates, then by falling back to the pre-ranker’s calibrated scores; never an empty slot because the model is slow. Fallback scores are marked and never trained on.
- Privacy (consent honoured · deletion < 30 days): Personalised features only for users who allow ad personalisation. A deletion removes the user’s embedding row, online features and training rows, which is why rows are partitioned so they can be rewritten.
Estimates · 5 min
Ask for two or three numbers, not all of them. What matters is whether they state assumptions, round sensibly, and say what the number implies. Push once with “where did that come from?”
The numbers (8)
- Ad requests per second: ~230 k/s avg · ~500 k/s peak. 20 B requests/day ÷ 86,400 ≈ 231 k/s. The evening peak is about twice the average, ~460 k/s; size for 500 k/s.
- Scores per second at peak: ~150 M/s. 500 k requests/s × 300 candidates = 150 M predictions/s. Requests are not the unit of work here, candidates are: every candidate the ad server adds raises the model’s cost linearly.
- GPUs for scoring: ~300 (vs ~1,500 naive). Run whole for each candidate, a GPU scores ~100 k candidates/s: 1,500 GPUs. The part over the user’s last 1,000 events is ~80 % of that work and identical for all 300 candidates. Computed once, a request costs 0.8 + 300 × 0.2 ≈ 61 units instead of 300, ~5× less, so ~500 k/s per GPU and 150 M ÷ 500 k = 300 GPUs before headroom. This one split is worth 1,200 GPUs.
- Embedding tables: ~128 GB served · ~512 GB in training. ~2 B rows (≈1.75 B user-side ids, ≈250 M ad-side ids and hashed crosses) × 64 dims. In fp32 for training 2 B × 64 × 4 B = 512 GB; quantised to int8 for serving 128 GB. More than one 80 GB GPU holds, so the ad-side tables (~16 GB) live on the GPU and the user-side ones (~112 GB) in host RAM, read once per request.
- Impressions and clicks per day: 30 B impressions · 300 M clicks. 1.5 impressions per request (some fetches fill two slots, some none): 20 B × 1.5 = 30 B impressions/day, ~350 k/s on average and ~700 k/s at peak. At a 1 % click rate that is 300 M clicks/day: positives are 1 row in 100, which is why non-clicks are sampled.
- Label joiner state at peak: ~420 GB. Each impression is held open until its 10-minute window closes: 700 k/s × 600 s = 420 M open impressions × ~1 KB (the served row) ≈ 420 GB, about 1.6 GB on each of 256 partitions. A 20-minute stall of the click stream adds ~840 GB, so the state lives on local SSD, not in memory.
- Training rows per day: ~3.3 B rows · ~3.3 TB. Keep every click and 10 % of non-clicks with weight 10: 300 M + 0.1 × 29.7 B ≈ 3.27 B rows/day at ~1 KB ≈ 3.3 TB/day, or ~140 M rows for each hourly training run. Thirty days for the weekly full retrain is ~100 TB.
- Hourly model update: ~7 GB instead of ~130 GB. In an hour about 100 M embedding rows change (the users and ads in that hour’s data) × 64 B = 6.4 GB, plus ~1 GB of dense layers: ~7 GB. Pushing the whole 130 GB model to ~120 hosts every hour would be ~16 TB/h of internal traffic; deltas are what make an hourly refresh cheap.
High-level design · 16 min
Let them draw. Interrupt only to ask what backs a component or what a box actually does. Then pick one flow below and ask them to walk it end to end.
Components (15)
- Experiment platform (arms · budget split): The A/B Testing Platform design: assigns users to model arms by a hash in the ad server’s process and computes the online metrics. For model tests the arms also split each campaign’s budget by traffic share, and it keeps a long-running 1 % holdback on a frozen weekly model that measures what hourly freshness is worth.
- Model registry (versions · maps · splits): Every model version with its lineage (training hours, feature schema, parent checkpoint, offline metrics), the calibration maps fitted for it, and which share of traffic each version serves: production, canary, shadow, holdback. Scorers watch it and swap versions between requests; a rollback is one write that points production at a version still loaded in memory.
- Model monitor (calibration · skew · guardrails): Independent of the trainer and the fitter: compares predicted with observed clicks per segment every 10 minutes, tracks how far each calibration map bends from the identity, watches the label rate and feature distributions online against offline, and judges every canary. It can roll a version back or freeze publishing on its own, because the system that ships a model should not be the one that judges it.
- Online feature store (KV · latest value · SSD): Latest feature values keyed by user id: profile, the last 1,000 interactions as ids, and per-advertiser counters, ~10 KB per user and ~15 TB for 1.5 B users, in an Aerospike or Bigtable class store with p99 reads under 5 ms. Also the source of the per-ad counter snapshot scorers pull every minute. It holds no history: “what was this value at 14:02 yesterday” is the offline store’s question.
- User app (renders ads · beacons): Shows the ads the ad server picked, sends an impression beacon when an ad is on screen and a click through the tracker, both carrying the signed impression id. Beacons can arrive late from a phone that was offline, or twice after a retry; the impression id is what makes them joinable and easy to deduplicate.
- Ad server (auction · 100 ms): The caller, as in the Ad Serving design: retrieves, filters and pre-ranks to ~300 candidates, calls the scorer with a 35 ms deadline, and runs the auction on bid × pCTR. Here it matters for two things: it sets how many candidates the model sees, which is the overload dial, and it writes the served record, including the inputs the scorer used, that every training row starts from.
- Scoring service (GPU · user part once): Treats one request as one batch: reads the user’s features once, runs the part of the network over the user’s history once, then scores all 300 candidates in a single GPU pass and applies the calibration map. Ad-side tables (~16 GB) and dense layers sit in GPU memory, user-side tables (~112 GB, int8) in host RAM. Returns calibrated pCTRs and a log blob of exactly the inputs it used.
- Trainer (hourly warm start · weekly full): Every hour, continues from the serving checkpoint on the last hour’s ~140 M rows and produces a candidate in ~25 minutes; every week, retrains from scratch on 30 days so architecture and feature changes land and slow drift is reset. Evaluates each candidate on the impressions just after its training data, never on a random split, and publishes only the rows that changed, ~7 GB.
- Event collector (impression · click beacons): The HTTPS edge for impression and click beacons. Verifies the impression id’s signature, so a forged click cannot label a row, stamps the receive time next to the client’s event time, appends to the event log and only then answers. Duplicates are expected from phone retries and are resolved downstream by impression id.
- Event log (Kafka · served · beacons): Topics for served records keyed by request id, impressions and clicks keyed by impression id, and invalid-traffic flags: ~1 GB/s at peak, kept 3 days so the joiner and the feature jobs can replay after an outage. Every downstream consumer reads event time from the records, never the time it happens to read them.
- Feature pipelines (Flink + daily batch): Turns events into features: streaming jobs keep counters (an ad’s impressions and clicks per placement over 1 h and 1 d, a user’s clicks per advertiser over 30 d, recent interaction lists) under 30 s behind, and daily batch jobs compute slow features. Each value is written twice by the same code: to the online store as the latest value, and to the offline history with its event time and the time it became readable online.
- Offline store (columnar · by hour · as-of): Training rows partitioned by hour, and the history of every feature value with event time and available time, as Parquet or Iceberg tables on object storage. Serves the trainers, as-of joins that backfill a new feature exactly as serving would have seen it, the calibration fitter, the monitor, and a daily rebuild that relabels with a 24-hour window and late invalid-traffic verdicts.
- Click aggregator (invalid traffic · billing): The Ad Click Aggregator design: deduplicates clicks for billing and flags invalid traffic (bots, click farms, accidental double taps), most within minutes and the rest in a nightly pass. Those flags matter to training as much as to billing: a model trained on bot clicks learns to predict bots, and an ad being click-bombed would look like a great ad.
- Label joiner (by impression id · 10 min): A stream join that turns a served record, its impression, any click and any invalid-traffic flag into one training row, keyed by impression id. It waits 10 minutes of event time after the impression, closed by the click stream’s watermark rather than the wall clock, so a stalled click pipeline delays labels instead of inventing negatives. Emits every click and 10 % of non-clicks with their weights.
- Calibration fitter (per segment · every 30 min): Fits a monotone map from raw score to click probability for each of ~4,000 segments (placement × country group × ad format) on the last 6 hours of labelled rows, undoing the negative sampling and adding back the ~2 % of clicks the 10-minute window misses. Thin segments fall back to their parent. A map belongs to one model version and is never applied to another.
Flows to ask them to walk (5)
- Score 300 ads inside one auction: The read path the auction waits on. The model sees 300 candidates but only one user, and the design exploits that: one feature read and one pass over the user’s history per request, then a single batched pass over the candidates.
- The app asks for ads; the ad server narrows the field to 300 candidates and looks up this user’s model arm.
- The ad server calls the scorer with the user, the context, 300 ad ids and the slots, under a deadline.
- The scorer reads the user’s features in one round trip and takes ad features from memory.
- The scorer runs the user half of the network once, then all 300 candidates in one GPU pass.
- Raw scores go through the calibration map for each ad’s segment, then the slot factor.
- The scorer returns calibrated pCTRs, the versions used and a blob of the inputs it read.
- The auction ranks on bid × pCTR, and the ad server writes the served record, blob included.
- An impression and a click become a row: The write path that feeds training. The click arrives seconds to minutes after the impression, on a different stream, so no row can be written until the system has waited long enough to call a non-click a non-click.
- The ad appears on screen and the app sends an impression beacon with the signed impression id.
- The label joiner opens state for the impression and starts a 10-minute event-time timer.
- The feature pipelines count the impression into the ad’s and the user’s counters.
- Forty seconds later the user taps the ad, and the click goes through the collector to the log.
- The joiner marks the open impression as clicked; a second tap changes nothing.
- An invalid-traffic flag that arrives inside the window removes the click.
- When the click stream’s watermark passes the impression time plus 10 minutes, the row is emitted.
- A daily batch run of the same join relabels yesterday with a 24-hour window and final verdicts.
- A record evening: 150 M scores a second: The scale-breaking case. Doubling traffic doubles candidates scored, and GPUs cannot be added in minutes, so the scorer stays inside its deadline by doing less per request instead of failing requests.
- Requests climb to ~500 k a second; each is a batch of 300 candidates, 150 M scores a second.
- Each host packs several requests into one GPU launch, waiting no more than 2 ms to fill it.
- Feature reads grow with requests: 500 k multi-gets a second against the online store.
- Queueing inside the scorer passes its threshold, and every response starts reporting load.
- The ad server scores fewer candidates on low-value placements first: 300, then 200, then 100.
- A host that stays slow is hedged: the request goes to a second host after the p95.
- An auction whose scores miss the deadline runs on the pre-ranker’s scores and is marked.
- The click stream stalls for 20 minutes: The failure that quietly breaks an ML system. If anything treats “no click yet” as “no click”, an hour of training data says nobody clicks, the next model believes it, and prices fall across every auction.
- Clicks from one region stop reaching the event log, while served records and impressions keep flowing.
- The joiner’s click watermark stops at the last click it saw, so no window past that point closes.
- State grows instead: twenty more minutes of open impressions, ~840 GB, spilled to local SSD.
- The trainer finds the hour incomplete and does not publish; production keeps the previous model.
- The calibration fitter holds its maps, and the monitor pages on the label rate and freezes publishing.
- Clicks catch up; the watermark moves and windows close with correct labels, in order.
- The trainer processes the delayed hours in order, and publishing resumes once the monitor lifts the freeze.
- The hourly refresh ships itself: The background path that keeps the model fresh. Twenty-four releases a day cannot each get an A/B test, so a refresh is a chain of automatic gates, a short canary and a rollback that is one write.
- Once an hour’s rows are complete, the trainer continues from the serving checkpoint on that hour.
- It evaluates the candidate on the impressions just after its data, against production on the same rows.
- The calibration fitter fits maps for the new version on recent rows scored by it.
- The registry records the version, and scorers pull the delta: changed rows and dense layers, ~7 GB.
- For 15 minutes, 5 % of requests run the new version while the monitor compares it with the rest.
- The guardrails hold and the registry moves all traffic; one tripped guardrail would have reversed it with a single write.
- Meanwhile 1 % of users stay on last week’s frozen model, to measure what freshness buys and to catch drift.
Deep dives · 16 min
Pick two. Ask the headline question, let them answer, then use the follow-ups. The follow-ups are where the level gets decided, so leave time for at least three of them.
Joining a click that arrives later
Ask: A click can arrive seconds or an hour after its impression. When do you decide an impression was not clicked, and what does that choice cost?
Good answers name: Event-time stream join, 10-minute window closed by the click watermark, plus a daily 24-hour rebuild, Batch join once a day in the warehouse, Emit every impression at once as a non-click, and a positive copy when the click comes, Close windows on the wall clock.
Our pick: The joiner is a Flink-class job keyed by impression id, with RocksDB state on local SSD. The served record opens the state (it is written before the page renders); the impression beacon starts a 10-minute event-time timer; a click inside the window sets the label; an invalid-traffic flag inside the window removes it. Timers fire only when the watermark of every click partition, in every region, has passed impression time plus 10 minutes, so a stalled region holds rows rather than closing them. Every click is emitted and 10 % of non-clicks with weight 10, upserted by impression id so a replay rewrites the same row. A daily batch job runs the same join code with a 24-hour window and the nightly invalid-traffic verdicts, for the weekly retrain and to measure the completion factor (24-hour clicks ÷ 10-minute clicks, about 1.02 per placement) that calibration applies. Google described this problem at search-ads scale in its Photon paper (SIGMOD 2013), which joins queries and clicks across data centres exactly once, and Facebook’s 2014 click-prediction paper describes an online joiner with a waiting window for the same reason.
- Why 10 minutes and not 1 or 60?
Because of the delay curve and what each extra minute buys. One minute catches ~90 % of clicks, so one positive in ten would be a fake negative, too large a bias to correct cleanly. Sixty minutes catches 99.5 %, but rows reach the trainer an hour later and the join state grows six-fold to ~2.5 TB. Ten minutes is the knee: ~98 % of clicks for ~420 GB of state, and the missing 2 % is a stable, measured factor. I would set it per placement from the measured curve, since a long video ad tends to be clicked later than a feed ad. - What happens to a click that arrives after its window closed?
In the hourly path it is lost: the row was already emitted as a non-click or sampled away. It goes to a late-click side output, and the daily rebuild labels that impression correctly for the weekly retrain. So the hourly model learns “clicked within 10 minutes”, about 2 % below the true rate, and the calibration layer multiplies by the measured completion factor so the auction still sees the true probability. - The joiner crashes and restarts. Do you get duplicate or different rows?
Neither. State and input offsets are checkpointed together, so a restart replays from the last checkpoint and rebuilds the same state. Windows close on event-time watermarks, so the replay makes the same decisions, and rows are upserted by impression id, so a row emitted before the crash is overwritten by an identical one. That is an exactly-once effect on top of at-least-once delivery. - How does this change for conversion prediction?
Conversions, such as a purchase or an install, arrive hours to days later, often through the advertiser’s own reporting. A window long enough to be accurate, say 7 days, would make the model a week old. That is where emitting at once with a delay-corrected loss earns its complexity, or a model that predicts the delay along with the conversion, as Criteo published in 2014 (“Modeling Delayed Feedback in Display Advertising”). The joiner itself barely changes: same key, longer state, kept on disk. - How would you know the joiner is healthy?
Three numbers per region. The join rate: the share of impressions that found their served record and of clicks that found their impression, both near 100 %; a drop means a key or clock problem. The click rate of emitted rows against the same hour last week. And the output watermark lag, how far behind real time the emitted rows are, which is the trainer’s real freshness.
Training rows without leakage
Ask: A teammate adds “clicks on this ad today” and offline AUC jumps from 0.78 to 0.80. Online, nothing. What happened, and how should the rows have been built?
Good answers name: Logged inputs for production features; backfills by an as-of join on available time from a history with both timestamps, As-of join on event time, Join daily snapshots by date, Recompute features in the training job from raw events, with the streaming job’s code.
Our pick: Production training rows are built only from the inputs the scorer logged, and every transform (bucketing, hashing, crosses, defaults for missing values) lives inside the exported model graph, so training and serving run the same code on the same inputs. Every feature pipeline also writes each value to the offline store with event_time and available_at, the moment the online store could serve it. A new feature is backfilled by an as-of join on available_at ≤ request time, never on event time or on the date, and it is logged at serving from the day it ships, before any model uses it. After two weeks the backfilled values are compared with the logged ones for the same requests; a gap is the backfill’s skew and blocks the switch. Two checks run all the time: a replay that re-scores 0.01 % of served requests offline from the log and must match the served raw score to 1e-4, which catches transform skew; and per-feature null rates and distributions online against offline (population stability index), which catch a default or a unit that differs between the two paths.
- Why is available time not just event time plus a constant?
Because pipeline lag varies. A streaming counter is usually 20 to 40 seconds behind but falls minutes behind during an incident; a daily table lands at 03:00 on a good day and 09:00 on a bad one. Serving saw whatever was there, lag included. Recording the real available time on every write captures that, and a backfill built from it reproduces the stale reads serving actually made, which is what the model has to cope with. - What other leaks are common in click prediction?
Session features computed at the end of the session, such as “ads clicked this session”, which include the session’s later clicks. Target encodings, such as an advertiser’s historical click rate, computed over a period that overlaps the training rows instead of ending before them. Random train and test splits, which put the same user-hour on both sides. And any feature whose pipeline reads the click stream with a shorter lag offline than online. The defence is the same for all of them: as of available time, and evaluation on a later period than training. - Why put the transforms inside the model graph?
Because the most common skew is not the stored value but what is done to it: a different bucket boundary, log instead of log1p, a missing value as 0 on one path and −1 on the other. If raw inputs are logged and every transform is part of the exported model, there is one implementation, and the replay check proves it. Transforms written twice, once in a SQL training pipeline and once in the serving code, drift apart within months. - The replay check fails for 0.3 % of requests. How do you find the cause?
Compare the failing rows feature by feature between the logged input and the training pipeline’s version of it; skew is almost always one feature. If the inputs match and the scores do not, the model artefacts differ, for example a quantisation step or a different version, which is why the tolerance is 1e-4 and not exact equality. Failures concentrated in one region or one scorer build point at deployment, not data.
Scoring 300 ads in 30 milliseconds
Ask: The auction gives you 30 ms to score 300 ads, 500 k times a second. How do you fit a big model into that?
Good answers name: One request is one batch: user part once and broadcast, candidates in one GPU pass, ad tables on the GPU, user tables in host RAM, Score each candidate as an independent example, Two-tower dot product: precomputed ad vectors, one user vector, Embedding tables sharded across separate parameter servers.
Our pick: The scorer receives one request with 300 ad ids and treats it as one batch. It reads the user’s ~10 KB of features in one multi-get (6 ms cap, hedged at the p95), looks up ~200 user-side ids in host RAM (int8, ~112 GB), and runs the user tower over the last 1,000 interactions once. The ad-side tables (~16 GB) and dense layers sit in GPU memory, so the 300 candidates gather their own embeddings on the GPU and go through the interaction and top layers in one pass. A dynamic batcher may pack 2 or 3 requests into one launch, waiting at most 2 ms. Position is a separate shallow tower, so each ad is scored once at a reference position and multiplied by a per-slot factor. The budget is 6 ms features, 2 ms lookups, 2 ms batching, 10 ms GPU, 1 ms calibration and response, and 9 ms of slack. Large ad platforms have described computing user-side parts once per request and reusing them across candidates; I would not quote their exact numbers.
- A scorer host is slow. What does the auction see?
The ad server hedges: if a host has not answered by the scorer’s p95, about 18 ms, it sends the request to a second host and takes the first answer, which costs extra GPU on only ~5 % of requests. A host whose queue stays long is taken out by its health check. If both copies miss the deadline, the auction runs on the pre-ranker’s calibrated scores and the served record is marked as a fallback, so those rows never train the model. - Traffic doubles for an hour and you cannot add GPUs that fast.
Do less per request instead of failing requests. The scorer reports queue time on every response; above a threshold the ad server trims candidates on low-value placements first, 300 to 200 to 100. The tail of the pre-ranked list carries little expected value, so revenue falls far less than the work does. The candidate count goes into the served log, so analysis can tell trimmed auctions from normal ones. - Why int8 for the embeddings but not for the dense layers?
Embedding tables are 99 % of the bytes and each row is used rarely, so row-wise int8, with a scale and offset per row, loses very little and saves 4× over fp32. The dense layers are ~1 GB and touched by every prediction, so quantising them saves little memory and risks more accuracy. Whatever is quantised, the replay check compares served scores with the training-side model, so a quantisation error shows up as skew rather than as a mystery. - Why not run all of this on CPUs?
For a model this size, the interaction layers and the sequence tower are dense matrix work that GPUs do roughly ten times cheaper per score. CPUs fit the light models: the pre-ranker, the fallback, and small markets where a cheaper model is good enough. The user-table lookups do run on the CPU, which is why those tables live in host RAM next to the GPU. - How do 10 M ads’ features reach the GPU without 300 network reads?
Per-ad counters (impressions and clicks per placement over 1 hour and 1 day, ~100 B per ad, ~1 GB in all) are pulled as a versioned snapshot every minute and held on each host, and the ad-side embedding rows already sit in GPU memory. A request carries 300 ids, not 300 feature vectors, and the snapshot version goes into the log blob, so training reconstructs exactly what was used.
Calibrated probabilities, not scores
Ask: Your new model has a better AUC and loses 2 % of revenue in the A/B test. How is that possible, and how do you make sure the number multiplied by the bid is a probability?
Good answers name: A monotone map per segment (placement × country group × format), fitted every 30 minutes on recent labelled rows, versioned with the model, Trust log loss: a model trained on it is calibrated, One global Platt scaling, a logistic fit on the raw score, Correction factors per advertiser.
Our pick: After the model, the scorer applies an isotonic map, stored as ~20 knots on the logit, chosen by segment: ~40 placements × ~20 country groups × 5 formats, ~4,000 segments. The fitter runs every 30 minutes on the last 6 hours of joined rows scored by the serving version, undoing the 10 % negative sampling with the row weights and multiplying by each placement’s completion factor (~1.02) for clicks the 10-minute window misses. A segment with fewer than ~2,000 clicks in the window falls back to placement × format, then to placement. Maps are versioned with their model and published as a pair; a new model gets maps fitted on held-out rows before it serves any traffic. The monitor measures the calibration ratio, Σ predicted ÷ Σ observed clicks, per segment, on 10-minute labels scaled by the completion factor and confirmed the next day on 24-hour labels, with alerts outside 0.95 to 1.05. It separately tracks how far each map bends from the identity: a correction that grows week by week means the model is drifting and the map is hiding it. Google’s 2013 paper “Ad Click Prediction: a View from the Trenches” describes the same idea, a calibration layer on top of the model to correct systematic bias.
- Why not refit the maps every minute?
Because a map fitted on a few minutes of data fits noise: a segment with 2,000 clicks in six hours has about 5 in a minute. Every 30 minutes over a 6-hour window balances freshness against variance. The fast-moving part of click rates, a new ad or a live event, is the job of the model and the counters; calibration corrects systematic bias, which moves slowly unless something breaks, and breakage is the monitor’s job. - A brand-new ad format launches. How is it calibrated on day one?
It has no segment of its own yet, so it falls back to its placement’s map, and the monitor tracks its ratio from the first hour. Until it has ~2,000 clicks it keeps the parent map, and the launch caps its share of auctions so a 20 % miscalibration costs little. Once it has data it gets its own map and its own line on the dashboard. - The maps reorder ads across segments. Is that a problem?
It is the point. Two ads in one auction can sit in different segments, a video and an image ad competing for the same slot, and if the model overpredicts video by 8 %, the map lowers video against image, which is exactly the correction that makes the auction fair. Within a segment the map is monotone, so the model’s ranking there is kept. What the map must not do is absorb a bias the model should learn, which is why its size is monitored. - How does calibration interact with exploration for new ads?
A new ad’s prediction rests on its advertiser and creative features and is less certain, and a map corrects the average of such ads, not each one. That is fine for pricing in aggregate but can starve a good new ad, which is why the Ad Serving design gives new ads a small exploration slice. Rows from those auctions carry their propensities, so the fitter and the trainer weight them correctly instead of treating explored impressions as ordinary ones.
Hourly, daily or continuous training
Ask: How often should the model be retrained, and why not just train it continuously on the click stream?
Good answers name: Hourly warm-start refresh with delta pushes, a weekly full retrain, and minute-fresh counters as features, Daily full retrain, Continuous online training, syncing changed rows to serving every minute, Retrain only when metrics degrade.
Our pick: About 10 minutes after the hour ends, once the last of its 10-minute windows has closed, the trainer warm-starts from the serving checkpoint and makes one pass over that hour’s ~140 M rows, in ~25 minutes. New ids get embedding rows initialised from their advertiser’s and creative’s rows. It evaluates on the next 10 minutes of impressions against the production model on the same rows (progressive validation) and publishes only the changed rows and the dense layers. Weekly, a full retrain from scratch on 30 days (~100 TB) produces a new base that goes through shadow, canary and A/B like any new model, and the hourly chain then continues from it. Fast-moving signals live in features, not weights: ad and user counters are under 30 seconds old, so a new ad’s own click rate starts counting minutes after launch. A 1 % holdback on last week’s frozen model measures what the hourly chain is worth and whether it drifts.
- How do you know hourly is worth it over daily?
Measure it instead of assuming it. The 1 % holdback on a frozen weekly model gives the decay curve directly: normalised entropy and revenue per thousand requests against the hourly chain, by the frozen model’s age. If the gap at 24 hours is a tiny fraction of revenue, daily is enough and the hourly machinery is not worth its risk. At this platform’s scale even a fraction of a percent is a lot of money, which is usually why hourly wins. - Someone runs a click-bombing attack on one ad. What does the hourly model learn?
Ideally nothing, because the click aggregator flags the bot clicks and the joiner drops them inside the window. If the flags are late, the hour’s rows show a wild click rate for one ad and placement. A validation step before training compares each ad’s and segment’s click rate with its recent history and quarantines outliers, and the evaluation gate catches a candidate whose predictions shift. The daily rebuild corrects the labels for the weekly retrain. - What does warm starting cost you?
Path dependence. A warm-started model is the sum of every hour’s updates and can drift slowly: rows for users who stopped appearing never update, optimiser state goes stale, one bad hour leaves a trace. The weekly full retrain resets that. At each weekly switch the fresh model is compared with the hourly chain; if the fresh one is not at least as good, something in the chain went wrong. - How does a 7 GB delta reach 120 hosts without disturbing scoring?
Each host downloads it in the background from a regional mirror or from peers, writes the changed rows and dense layers into a second copy of just those parts, and switches a version pointer between requests. The cost is memory headroom for a second copy of the changed part, not of the whole model. The previous version stays addressable for an hour, so the registry can roll back with one write.
Shipping a new model safely
Ask: A new architecture beats production by 1 % normalised entropy offline. Take me from there to 100 % of traffic.
Good answers name: Offline replay, shadow on 10 % of requests, a 1 % canary with automatic guardrails, a budget-split A/B test, then a ramp with a holdback, Straight to an A/B test, Offline metrics only, Interleaving both models within one request.
Our pick: Offline: normalised entropy, calibration and AUC per segment on two weeks of rows from a later period than training, plus a replay of logged auctions to estimate revenue per thousand requests. Shadow: the new model scores 10 % of live requests after the auction already has its answer, with outputs logged and never used, for 2 to 3 days; that checks p99 latency on real inputs, the prediction distribution, calibration as labels arrive, and the replay check against its own training pipeline. Canary: 1 % of requests for a day, with guardrails that roll back automatically within minutes: p99 latency and timeouts, mean pCTR against control, calibration ratio within 0.95 to 1.05, revenue per thousand requests, click rate, and cost per click for large advertisers. A/B: 5 % for 1 to 2 weeks with each campaign’s budget split between arms (the Ad Serving design explains why), judged on revenue, advertiser value (conversions per dollar, which keeps budgets coming) and user signals such as ad hides and session time. Then a ramp to 100 %, keeping a 1 % holdback for a few weeks to watch long-term effects. Hourly refreshes skip shadow and the A/B test: they pass offline gates, then a 15-minute canary on 5 % with the same guardrails.
- Shadow scoring costs GPUs. Is it worth it?
On a slice, yes, which is why it is 10 % of requests: about 30 extra GPUs for three days is cheap next to a pricing incident. Shadow is the only stage that tests the model on exactly the live inputs with nothing at stake, and it is where feature skew, a slow new layer, or maps fitted for the wrong version show up. Running it after the auction has its answer means it can never slow a real request. - Which guardrail fires most often, and is it usually real?
Mean pCTR against control, because any feature or calibration mistake moves it at once, long before revenue can be measured. It is noisy on a small canary, so it uses a band, say ±3 %, and a minimum duration before it trips. A real problem is a sustained shift that the calibration ratio confirms once labels arrive 10 to 20 minutes later; a blip that reverses is not. - The A/B shows +1.5 % revenue and −2 % advertiser conversions per dollar. Ship it?
Not as it is. More revenue with worse results per dollar usually means the model raised prices or sent impressions where they convert less, and advertisers adjust: they lower bids or move budget elsewhere, so the gain decays over weeks. I would find the segments that lose advertiser value and check whether calibration shifted there, and if the trade-off is real, decide it explicitly with the business rather than let a short test decide it. - Why do hourly refreshes skip the A/B test?
Because they change weights, not the design: same architecture, same features, one more hour of data. Their risks are a bad hour of data or a broken push, which offline gates and a 15-minute canary catch. An A/B test per hour would never finish, since revenue needs days to measure. The holdback on a frozen weekly model is the long-run check that the hourly chain as a whole is helping.
Close · 5 min
Ask what breaks first at ten times the load, and what they would build next. Then give them your read: one thing that was strong, one thing that was missing, one thing to practise. Be specific; “good job” helps nobody.