
Eliminating database bottlenecks on the ad-serving critical path through stateful stream processing with Apache Flink
This article details how Netflix evolved its Ads Event Publisher pipeline to support massive live streaming events like NFL games and fight nights. By moving away from synchronous database writes and adopting real-time streaming joins in Apache Flink, Netflix achieved elastic scalability, lower serving latency, and high system reliability.
Essential reading for backend and data platform engineers looking to migrate high-throughput synchronous database architectures to stateful, real-time stream processing systems.
Netflix's legacy ads enrichment pipeline relied on the ad server writing metadata synchronously to a Key-Value store on the serving path. Under live streaming events with tens of millions of concurrent viewers, this synchronous write pattern created a massive scaling bottleneck and posed a single point of failure risks on the ad serving critical path.
Netflix replaced the synchronous database lookup with a stateful stream processing architecture using Apache Flink. By streaming both ad serving responses and client events through Kafka, Flink performs a real-time streaming join using a KeyedCoProcessFunction within a 60-minute retention window, backed by a Spark batch job orchestrated by Maestro for long-tail event recovery.
The team completely eliminated database write dependencies from the ad serving critical path, removing scaling bottlenecks for live events. Through shadow testing and automated audits, they verified over 99.99% output consistency before smoothly decommissioning the legacy registry and service without downtime.
Trade-off
Restricting the in-memory state window to 60 minutes means that late-arriving long-tail events (~0.001%) cannot be enriched in real time and must rely on an offline Spark batch recovery path, introducing slight processing latency for edge cases.
A stream processing technique that combines events from two distinct data streams in real time based on a shared key, eliminating the need for intermediate database lookups.
A low-level stateful operator in Apache Flink that allows granular control over state retention and timers across two keyed streams.
A system design pattern ensuring event delivery at least once while performing in-stream deduplication via localized state, leaving exact deduplication to downstream consumers with longer time windows.









