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

Design an AdTech CTR Prediction &
Real-Time Bidding Engine (500K QPS).

Design a globally distributed AdTech DSP capable of handling 500K OpenRTB QPS at <50ms internal p99 latency, with Aerospike feature lookups, batched TensorRT CTR scoring, Redis budget pacing, and streaming FTRL updates.
Start the journey7 stages· Last modified Nov 24, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

To keep the architecture evolvable without sacrificing reliability, colocate stateless bidder PoPs near Ad Exchanges, use Aerospike NVMe/RAM for sub-2ms feature reads, and decouple online learning via Kafka and Flink.

TL;DR30-second simplified summary
▾

At 500K QPS, edge colocation saves network RTT, Aerospike HMA stores 1B profiles cheaply, and 2ms TensorRT micro-batching maximizes GPU throughput.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
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.
Full walkthrough · 7 stages
01
foundation

500K QPS Scale & Regional Edge Sizing.

Why this matters: Size regional bidder PoPs, Aerospike IOPS, and network bandwidth.

500K QPS split across 4 global exchange regions equals ~125K QPS per region.

With ~4 KB per OpenRTB request, ingress is 500 MB/s per region.

Scale & Sizing

500K QPS Multi-Region Bidder Sizing

Global Ad ExchangesTraffic source4 Regional BidderPoPsEdge computeAerospike LocalClusterFeature storeL4/T4 InferencePoolCTR scorerFetches user/ad state

1.Regional Isolation: Each PoP operates autonomously; a regional outage never takes down global bidding.

2.Early Load Shedding: Drop low-floor or stale (>20ms queued) BidRequests before GPU scoring.

Colocating 4 regional PoPs keeps network RTT low and isolates regional traffic spikes.

02
foundation

Bidder Edge Request Lifecycle.

Why this matters: Trace the <50ms synchronous pipeline from BidRequest to BidResponse.

Think of Bidder Edge Request Lifecycle as the intuition layer for Design an AdTech CTR Prediction & Real-Time Bidding Engine (500K QPS): Trace the <50ms synchronous pipeline from BidRequest to BidResponse.

On arrival, the Bidder Edge validates tmax, queries Aerospike for user segments and frequency caps, runs an in-memory Roaring Bitmap targeting index to pick <=50 eligible ads, scores them in one TensorRT batch, shades the top bid, and checks the Redis token-bucket pacer.

Synchronous Path

50ms Bidder Edge Execution Flow

OpenRTB ParserIngress gateAerospike LookupState fetchRoaring BitmapIndexTargeting filterCTR + Shade + PacerBid emitterApplies frequency caps

1.In-Memory Targeting: Roaring Bitmaps intersect geo, device, and OS targeting in <0.5ms.

2.Graceful NO_BID: Returning HTTP 204 NO_BID cleanly is always better than timing out.

Bitset targeting and sub-3ms Aerospike reads leave ample headroom for TensorRT scoring.

Engineering Decision Framework
Problem
How to implement Design an AdTech CTR Prediction & Real-Time Bidding Engine (500K QPS) 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
To keep the architecture evolvable without sacrificing reliability, colocate stateless bidder PoPs near Ad Exchanges, use Aerospike NVMe/RAM for sub-2ms feature reads, and decouple online learning via Kafka and Flink.
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 Design an AdTech CTR Prediction & Real-Time Bidding Engine (500K QPS) experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

03
intermediate

Aerospike Hybrid Memory Architecture.

Why this matters: Serve 500K QPS user profiles and frequency caps at <2ms p99 without huge RAM bills.

Think of Aerospike Hybrid Memory Architecture as the intuition layer for Design an AdTech CTR Prediction & Real-Time Bidding Engine (500K QPS): Serve 500K QPS user profiles and frequency caps at <2ms p99 without huge RAM bills.

Storing 1B user profiles purely in Redis RAM would cost millions. Aerospike's Hybrid Memory Architecture (HMA) keeps primary 64-byte index pointers in DRAM while reading 1 KB user payloads directly from local NVMe SSDs in <1.5ms p99.

Low-Latency Storage

Aerospike DRAM Index + NVMe Payload Store

Bidder AerospikeClient1-hop lookupDRAM Primary IndexZero disk seekLocal NVMe SSDs1B user profilesAnonymous FallbackTail guardSingle NVMe read

1.5x Lower Cost: DRAM index + NVMe data cuts infrastructure cost by ~75% vs pure Redis.

2.1-Hop Routing: Partition maps in the client eliminate proxy hops.

Aerospike HMA delivers Redis-like sub-2ms reads at NVMe storage economics.

04
intermediate

Distributed Token-Bucket Budget Pacing.

Why this matters: Enforce strict daily spend caps across 65 regional pods without overspending.

Think of Distributed Token-Bucket Budget Pacing as the intuition layer for Design an AdTech CTR Prediction & Real-Time Bidding Engine (500K QPS): Enforce strict daily spend caps across 65 regional pods without overspending.

If 65 pods each check Redis on every bid, Redis sees 500K write OPS. Instead, pods lease small local budget chunks (e.g., $2.00 every 5 seconds) from a regional Redis Token-Bucket Pacer, allowing zero-network-hop local spend checks.

Budget Pacing

Hierarchical Redis-to-Pod Budget Leasing

Regional RedisPacerGlobal allocator5s Pod Budget LeaseLock-free localBidder Pod CheckSynchronous gateWin-PriceReconcilerExact accountingAuthorizes bid

1.Zero Sync Overhead: Bidders never block on Redis during the 50ms auction path.

2.Bounded Overspend: Max theoretical overspend is capped at 1 lease cycle across active pods.

Micro-budget leasing removes Redis from the critical bidding path while bounding overspend.

05
intermediate

Batched ONNX / TensorRT CTR Inference.

Why this matters: Score 50 candidate ads per request in under 10ms using dynamic GPU batching.

Think of Batched ONNX / TensorRT CTR Inference as the intuition layer for Design an AdTech CTR Prediction & Real-Time Bidding Engine (500K QPS): Score 50 candidate ads per request in under 10ms using dynamic GPU batching.

Ad requests arrive at 2.5K QPS per pod, each needing 50 ad scores (125K scores/sec/pod). Dynamic micro-batching accumulates requests for 2ms (grouping ~5 requests = 250 ads) into one TensorRT FP16 forward pass, achieving <8ms p99 scoring latency.

Inference Engine

2ms Dynamic Micro-Batch TensorRT Pipeline

Lock-Free BatchQueueRequest coalescerEmbedding CacheZero-copy lookupTensorRT FP16EngineDCNv2 scorerIsotonic CalibratorpCTR outputRuns fused MLP/Cross

1.2ms Coalescing: Waiting 2ms triples GPU utilization while keeping p99 under 8ms.

2.VRAM Pinning: Hot ad embeddings stay pinned in GPU VRAM to avoid PCIe transfers.

Dynamic 2ms micro-batching and pinned VRAM embeddings maximize GPU inference efficiency.

06
advanced

Kafka Joiner & Flink Online Learning Loop.

Why this matters: Close the 60-second online learning loop from impressions to Parameter Server.

Think of Kafka Joiner & Flink Online Learning Loop as the intuition layer for Design an AdTech CTR Prediction & Real-Time Bidding Engine (500K QPS): Close the 60-second online learning loop from impressions to Parameter Server.

Win notices, impressions, and IVT-scrubbed clicks stream into Kafka. Flink joins them by auction_id, computes mini-batch gradients, and pushes sparse FTRL updates to a sharded Parameter Server, which streams compact weight deltas to regional bidders every 60s.

Online Learning

Kafka -> Flink -> Parameter Server 60s Sync

Kafka Win/Imp/ClickEvent backboneFlink AttributionJoinStream joinerParameter ServerModel master60s Delta PushWeight distributorSends labeled gradients

1.Atomic Hot-Swap: Double-buffered weight tables swap pointers without pausing inference.

2.Version Guard: Monotonic version checks prevent out-of-order delta regressions.

A 60-second streaming learning loop keeps CTR weights aligned with live user behavior.

07
advanced

Graceful Degradation & Model Rollback.

Why this matters: Survive GPU failures, Aerospike blips, or bad model weight pushes without losing revenue.

Think of Graceful Degradation & Model Rollback as the intuition layer for Design an AdTech CTR Prediction & Real-Time Bidding Engine (500K QPS): Survive GPU failures, Aerospike blips, or bad model weight pushes without losing revenue.

If a bad online weight push causes predicted CTR to spike 3x (triggering budget burn), an automated Watchdog immediately rolls back the Parameter Server pointer to the last known-good hourly checkpoint. If GPUs saturate, bidders fall back to a lightweight CPU logistic regression model.

Resilience

Automated Weight Watchdog & CPU Fallback

Spend & pCTRWatchdogSafety monitorCheckpoint RollbackModel guardCPU LogisticFallbackGPU bypassBid-Floor ShedderOverload shieldSwitches on GPU timeout

1.Auto-Rollback: Reverting to an hourly checkpoint stops runaway spend within 10 seconds.

2.Linear Fallback: A CPU FTRL model keeps bidding profitably even if all GPUs throttle.

Automated spend watchdogs and CPU linear fallbacks protect revenue under failure.

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

Why is Aerospike Hybrid Memory Architecture (DRAM index + NVMe data) preferred over pure in-memory Redis for storing 1B user profiles at 500K QPS?

Recommended Learning Flow