# Machine-learning predictive autoscaling for Flink

[Grab](https://yomu.fyi/company/grab) · Minh Nhat Nguyen · Oct 30, 2025

## Summary

Managing resource allocations for expanding Apache Flink stream-processing workloads often leads to over-provisioning or unstable reactive scaling. Reactive autoscaling with Kubernetes Horizontal Pod Autoscaling triggers severe restart spikes because pipelines must reprocess backlogged records from checkpoints, inducing feedback loops and scaling fluctuations. To prevent these spirals, a predictive vertical autoscaling system uses upstream Kafka message throughput as an independent workload metric. The architecture forecasts future workload using time-series models and maps the projected throughput to required TaskManager CPU allocations through a trained regression model. A custom controller vertically scales TaskManager CPU resources before traffic changes arrive, avoiding restart-induced latency spikes.

## Takeaways

- Reactive autoscaling in Flink triggers performance spirals because restarting from checkpoints causes immediate CPU and consumer latency surges to process backlogged source data.
- Horizontal autoscaling for Kafka-backed Flink applications is strictly constrained by source topic partition counts, making vertical CPU scaling essential once consumer parallelism limits are reached.
- Predictive vertical autoscaling maps time-series throughput forecasts directly to CPU needs using a regression model trained solely on metrics from stable, unconstrained pipeline runs.

**Tags:** [Kafka](https://yomu.fyi/topic/kafka), [Kubernetes](https://yomu.fyi/topic/kubernetes), [Machine Learning](https://yomu.fyi/topic/machine-learning), [Scalability](https://yomu.fyi/topic/scalability), [Streaming](https://yomu.fyi/topic/streaming)

[Read original post](https://engineering.grab.com/ml-predictive-autoscaling-for-flink)
