- Infrastructure components: the scheduler and executor, Dag processor, API server, triggerer, metadata database, and workers.
- Environment: limits that apply to all Dags in an Airflow environment.
- Dag and Dag runs: limits that apply to one Dag or Dag run.
- Tasks and task instances: limits that apply to one task or task instance.
Scale on AstroDuring Astronomer load tests with long-running tasks, the Astro executor with the standard Airflow scheduler sustained 200,000 concurrent task instances. This result depends on the tested setup, including worker size, database capacity, and the number of replicas of each component. See The Astro Runtime: Airflow re-engineered for speed and scale and talk to your Astronomer account team if you are looking to run Airflow at similar scales.
Assumed knowledge
To get the most out of this guide, you should have an understanding of:- Airflow core components. See Airflow’s components.
- Airflow executors. See Airflow executors explained.
Plan for your scale
Before you change any parameters, answer the following questions about your current environment:- How many Dag files does Airflow parse, and how long does parsing take?
- How many task instances need to run at the same time?
- How much CPU, memory, and storage do your task instances use?
- How much CPU and memory do the scheduler, Dag processor, API server, and triggerer use?
Change Airflow configuration
Environment-level and component-level settings are Airflow configuration options. You can change them by setting environment variables in the formatAIRFLOW__<SECTION>__<OPTION>, for example AIRFLOW__CORE__PARALLELISM. For all options and their defaults, see the Airflow configuration reference. To check the current values in a running Airflow environment, go to Admin > Config in the Airflow UI.
On Astro, you can set configuration options in the Astro environment manager.
Dag-level and task-level settings are set using parameters in your Dag code.
Scale Airflow components
The following diagram shows the components of an Airflow 3 environment. For more on the individual components, see the Airflow components guide.
- Increase the size of the underlying infrastructure, for example use a larger node for a worker with more vCPU and RAM
- Add more units of the same component, for example high availability for the API server
- Change configuration parameters, for example increase the scheduler’s
max_tis_per_queryso that it queues more task instances per scheduler loop
Astro Deployment optionsAstro has the following additional Deployment options:
- Hibernation: You can hibernate Deployments that have Development Mode turned on. Define a wake schedule so that the Deployment runs only during the hours you use it. See Hibernate a development Deployment.
- Cost Management: The Data Pipelines Health Overview dashboard in Astro Observe includes a Cost Management section that lists the Dags and tasks with the highest cost and shows how their cost changes over time.
- Disaster recovery: For Deployments on dedicated clusters, cross-region disaster recovery keeps a secondary cluster in a second region synchronized with the primary cluster, so that you can fail over if the primary region has an outage. Cross-region disaster recovery requires the Enterprise Business Critical tier. See Disaster recovery.
Scheduler
The scheduler creates Dag runs, determines which task instances are ready to run, and queues them for the executor. Running more than one scheduler increases reliability and scheduling throughput. Astronomer recommends using high availability for all production environments. See Deployment resources for how to configure your scheduler infrastructure on Astro. The following scheduler settings affect scheduling throughput. To set one as an environment variable, add the prefixAIRFLOW__SCHEDULER__ to the name in uppercase, for example AIRFLOW__SCHEDULER__MAX_TIS_PER_QUERY.
Executor
The executor determines how and where task instances run. Your choice of executor affects how quickly task instances start, their level of isolation, and which settings you tune to scale:
In open source Airflow, you can run multiple executors at the same time and assign each task to one of them. See Using multiple executors concurrently. For a detailed comparison of executors, see Airflow executors explained.
Remote executionOn Astro, Remote Execution runs your workers on your own infrastructure, separate from the Airflow components that Astro hosts. Remote Execution is available on the Enterprise tier and above.In open source Airflow, you can run workers on infrastructure separate from the Airflow components with the Edge executor of the Edge3 provider.
Dag processor
In Airflow 3, the Dag processor is a separate component that parses Dag files independently of the scheduler. If new or changed Dags take a long time to appear in the Airflow UI, scale the Dag processor. On Astro, Small Deployments run the scheduler and Dag processor in the same Pod, and larger Deployments run them separately. See Deployment resources. The following settings control how often and how quickly Airflow parses Dag files. To set one as an environment variable, add the prefix of its configuration section to the name in uppercase:AIRFLOW__CORE__ for dagbag_import_timeout, for example AIRFLOW__CORE__DAGBAG_IMPORT_TIMEOUT, and AIRFLOW__DAG_PROCESSOR__ for all other settings in the table, for example AIRFLOW__DAG_PROCESSOR__REFRESH_INTERVAL.
To determine which values to use, monitor how long parsing takes with the
dag_processing.total_parse_time and dag_processing.last_duration metrics. See Monitor scaling.
API server
The API server serves the Airflow UI, the Airflow REST API, and the Execution API that workers use to receive task instances and report their state. Scale your API server if:- You have Dags with a high number of tasks, which increases the load from the Airflow UI.
- You make many calls to the Airflow REST API.
- You run thousands of concurrent task instances, which all communicate with the metadata database through the API server.
AIRFLOW__API__WORKERS (default 1) determines the number of worker processes in each API server. To scale further, the Airflow configuration reference recommends running multiple API servers instead of increasing the number of worker processes. On Astro, you can enable API server autoscaling.
Triggerer
The triggerer runs the triggers of deferred task instances.AIRFLOW__TRIGGERER__CAPACITY (default 1000) determines how many triggers a single triggerer runs at the same time. If you run many deferrable operators, monitor the triggerer.capacity_left metric, and add triggerers or increase their resources when capacity runs low.
On Astro, each Deployment includes one triggerer with 0.5 vCPU and 1.875 GiB of memory. If you need more than about 1,000 concurrent triggers, or your triggers need more memory, increase the number and size of triggerers with the ASTRO_TRIGGERER_REPLICAS, ASTRO_TRIGGERER_RESOURCES_CPU, and ASTRO_TRIGGERER_RESOURCES_MEMORY environment variables. See Triggerer.
Metadata database
All components store their state in the metadata database, so its size and load grow with your number of Dags, Dag runs, and task instances. To keep large data out of the metadata database, use a custom XCom backend that stores XComs in object storage. With a custom XCom backend, the metadata database stores only a reference to each XCom. On Astro, Hosted Deployments that run Astro Runtime 3.0 or later automatically store XCom values larger than 64 KB in an Astro-managed object storage bucket, so you don’t need to configure a custom XCom backend. Astro Runtime 3.3 and later also stores task and asset state values larger than 64 KB in this bucket. See XCom and state store backends. Astro also has the Airflow DB Storage High Deployment health alert, which notifies you when the metadata database has tables larger than 50 GiB.Workers
Workers run your task instances. The more workers you have, or the larger they are, the more task instances you can run at the same time. When you size workers, consider what your tasks need:Worker queues on Astro
On Astro, the Astro executor and the Celery executor run workers in worker queues. Each worker queue has the following settings:- Worker Type: The vCPU and memory of each worker, for example A5 (1 vCPU, 2 GiB) or A20 (4 vCPU, 8 GiB).
- Storage: The ephemeral storage of each worker.
- Concurrency: How many task instances each worker runs at the same time.
- Min # Workers and Max # Workers: The minimum and maximum number of workers in the queue.
queue parameter to the name of the worker queue, for example queue="memory-intensive".
If your Deployment uses the Kubernetes executor, each task instance runs in its own Pod. You can define default Pod resources and limits for the Deployment, and customize the Pod resources of individual tasks. See Configure Kubernetes Pod resources.
If your Deployment uses Remote Execution mode, you manage the scaling of Remote Execution Agent workers in your own Kubernetes cluster. See Autoscale Remote Execution Agent workers on queue depth.
Environment-level settings
Environment-level settings apply to all Dags in your Airflow environment. All of the following settings are in thecore configuration section. To set one as an environment variable, add the prefix AIRFLOW__CORE__ to the name in uppercase, for example AIRFLOW__CORE__PARALLELISM.
PoolsPools limit how many task instances can be queued or running at the same time, in addition to
parallelism. All tasks without an assigned pool use default_pool, which has 128 slots by default. To run more tasks in parallel, increase the slots of default_pool, or assign tasks to other pools.Dag-level settings
Dag-level settings apply to one Dag and are defined in your Dag code. They override the corresponding environment-level settings.
The following example allows a maximum of 10 concurrent task instances in each Dag run, and a maximum of three active Dag runs:
- TaskFlow
- Traditional
Task-level settings
Task-level settings apply to one task. You can define them on any operator that inherits fromBaseOperator, as well as on decorators such as @task.
Unlike
max_active_tasks, the max_active_tis_per_dag and max_active_tis_per_dagrun limits count task instances in the deferred state.
Priority weightsWhen more task instances are ready to run than there are open slots, the scheduler queues the task instances with the highest
priority_weight first. See Priority weights in the Airflow documentation.- TaskFlow
- Traditional
Default arguments
To define task-level settings for all tasks in a Dag, pass them to the Dag indefault_args. Task groups also have a default_args parameter, which applies to all tasks in the task group and overrides the default_args of the Dag. Parameters that you define on a task override both.
The following example defines a pool in three places. The tasks use the following pools:
extractusesdag_poolfrom thedefault_argsof the Dag.transformusestask_group_poolfrom thedefault_argsof themy_task_grouptask group.loadusestask_pool, which is defined on the task itself.
Right-size tasks with task-level metrics on Astro
On Astro Deployments that use the Astro executor, the Airflow UI shows CPU and memory usage for each Dag, task, and task instance. You can use these task-level metrics to adjust your worker queues.
Scale surrounding systems
When Airflow runs more task instances, the systems your Dags interact with receive more requests. Check the following before you scale:- How many concurrent connections and writes your databases support. Use pools to stay within those limits.
- The rate limits of the APIs your tasks call. Use pools or
max_active_tis_per_dagto stay within them.
RetriesTasks can retry automatically when they fail, for example because an API returned a rate limit error. With retry policies, available in Airflow 3.3 and later, you can control whether a task instance retries based on the exception it raised. To preserve state in between retries, see Durable execution with the task state store.
Monitor scaling
To find out what to scale, collect Airflow metrics. Airflow can emit metrics to StatsD (AIRFLOW__METRICS__STATSD_ON=True) or OpenTelemetry (AIRFLOW__METRICS__OTEL_ON=True). For a description of all metrics, see the Airflow metrics reference.
On Astro, you can also use the following monitoring features:
- The Analytics page of each Deployment in the Astro UI shows metrics for Dag runs, task runs, workers, the scheduler and Dag processor, the triggerer, and pools. See View metrics for Astro Deployments.
- The Airflow UI shows CPU and memory usage for each task. See Right-size tasks with task-level metrics on Astro.
- You can export Airflow infrastructure and task metrics to a Prometheus-compatible monitoring system, and infrastructure metrics to Datadog. See Export metrics from Astro.
- The Worker Queue At Capacity Deployment health alert notifies you when at least one worker queue runs the maximum number of task instances and workers. Task Duration and Dag Duration alerts notify you when tasks or Dags take longer than a duration you define. See Astro alerts.
For help with scaling Airflow, join the Apache Airflow Slack. If you’re an Astronomer customer and want advice on scaling your Deployments, contact your Astronomer account team.