</> MAANG.io

Expert

Design landmark systems in depth, from Dynamo, GFS, Bigtable and Kafka to payments and ads pipelines.

0 of 232 solved 0%

Section 2: Fast for the Feed, Exact for the Invoice - Requirements (Functional & Non-Functional)

Executive Summary: Section 1 reframed "show some ads" as a latency-bounded, money-bearing pipeline called by the feed service. This section writes the contract. Functionally, the system selects three ads for a placement, honors targeting, policy and frequency caps, runs an auction and prices each winner, respects every budget, issues a signed tracking token per ad, ingests impression and click events, feeds spend back to pacing, and logs what it served for training. Non-functionally, it answers in 80 ms at p99, returns a valid response 99.99% of the time, reflects a takedown within 10 s, overdelivers by no more than 0.1% of daily spend, and bills every verified click exactly once. Two requirements pull in opposite directions, speed on the request path and exactness on the money path, and keeping them apart shapes most of what follows.

The interviewer turns the page. "You've scoped it. Now tell me what you're promising, in numbers I could test, and what you're refusing to build."

You: "Two kinds of promise, and they want different things. The request path promises speed: answer inside 80 ms or get out of the feed's way. The money path promises correctness: every billable click counted once, never invented, never lost. A lot of this design is about keeping those two from leaking into each other."

Functional requirements: what the system does

Each duty is shown through Maya's 7:42 a.m. request, r-7f3a, for three ads on feed_mobile.

On the request path (inside the 80 ms):

  • Select ads for a placement. Given a placement and a slot count, return up to 3 ads. Fewer, or none, is a legal answer.
  • Honor eligibility. Only ads whose targeting matches Maya, whose creative has passed policy review, whose schedule is live, and whose frequency cap isn't spent. Trailhead's cap is 3 impressions per user in any rolling 24 hours.
  • Run the auction and price each winner. Rank by expected value, charge each winner no more than its bid. Trailhead bids $1.20 per click and, as Section 10 works out, pays $1.01 if Maya clicks.
  • Respect budgets and pacing. Spread each campaign's spend across the day and stop delivery when the budget runs out. Trailhead has $5,000 a day.
  • Emit a signed tracking token with every ad, carrying the price, so later events can be verified without trusting the client.

On the feedback loop (seconds to a day):

  • Ingest impression and click events: verify the token's signature and its one-hour validity, append to a durable log, then deduplicate and filter invalid traffic downstream.
  • Feed spend back to pacing, so the next requests see a campaign's current spend.
  • Log what was served, with the features used at serve time, for model training.

On the control plane: absorb campaign edits, new ads and policy verdicts as a change stream, fast enough to meet the freshness numbers below.

Requirements grouped into the 80 ms request path, the feedback loop and the control plane, with the four edges that connect them

What we're not building

Out of scope Why What we consume instead
Campaign management UI Advertisers' tooling, its own product and team A change stream from the campaign database
Creative review pipeline A separate system with human reviewers and its own SLAs Its verdicts: approved, rejected, taken down
Model training internals Architecture and training are a different interview Model versions to serve, plus our serve-time feature log as training input
Advertiser reporting dashboards Downstream analytics on the same events Nothing; we owe them correct, deduplicated events

Interviewer: "You've cut creative review. But if a scam ad shows up in Maya's feed, that's your problem, not theirs."

You: "Agreed, so the verdict is in scope even though the reviewer isn't. When review takes an ad down, serving has to stop within 10 seconds. That's a freshness requirement on us, whichever system makes the call."

Quick check before moving on:


Sign in to continue reading

The rest of this lesson is available with a free account. Signing in with Google or Microsoft is free.

Sign in to read the full lesson

Sign in to MAANG.io

Use your Google or Microsoft account — no password to remember.

Continue with Google Continue with Microsoft

Please accept the terms above to continue.