Preparing your design workspace

Loading the problem and your latest saved attempt…

Design an Ad Marketplace for Publisher Websites

Sell ad slots on publisher pages to outside ad providers through real-time auctions, return the winning ad fast, and charge every rendered ad exactly once without letting a provider spend past its daily budget.

Problem statement

Design a marketplace where websites sell the ad space on their pages to outside ad providers through real-time auctions.

For this exercise, assume publishers register their sites and the ad slots on their pages. Each slot has a size and a floor price, and a publisher can block categories of advertisers.

Ad providers register a bidding endpoint, the slots they want (sizes, countries, device types and site categories), the most bid requests per second they accept, and one daily budget with the marketplace. Providers run their own campaigns; the marketplace sees only their bids.

When a page loads, its ad code asks the marketplace for an ad for one slot. The marketplace chooses which providers may bid, sends them a bid request, and waits at most 100 ms for answers. A bid gives a price per thousand impressions and an approved creative.

The highest bid at or above the slot's floor wins and pays its own bid (a first-price auction); with no such bid the slot gets no ad. The page shows the winning creative and then reports that the ad rendered.

Assume a provider is charged only for ads that actually render: each rendered ad costs its winning price divided by 1,000. A render report counts only if it reaches the marketplace within 10 minutes of its auction, and each auction can be charged at most once, even if the report is sent again.

The page's ad code may retry an ad request with the same request ID within a few seconds; a retry must never lead to two charges for one slot view. A provider's daily budget resets at 00:00 UTC, each charge counts toward the day of its auction, and spend for a day may exceed that day's budget by at most 1%.

The publisher earns 80% of every charge and the marketplace keeps 20%. Providers and publishers can see their spend and earnings.

Creative review, fraud and bot detection beyond rejecting forged or repeated render reports, user tracking, the providers' own campaign tools, and invoicing or bank payouts are out of scope. You may use any technologies you like.

What to build

  1. Publishers register sites and ad slots with sizes, floor prices and blocked advertiser categories; ad providers register a bidding endpoint, targeting, a request-rate cap and a daily budget.
  2. For each ad request, send bid requests only to providers whose targeting and rate cap fit and who still have budget, collect bids for at most 100 ms, and pick the highest bid at or above the floor.
  3. Return the winning approved creative with a way to report that it rendered, or return no ad.
  4. Charge each rendered ad once at its winning price, keep each provider's daily spend within 1% of its budget, credit the publisher 80% of each charge, and show both sides their spend and earnings.

At scale

  • For this exercise, assume about 20,000 publisher sites and 300 ad providers; ad requests peak at about 200,000 a second, and each request is sent to about 10 providers on average.
  • For this exercise, assume the page must get its answer within 150 ms at the 99th percentile, and providers that have not answered after 100 ms are left out of that auction.
  • For this exercise, assume about 100,000 rendered ads a second at peak and about 3 billion a day, at a typical price of $2 per thousand. Daily budgets range from $100 to $1,000,000, and spend and earnings appear in reports within 5 minutes.