Horizontal Autoscaling Stay organized with collections Save and categorize content based on your preferences.
Horizontal Autoscaling enables Dataflow to choose the appropriatenumber of worker instances for your job, adding or removing workers as needed.Dataflow scales based on the average CPU utilization of theworkers and on the parallelism of a pipeline. The parallelism of a pipeline isan estimate of the number of threads needed to most efficiently process data atany given time.
Horizontal Autoscaling is supported in both batch and streaming pipelines.
Batch autoscaling
Horizontal Autoscaling is enabled by default on all batch pipelines.Dataflow automatically chooses the number of workers based on theestimated total amount of work in each stage of your pipeline. This estimatedepends on the input size and the current throughput. Every 30 seconds,Dataflow re-evaluates the amount of work according to theexecution progress. As the estimated total amount of work increases ordecreases, Dataflow dynamically scales the number of workers up ordown.
The number of workers is sublinear to the amount of work. For example, a jobwith twice the work has fewer than twice the workers.
If any of the following conditions occur, Dataflow eithermaintains or decreases the number of workers, in order to save idle resources:
- The average worker CPU usage is lower than 5%.
- Parallelism is limited due to unparallelizable work, such as un-splittabledata caused by compressed files or I/O modules that don't split.
- The degree of parallelism is fixed, for example when writing to existingfiles in Cloud Storage.
To set an upper bound on the number of workers, set the--maxNumWorkers pipeline option.The default value is2,000.To set a lower bound on the number of workers, set the--dataflow-service-options=min_num_workers service option.These flags are optional.
Streaming autoscaling
For streaming jobs, Horizontal Autoscaling allows Dataflow toadaptively change the number of workers in response to changes in load andresource utilization.
Horizontal Autoscaling is enabled by default for streaming jobs that useStreaming Engine.To enable Horizontal Autoscaling for streaming jobs that don't useStreaming Engine, set the followingpipeline options when you startyour pipeline:
Java
--autoscalingAlgorithm=THROUGHPUT_BASED--maxNumWorkers=MAX_WORKERSReplaceMAX_WORKERS with the maximum number of workerinstances.
Python
--autoscaling_algorithm=THROUGHPUT_BASED--max_num_workers=MAX_WORKERSReplaceMAX_WORKERS with the maximum number of workerinstances.
Go
--autoscaling_algorithm=THROUGHPUT_BASED--max_num_workers=MAX_WORKERSReplaceMAX_WORKERS with the maximum number of workerinstances.
To set a lower bound on the number of workers, set the--dataflow-service-options=min_num_workers service option.When you set this value, horizontal autoscaling doesn't scale below the numberof workers specified. This flag is optional.
While a streaming job is running, you can update the minimum and maximum workersby using anin-flight job update.To adjust the settings, set themin-num-workers andmax-num-workers flags.For more information, seeUpdate the autoscaling range.
Disable Horizontal Autoscaling
To disable Horizontal Autoscaling, set the followingpipeline option when you runthe job.
Java
--autoscalingAlgorithm=NONEIf you disable Horizontal Autoscaling, then Dataflow setsthe number of workers based on the--numWorkers option.
Python
--autoscaling_algorithm=NONEIf you disable Horizontal Autoscaling, then Dataflow setsthe number of workers based on the--num_workers option.
Go
--autoscaling_algorithm=NONEIf you disable Horizontal Autoscaling, then Dataflow setsthe number of workers based on the--num_workers option.
Custom sources
If you create a custom data source, you can potentially improve performance byimplementing methods that provide more information to the Horizontal Autoscalingalgorithm:
Java
Bounded sources
- In your
BoundedSourcesubclass, implement the methodgetEstimatedSizeBytes.The Dataflow service usesgetEstimatedSizeByteswhen calculatingthe initial number of workers to use for your pipeline. - In your
BoundedReadersubclass, implement the methodgetFractionConsumed.The Dataflow service usesgetFractionConsumedto track readprogress and converge on the correct number of workers to use during a read.
Unbounded sources
The source must inform the Dataflow service about backlog.Backlog is an estimate of the input in bytes that has not yet been processedby the source. To inform the service about backlog, implement either one ofthe following methods in yourUnboundedReader class.
getSplitBacklogBytes()- Backlog for the current split of the source. Theservice aggregates backlog across all the splits.getTotalBacklogBytes()- The global backlog across all the splits. Insome cases the backlog is not available for each split and can only becalculated across all the splits. Only the first split (split ID '0') needsto provide total backlog.
The Apache Beam repository contains severalexamplesof custom sources that implement theUnboundedReader class.
Python
Bounded sources
- In your
BoundedSourcesubclass, implement the methodestimate_size. TheDataflow service usesestimate_sizewhen calculating theinitial number of workers to use for your pipeline. - In your
RangeTrackersubclass, implement the methodfraction_consumed.The Dataflow service usesfraction_consumedto track readprogress and converge on the correct number of workers to use during a read.
Go
Bounded sources
- In your
RangeTracker, implement the methodGetProgress(). TheDataflow service usesGetProgressto track read progress andconverge on the correct number of workers to use during a read.
Limitations
- In jobs running Dataflow Prime, Horizontal Autoscaling is deactivatedduring and up to 10 minutes after Vertical Autoscaling. For more information,seeEffect on Horizontal Autoscaling.
- For pipelines not usingDataflow Shuffle,Dataflow might not be able to scale down the workers effectivelybecause the workers might have shuffled data stored in local disks.
- ThePeriodicImpulsetransform is supported with streaming autoscaling in the Apache Beam SDK versions 2.60.0 and later. If your pipeline uses
PeriodicImpulsewith an earlier SDK version, then Dataflow workers don't scale down asexpected.
What's next
- Tune Horizontal Autoscaling for streaming pipelines
- Monitor Dataflow autoscaling
- Troubleshoot Dataflow autoscaling
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-19 UTC.