Design a Sponsored Product Ads Ranking Pipeline
Design the end-to-end pipeline that picks, ranks, prices and learns from sponsored product ads shown inside grocery search and category pages.
Problem statement
For this exercise, assume a grocery delivery marketplace lets brands pay to promote their products. A shopper picks a store, then searches (for example "oat milk") or browses a category page. Next to the organic results, the page has up to four sponsored slots. Each sponsored ad is one campaign promoting one product.
A campaign has a daily budget, a cost-per-click bid, and the keywords and categories it targets.
Design the ads pipeline end to end: find candidate ads for the request, drop ads that are not eligible (paused, out of budget, or for a product that is out of stock at the shopper's store), predict how likely the shopper is to click and to buy, rank and price the ads in an auction, and record impressions, clicks and purchases so the models keep learning.
Explain which model each stage uses and what loss it is trained with. The auction ranks ads by bid times predicted click probability.
A winner pays per click the second-price amount: the lowest bid that would still keep its position, which is the next ad's score divided by the winner's own predicted click probability, at least a reserve price and never more than its own bid.
Because both ranking and price use the predicted probability as a number, it must be calibrated, not just well ordered.
Before the auction, an ad must also clear a relevance floor: its predicted chance of a purchase per impression (predicted click probability times predicted purchase-after-click probability) must be at least a floor set per surface, so a high bid alone cannot buy a slot for a product shoppers rarely buy.
New ads and new products start with no history. For this exercise, assume the organic search ranking already exists as a separate service and is out of scope; the page places your ads in its fixed sponsored slots.
Advertiser campaign tools, invoicing, fraud detection beyond duplicate events, and spreading a budget evenly across the day are also out of scope.
What to build
- For a search or category request at the shopper's selected store, return up to four sponsored product ads that are relevant and in stock at that store, with a decision ID, or return no ads.
- Rank eligible ads by bid times calibrated predicted click probability, drop ads whose predicted purchase chance per impression is below the relevance floor, and charge each winner per click the second-price amount, at least the reserve and never more than its bid.
- Record impressions, clicks and purchases against the exact decision that showed the ad, charge each click once, attribute purchases within 7 days, and stop a campaign when its daily budget is used up.
- Build training data from logged decisions and outcomes, train, evaluate and calibrate the retrieval and prediction models, release new versions safely, and give new ads a fair chance without history.
At scale
- For this exercise, assume 30,000 ad requests per second at peak, 5 million active ads (campaign and product pairs), and up to 1,000 retrieved candidates per request, which is about 30 million candidate scores per second before any ranking stage narrows the set.
- For this exercise, assume the ad decision must return within 80 milliseconds at p99; if it cannot, the page shows organic results with no ads instead of waiting.
- For this exercise, assume stock at a store can change at any time, and an ad must stop showing at a store within 5 minutes after its product goes out of stock there.
- For this exercise, assume clicks arrive within seconds, purchases arrive up to 7 days after the click, each click is charged once, delivered clicks may exceed a daily budget by at most 2 percent, and an advertiser is never billed above its budget.