MongoDB

Designing a Real-Time Bidding Auction System

Deep dive into programmatic real-time bidding infrastructure — SSP/DSP communication, bid caching, pacing, win rate optimization, and auction latency.

S

srikanthtelkalapally888@gmail.com

Real-time bidding requires decisions in under 100 milliseconds — combining ML inference, data lookups, and network round trips.

Auction Timeline

0ms:    User loads page, ad slot detected
10ms:   SSP sends bid request to exchange
20ms:   Exchange fans out to 50+ DSPs
80ms:   Bid deadline — DSPs must respond
85ms:   Exchange selects winner (first/second price)
95ms:   Winner notified, ad creative fetched
200ms:  Ad rendered (before user sees page fully)

DSP Bidding Infrastructure

Bid Request received:
    ↓
User Lookup (Redis, <5ms)
  → User segment membership
  → Frequency cap check
  → Geo + device data
    ↓
Campaign Matching (<10ms)
  → Find eligible campaigns
  → Targeting criteria match
    ↓
Bid Price Calculation (<5ms)
  → ML model (CTR prediction × CPM)
  → Budget pacing check
    ↓
Bid Response → Exchange

Bid Caching

Problem: 1M bid requests/sec → Too many ML inferences

Solution: Cache bid decisions per user segment
  segment:sports_fans → bid $2.50
  segment:auto_intenders → bid $4.00

Refresh cache every 5 minutes
Reduce ML inference by 90%

Budget Pacing

Campaign: $10,000/day budget

Naive: Spend all money in first 2 hours
Pacing: Distribute spend evenly across day

Throttle rate = (remaining_budget / remaining_time) / avg_cpm

Redis token bucket per campaign:
  IF tokens available: bid
  ELSE: skip this auction

Win Rate Optimization

Bid too low → Never win, zero impressions
Bid too high → Win everything, overpay
Optimal → Win target % at target CPM

ML bid shading:
  Predict clearing price
  Bid clearing_price + $0.01 (just enough to win)
  Reduces overpayment significantly

Loss Notification

Win:  Charge advertiser, serve ad, track impression
Loss: Log reason (outbid, targeting mismatch)
       → Feed into bid optimization model

Conclusion

RTB systems run the most demanding real-time ML inference at scale. Bid caching, budget pacing, and bid shading are the key optimizations for efficiency and ROI.

Share this article