Abdullah Al Mamun
Ad Tech
Ad TechOpenRTBGo

Building an OpenRTB-Compliant Ad Exchange

OpenRTB is a 50-page spec that looks simple until you're debugging a bid response that's technically valid but semantically wrong. Here's what I learned building a compliant exchange.

AA

Abdullah Al Mamun

May 10, 2024 · 10 min read

What OpenRTB Actually Is

OpenRTB (Open Real-Time Bidding) is a protocol for programmatic advertising auctions. A publisher sends a bid request to multiple DSPs (demand-side platforms). DSPs respond with bids. The exchange picks a winner and notifies the DSPs.

The spec is maintained by the IAB Tech Lab and is currently at version 2.6. It's a JSON-over-HTTP protocol with a lot of optional fields and a lot of room for interpretation.

The Bid Request

A bid request describes the ad opportunity: the publisher, the user (anonymized), the ad slot dimensions, and the floor price.

{
  "id": "auction-123",
  "imp": [{
    "id": "1",
    "banner": { "w": 300, "h": 250 },
    "bidfloor": 0.50,
    "bidfloorcur": "USD"
  }],
  "site": { "domain": "example.com" },
  "user": { "id": "user-hash-abc" }
}

The Auction Mechanics

We run a second-price auction (Vickrey auction). The highest bidder wins but pays the second-highest price plus $0.01. This incentivizes DSPs to bid their true value.

The auction must complete within 100ms — this is the industry standard timeout. DSPs that don't respond in time are excluded from the auction.

The Hard Parts

Bid response validation. The spec allows many optional fields, but some combinations are invalid. A bid with a price below the floor is technically valid JSON but should be rejected. We built a validation layer that catches these semantic errors.

Win notification. The winning DSP must be notified via a win notice URL. This URL is provided in the bid response and must be called asynchronously after the ad is served. Getting this wrong means DSPs don't know their bids won, which breaks their optimization algorithms.

Loss notification. OpenRTB 2.6 added loss notifications — telling losing DSPs why they lost (price, policy, etc.). This is optional but DSPs love it because it helps them tune their bidding.

Currency handling. DSPs bid in different currencies. We normalize everything to USD at auction time using exchange rates cached from an external API. Stale exchange rates can cause pricing errors.

What I'd Do Differently

The bid request/response serialization is on the critical path. I'd invest more in optimizing JSON marshaling — potentially using a code-generated serializer instead of encoding/json for the hot path.