Scheduled pipelines,
each task in the right order.
Airflow schedules data pipelines, releases each task when the previous ones finish, and shows what ran, what failed, and what is still waiting. Follow a DAG from scheduling to the completed task.
A workflow orchestration platform schedules, runs, and monitors sequences of tasks that depend on one another. In TDP, data pipelines are scheduled by Apache Airflow.
Workflow as code
A DAG in Python
The whole workflow is written in Python, as a DAG: the tasks, the dependencies between them, and when it should run.
In the right order
Each task waits for the previous ones
The Scheduler tracks all the tasks and releases each one when its dependencies are met.
On this page
- See a DAG run
- Architecture
- From the DAG to the task instance
- Where the task runs
- Why Airflow
- In the TDP editions
See a DAG run
The scene shows the run on Workers. The Executor can also run the task on the Scheduler itself or in a Pod created just for it (see Where the task runs). Press Play or step through. The underlined names lead to the Glossary.
1 The DAG is read
The DAG processor parses the Python files in the DAGs folder and writes each DAG, serialized, to the metadata database. From there, the other components learn about the tasks and the dependencies.
In the Glossary: DAGs folder · Metadata database · DAG processor
- The DAG is read. The DAG processor parses the Python files in the DAGs folder and writes each DAG, serialized, to the metadata database. From there, the other components learn about the tasks and the dependencies.
- A DAG Run is born. The schedule defined in the DAG comes due, or someone triggers it from the interface or the API. The Scheduler creates a DAG Run: one execution of the DAG, with its data interval. Each task gets an instance in that run, still in the none state.
- Dependencies met: scheduled. The Scheduler tracks all the tasks. When the upstream tasks of a task finish successfully, its dependencies are met, and the instance moves to scheduled: it is ready to run.
- Handed to the Executor: queued. The Scheduler uses the configured Executor to run the ready tasks. Once assigned to the Executor, the instance stays in queued, waiting for a Worker.
- A Worker runs it: running. The task goes to a Worker with free capacity, and the instance moves to running. The Worker reads the same DAG file, which is why the DAGs folder must be synchronized between the components that use it.
- Task completed: success. The task finishes without errors, and the instance reaches success. The state is kept in the metadata database, and the web interface shows the progress. The downstream tasks enter the same cycle. When all of them reach a final state, the DAG Run gets its own.
This is the ideal path of a task instance: none, scheduled, queued, running, and success. When something leaves the path, the state says what: failed for an error during execution, up_for_retry when retries remain, upstream_failed when a previous task failed, skipped when the task was skipped.
Architecture
A Scheduler with its Executor, Workers, a web interface, a DAGs folder, and a metadata database.
What the figure shows:
- The user interface accesses the Web Server and makes it possible to trigger, inspect, and debug DAGs and tasks.
- The Web Server serves the web interface. In more recent Airflow versions, it is served by the API Server.
- The Scheduler triggers the scheduled workflows and hands the tasks to the Executor, which runs inside it and communicates with the Workers.
- The Workers run the tasks.
- The DAGs folder holds the files that the Scheduler, Workers, and Triggerer read, the same for all of them. In the figure, dashed lines connect it to the Scheduler and to the Workers.
- The metadata database is where all of them store and query the state. In the figure, the Web Server, Scheduler, and Workers connect to it.
From the DAG to the task instance
What Airflow does with the Python file you wrote: three levels, each one inside the other.
Level 1 of 3
DAG
The workflow model, written in Python: the tasks, the dependencies between them, and the schedule. The DAG does not concern itself with what happens inside the tasks, but with how to run them: the order, the retries, the timeouts.
- DAG RunEach execution of the DAG in time, with its data interval. Several runs of the same DAG can happen in parallel, and a historical period can be reprocessed with backfill.
- DAG. The workflow model, written in Python: the tasks, the dependencies between them, and the schedule. The DAG does not concern itself with what happens inside the tasks, but with how to run them: the order, the retries, the timeouts.
- DAG Run. Each execution of the DAG in time, with its data interval. Several runs of the same DAG can happen in parallel, and a historical period can be reprocessed with backfill.
- Task. The basic unit of execution. The dependencies set the order: the upstream task comes first, the downstream one comes after, and a task waits for its upstream tasks to finish successfully.
- Operator. A ready-made task template: the BashOperator runs a Bash command, the PythonOperator calls a Python function.
- Sensor. A special Operator that waits for an external event to happen.
- TaskFlow. A plain Python function, marked with @task, packaged as a task.
- Task Instance. The execution of a task within a DAG Run. It is the one that has a state: none, scheduled, queued, running, success, or another that explains the deviation.
The Airflow core ships the basic Operators, and the providers add operators, hooks, and sensors to talk to external systems, such as Hive, Kafka, or Trino.
Where the task runs
The Executor is interchangeable: the same task can run on the Scheduler itself, on a Worker that pulls it from a queue, or in a container created just for it.
Tasks run inside the Scheduler process, as with the LocalExecutor: simple to use, with few requirements, but sharing resources with the Scheduler.
Tasks go to a central queue, and remote Workers pull them to run, as with the CeleryExecutor. Workers are usually persistent and run several tasks at the same time.
Each task instance runs in its own Pod, as with the KubernetesExecutor: the Pod is created when the task enters the queue and terminates when it finishes.
In any case, whatever runs the task needs to read the DAG file. The files can reach the Workers through a persistent volume mounted on all of them, through synchronization with a Git repository, or inside the image itself.
Why Airflow
Code
Dynamic pipelines in Python
Because the pipeline is code, DAGs can be generated and parameterized dynamically, versioned, tested, and maintained by several developers on the same codebase.
Extensible
Ready-made operators and providers
A broad collection of operators ships with Airflow, and the framework can be extended for each need.
Flexible
Jinja templates
The Jinja templating engine makes it possible to customize tasks and parameters.
Scheduling
Recurring and complex pipelines
Rich scheduling and execution semantics make it easier to define pipelines that repeat.
Reprocessing
Backfill and rerun
DAG Runs can process historical data, and only the tasks that failed can be run again, saving cost and time.
Visibility
Web interface
Through the interface, it is possible to trigger DAGs manually, view logs, and follow the state of the tasks.
Airflow began in October 2014, with Maxime Beauchemin, at Airbnb, and has been open source since the first commit. It entered the Apache Software Foundation incubator in March 2016 and became an Apache top-level project in January 2019. It is maintained by a global community.
In the TDP editions
| Edition | Version | Documentation |
|---|---|---|
| TDP Datacenter | 2.10.5 | TDP Datacenter components |
| TDP Kubernetes | 3.0.2 · chart tdp-airflow 3.0.3 | Configuration in TDP Kubernetes |
In TDP Datacenter
In TDP Datacenter, Airflow is a stack service, installed and managed by Ambari.
AIRFLOW_CELERY_FLOWER (slave, one instance), AIRFLOW_SCHEDULER (master, one instance), AIRFLOW_WEBSERVER (master, one or more) and AIRFLOW_WORKER (slave, optional). Component category.
Airflow Celery Flower is the web interface that monitors the Workers. See Flower.
Configurable in airflow-core-site, in the executor property, among options such as LocalExecutor, CeleryExecutor, and KubernetesExecutor. See Where the task runs.
A PostgreSQL database, created during the Ambari installation, with the connection configurable in airflow-database-site, in the sql_alchemy_conn property.
Lineage in Apache Atlas, with the Atlas address in airflow-atlas-site (host and port), and Kerberos authentication. See Security in TDP Datacenter.
The Hive, Kafka, and Druid providers, the Trino Python library, the spark-submit of the Spark client, and the Great Expectations provider come already installed.
These services require this one in the cluster: OpenMetadata.
OpenMetadata uses Airflow for metadata ingestion. See OpenMetadata.
In TDP Kubernetes
In TDP Kubernetes, Airflow is installed by the tdp-airflow chart, which packages the Apache Airflow chart and gathers its settings under tdp-airflow. The chart brings up the API Server, the Scheduler, the Triggerer, and the DAG processor.
KubernetesExecutor by default, in tdp-airflow.executor: each task instance runs in its own Pod.
A persistent volume created by the chart, enabled by default in tdp-airflow.dags.persistence.enabled. DAGs reach this volume by file copy or by git-sync, and helm uninstall deletes this volume. See Airflow configuration.
PostgreSQL, through the embedded subchart (tdp-airflow.postgresql.enabled) or through an external PostgreSQL (TDP-Settings.externalDatabase).
The API Server is exposed through a Kubernetes Service. Ingress or Gateway API bring the interface outside the cluster.
Connection to S3-compatible storage, such as Apache Ozone (TDP-Settings.s3Connection). LDAP authentication (tdp-airflow.ldap.enabled).
The image includes the Airflow providers, PySpark with spark-submit, and the ClickHouse libraries, for tasks with Spark, Kafka, Trino, and ClickHouse.
In both editions, what changes is where the task runs and where the DAGs come from. The path of each task, from the DAG Run to the final state, goes through the same states as in Figure 1.
Next steps
TDP Kubernetes
Airflow Configuration
Executor, DAGs volume, metadata database, and access in the chart.
TDP Datacenter
TDP Datacenter Architecture
Where the services sit in the cluster and what is enabled in Ambari.
Sources
Apache Airflow - Documentation