Skip to main content
← CONCEPTS / SYSTEM-DESIGN
An end-to-end domain learning journey

Real-Time Bidding (RTB), CTR
Calibration & Bid Shading.

Real-Time Bidding (RTB) & CTR Calibration converts raw neural click probabilities into profitable first-price auction bids within a strict 100ms OpenRTB round-trip.
Start the journey7 sections· Last modified Nov 24, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When a user loads a webpage, the SSP/Ad Exchange broadcasts an OpenRTB JSON/Protobuf BidRequest with tmax=100ms, in first-price auctions, an uncalibrated CTR model or naive expected-value bid overpays dramatically; you must calibrate pCTR (Isotonic/Platt) and apply bid shading.

TL;DR30-second simplified summary
▾

To win programmatic auctions profitably, recalibrate downsampled CTR outputs with log-odds/isotonic regression, apply first-price bid shading, and pace spend via a 10-second PID loop.

Full walkthrough · 7 stages
01
foundation

OpenRTB Auction Mechanics & 100ms Budget.

Why this matters: Understand the end-to-end OpenRTB protocol flow and strict timeout penalties.

Think of OpenRTB Auction Mechanics & 100ms Budget as the intuition layer for Real-Time Bidding (RTB), CTR Calibration & Bid Shading: Understand the end-to-end OpenRTB protocol flow and strict timeout penalties.

When a user loads a webpage, the SSP/Ad Exchange broadcasts an OpenRTB JSON/Protobuf BidRequest with tmax=100ms. Any DSP response arriving after 100ms is silently dropped (0% win rate), making tail latency directly equal to lost revenue.

OpenRTB Protocol

OpenRTB 100ms Round-Trip Timeline

Ad Exchange / SSPAuction hostNetwork RTT (~25ms)Transport overheadDSP Bidder (50ms)Decision engineBidResponse / DropAuction outcomeRoutes to nearest PoP

1.Zero-Grace Cutoff: Responses at 101ms earn zero impressions regardless of bid price.

2.Edge Colocation: Deploying bidder PoPs near Ad Exchange regions saves 20-40ms RTT.

Regional edge colocation and strict internal timeouts keep DSPs inside the 100ms OpenRTB window.

02
foundation

Expected Value & Negative Downsampling Correction.

Why this matters: Convert downsampled model outputs into true calibrated click probabilities.

Click rates are tiny (~0.5%–2%).

To speed up training, negative (non-click) impressions are downsampled by rate w (e.g., 0.1).

Probability Calibration

Negative Downsampling Log-Odds Correction

Imbalanced LogsRaw distribution10% Neg DownsamplingFast trainingLog-Odds + IsotonicCalibration layereCPM CalculatorTrue valuationApplies w=0.1 prior shift

1.10x Overbid Hazard: Forgetting the w=0.1 correction inflates CPC bids by nearly 10x.

2.Isotonic Calibration: Non-parametric isotonic regression fixes non-linear neural score distortion.

Log-odds prior correction and isotonic calibration turn neural scores into true probabilities.

Engineering Decision Framework
Problem
How to implement Real-Time Bidding (RTB), CTR Calibration & Bid Shading without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
When a user loads a webpage, the SSP/Ad Exchange broadcasts an OpenRTB JSON/Protobuf BidRequest with tmax=100ms, in first-price auctions, an uncalibrated CTR model or naive expected-value bid overpays dramatically; you must calibrate pCTR (Isotonic/Platt) and apply bid shading.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Real-Time Bidding (RTB), CTR Calibration & Bid Shading experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

03
intermediate

First-Price Auctions & Bid Shading.

Why this matters: Maximize advertiser ROI by bidding just above the expected clearing price.

In second-price auctions, bidding true value v was optimal.

In modern first-price auctions, you pay what you bid.

Auction Theory

First-Price Bid Shading Optimization

True eCPM Value (v)Upper boundWin-Rate CDF ModelMarket estimatorSurplus MaximizerBid shaderShaded Bid (b*)Auction bidProvides P(win | b)

1.Floor Enforcement: Never shade below the publisher's hard bidfloor or auction fails.

2.Surplus Gain: Balancing win-rate drop against CPM savings boosts net conversions per dollar.

Bid shading maximizes advertiser surplus by predicting the minimum winning bid in first-price auctions.

04
intermediate

Budget Pacing & Throttling.

Why this matters: Spread daily campaign budgets smoothly across 24 hours without premature exhaustion.

Without pacing, a $10K daily campaign can burn out in 15 minutes of cheap midnight traffic.

A probabilistic PID controller adjusts each campaign's participation rate p_pace(t) every 10 seconds based on target vs.

Spend Control

PID Probabilistic Budget Pacer

Win NotificationStreamSpend sensorRedis Spend CountersGlobal ledgerPID PacingControllerRate adjusterProbabilistic GateSmooth deliveryCompares vs time curve

1.Probabilistic vs Hard Cap: Probabilistic pacing preserves high-CTR inventory later in the day.

2.10s Sync Lag: Local bidder caches sync spend from Redis every 10s to avoid per-bid locks.

A distributed PID controller paces campaign spend smoothly across peak and off-peak hours.

05
intermediate

Delayed Attribution & Streaming Joiners.

Why this matters: Join bid requests, win notices, impressions, and delayed clicks in Flink.

Think of Delayed Attribution & Streaming Joiners as the intuition layer for Real-Time Bidding (RTB), CTR Calibration & Bid Shading: Join bid requests, win notices, impressions, and delayed clicks in Flink.

A bid request occurs at t=0, win notice at t=50ms, impression pixel at t=500ms, and click at t=10s–24h. Flink maintains a RocksDB interval-join keyed by auction_id across a 2-hour window, emitting negative samples on timeout and positive samples on click.

Attribution

Flink Multi-Event Auction Attribution Joiner

Bid & Win EventsFeature anchorImpression PixelExposure confirmClick / ConversionPositive labelFlink Interval JoinLabel emitterStarts attribution timer

1.Zero Leakage: Features are frozen at bid time (t=0), never re-read at click time.

2.Timer Expiry: Unclicked impressions emit label=0 once the attribution timer expires.

Flink interval joins correlate asynchronous bid, impression, and click streams by auction_id.

06
advanced

FTRL-Proximal Online Learning.

Why this matters: Update sparse ad-ID and publisher-ID weights in real time within minutes.

Think of FTRL-Proximal Online Learning as the intuition layer for Real-Time Bidding (RTB), CTR Calibration & Bid Shading: Update sparse ad-ID and publisher-ID weights in real time within minutes.

New ad creatives launch constantly and need rapid CTR adaptation. FTRL-Proximal (Follow-The-Regularized-Leader) with L1+L2 regularization updates sparse embedding tables online via Parameter Servers, driving irrelevant feature weights to exact zero for compact memory.

Online Learning

FTRL-Proximal Sparse Weight Updates

Attributed LabelsGradient sourceParameter ServerModel stateFTRL-Proximal StepOptimizerDelta Weight PushLive updateUpdates z and n accumulators

1.Exact L1 Sparsity: FTRL zeros out noisy cross-features, keeping sparse tables under 10 GB.

2.60s Freshness: New ad creatives converge to accurate pCTR within minutes of launch.

FTRL-Proximal delivers fast online convergence while keeping sparse feature tables compact.

07
advanced

Click Fraud & Invalid Traffic (IVT) Filtering.

Why this matters: Prevent bots and click-farms from draining advertiser budgets and poisoning CTR models.

Think of Click Fraud & Invalid Traffic (IVT) Filtering as the intuition layer for Real-Time Bidding (RTB), CTR Calibration & Bid Shading: Prevent bots and click-farms from draining advertiser budgets and poisoning CTR models.

Botnets generate fake clicks that distort both billing and online learning gradients. A streaming IVT detector flags headless browsers, datacenter ASN bursts, and sub-100ms click-after-impression anomalies before clicks enter billing or FTRL training.

Fraud Defense

Pre-Billing & Pre-Training IVT Gate

Raw Click StreamUnfiltered inputAuction DeduplicatorReplay guardIVT Rules & ASNCheckBot filterClean AttributionBusTrusted signalEvaluates bot heuristics

1.Model Poisoning Guard: Filtering IVT before FTRL prevents models from learning to target bots.

2.Zero-Cost Drop: Invalid clicks are excluded from advertiser billing automatically.

Scrubbing duplicate and bot clicks before attribution protects both billing and model weights.

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

You train a DeepFM CTR model with 10% negative downsampling (w=0.1) and deploy it directly to a first-price auction without recalibration. What happens?

Recommended Learning Flow