KatInterview

Design a Query-Driven Feed Ranking System with Ad Insertion

System DesignModel answer
HardModel answerSystem Designrankingadssearch

Last updated

Design a low-latency pipeline that blends organic search results with sponsored content, balancing user engagement and revenue at 50k QPS.

Query-Driven Feed Ranking with Sponsored Content

You are designing the backend ranking pipeline for a high-traffic mobile platform where users type queries and receive a blended feed of organic results (creators, videos, places) and paid advertisements. Your job is to architect the system end-to-end.

Scale and Constraints

  • Traffic: 50,000 queries per second at peak
  • Organic inventory: billions of documents; roughly 500M frequently updated items
  • Ad inventory: ~10M active creatives across ~1M campaigns
  • Latency: p99 server-side response under 200ms
  • Each response: ~20 ranked items per page, mixing organic and sponsored content

What You Need to Design

1. Pipeline Architecture Lay out the stages from raw query to final response. How do you structure retrieval, scoring, and blending? How do the organic and ad funnels relate to each other?

2. Multi-Objective Modeling Users care about relevance and engagement. The platform cares about revenue. How do you represent both in a model, what signals and features matter, and how do you handle the tension between them?

3. Auction and Pacing Mechanics Advertisers bid for placement. Campaigns have daily budgets. How do you score ads, run the auction, and prevent a campaign from blowing its budget in the first hour?

4. Mixing and Ad Load Once you have a ranked list of organic items and a ranked list of ads, how do you decide which slots get ads? What constraints protect the user experience?

5. Latency and Throughput Walk through your strategies for hitting the 200ms budget. Where does compute go and how do you stay under the limit at 50k QPS?

Treat this as a real design conversation: call out assumptions, discuss trade-offs, and flag where you'd run experiments rather than hard-code values.

Hints

Hint 1

Break the pipeline into two parallel funnels — organic and ads — that both start at query time, then merge at a late mixing stage. Each funnel should progressively shrink its candidate set by ~10x per stage so expensive models only score a small pool.

Hint 2

Ad ranking is not just about bid size. Think about what 'effective CPM' means across different campaign types (CPC vs. oCPM), and why predicted click and conversion probabilities need to be well-calibrated — not just accurate — since they directly determine prices.

Hint 3

Hard constraints in the mixer (no ad in slot 1 for navigational queries, minimum spacing between ads, per-session fatigue caps) are your safety net. They protect user experience even when the revenue-engagement trade-off weight λ is tuned aggressively.