This article details Netflix's journey with Apache Flink autoscaling, highlighting their transition from a custom-built external autoscaler to adopting and extending the open-source Apache Flink Autoscaler. It explores the architectural limitations of their initial approach, the benefits of an internal, operator-aware scaling mechanism, and the engineering challenges and solutions encountered when scaling the open-source solution to Netflix's massive Flink fleet.
Read original on Netflix Tech BlogNetflix operates over 30,000 Apache Flink jobs, necessitating robust autoscaling to manage fluctuating loads efficiently and cost-effectively. Static provisioning for peak load is wasteful, while provisioning for average load leads to performance lags during surges. A critical challenge is that Flink scaling involves taking a savepoint, stopping, and restarting the job, which can take several minutes for large stateful jobs, making rapid scaling difficult and impacting availability. This context frames the fundamental requirement for intelligent and reliable autoscaling.
Netflix's first autoscaler, built around 2019, operated externally, consuming cluster-level metrics from Atlas (CPU, network, Kafka lag, etc.). It functioned as a streaming job on Mantis, scaling out easily to handle more Flink jobs. While this system reduced resource usage by 25-45% for simple pipelines, it had significant limitations:
The open-source Apache Flink Autoscaler offers a more sophisticated approach by reasoning *from inside* the Flink job. Its core idea is to estimate each operator's True Processing Rate (TPR) – the throughput an operator could sustain if fully busy. By dividing observed throughput by the 'busy fraction' (time spent doing actual work), it extrapolates capacity to full utilization. This allows it to compute the required parallelism for *each operator vertex* in the job graph, preventing single-operator bottlenecks rather than resizing the entire cluster uniformly.
Metric Choice Matters
A key takeaway from Netflix's experience is that the choice of metrics is more critical than the sophistication of the scaling algorithm itself. Accurate, internal metrics like 'busy fraction' provide a much better signal for intelligent scaling decisions than external, aggregate resource utilization.
While the community provided the core logic, integrating and scaling the OSS autoscaler to Netflix's environment required significant engineering, particularly since Netflix's Flink platform uses its own control plane, not the Kubernetes Operator for Flink. They leveraged the autoscaler's refactored generic interfaces (context, state store, event handler, realizer) to plug it into their internal ecosystem.
The OSS-based autoscaler achieved significant cost savings (e.g., 58% reduction, $1.1M annually for one team) by dynamically adapting to load, continuous optimization, and enabling better bin-packing. Netflix also tuned the target utilization (0.45 vs. default 0.7) to prioritize stability over aggressive efficiency for large stateful jobs, accepting marginal cost for fewer, calmer rescales. Future plans include leveraging Flink 2's disaggregated state architecture to reduce state recovery bottlenecks during scaling events, further improving scaling performance and cost efficiency.