Every time you open an app or a website, an invisible war happens.
Hundreds of advertisers compete โ and all of it ends in under 120 milliseconds.
Thatโs real-time bidding (RTB).
And Java? Still one of the best tools to power it.
โพ The Challenge
โพ Handle 1M+ bid requests per second (QPS)
โพ Complete auction logic, scoring, pricing, and response
โพ Maintain latency <100ms end-to-end
โพ Avoid revenue leaks from concurrency, GC, or network lag
โพ System Blueprint
1๏ธโฃ Ingress Layer (Bid Gateway)
Built using Netty or Vert.x โ lightweight, async, blazing fast.
Accepts OpenRTB 2.x / 3.x JSON bid requests from SSPs or exchanges.
Parses + validates payloads, then publishes to internal Kafka topic (bids.incoming).
2๏ธโฃ Enrichment & Targeting Service
Microservice in Spring Boot + Reactor or Micronaut.
Adds geo, device, user segments, campaign eligibility.
Fetches feature vectors from Redis or Aerospike in <10ms.
3๏ธโฃ Real-Time Auction Service (The Heart)
Written in Java with low-GC tuning (ZGC / Shenandoah).
Implements second-price (Vickrey) or first-price auctions.
Filters 1000+ bids โ sorts by eCPM โ applies business constraints (budget, pacing, frequency caps).
Uses in-memory priority queues or skip-lists for O(log n) selections.
Publishes the winning bid to Kafka (bids.won) and returns the ad markup immediately.
4๏ธโฃ Budget & Pacing Engine
Tracks spend per campaign / advertiser in Redis + Kafka Streams.
Prevents overspending by reserving budgets atomically.
Supports real-time pacing (budget/time) with leaky bucket logic.
5๏ธโฃ Analytics & Feedback Loop
Impression, click, conversion events flow into Kafka โ Flink for aggregation.
ML models update bid multipliers in near-real time (CTR, CVR predictions).
Model outputs stored in feature store (Feast / Redis / Cassandra).
โพ Key Tech Stack
Java 21 (virtual threads for concurrency)
Spring Boot / Micronaut / Quarkus for microservices
Kafka + Flink for streaming and feedback
Redis / Aerospike for ultra-low latency key lookups
gRPC for internal service calls
ClickHouse / Pinot for analytics
Prometheus + Grafana + OpenTelemetry for observability
โพ Performance Tricks
โพ Keep auction logic pure in-memory โ no DB calls on critical path
โพ Use object pooling to avoid GC pauses
โพ Co-locate data (geo + campaign data in RAM)
โพ Batch outbound responses using Netty channels
โพ Fraud detection hooks every 10ms (bot, domain spoofing, invalid traffic)
โพ Fail open (show fallback ad) โ never blank screen
๐ก Takeaway:
The fastest ad auction wins the dollar.
Java still dominates here , not because itโs fancy, but because itโs predictable, tunable, and fast.
Top comments (0)