Skip to main content

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.

Wherever there is room

The Executor distributes

The Executor hands each task over wherever there is room: to a Worker, to the Scheduler itself, or to a Pod created just for it.

On this page

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.

InterfaceWho follows along
Web ServerWeb interface: trigger, inspect, debug
Code and stateWhat Airflow reads and writes
DAGs folderPython files with the DAGs
Metadata databaseState of DAGs and tasks
SchedulingWho decides the turn
DAG processorReads the DAG files
SchedulerTriggers runs and releases tasks
ExecutorTakes the task to a Worker
ExecutionWho runs it
WorkerRuns the task
WorkerAvailable for the next one
Step 1 of 6

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.

  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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
Figure 1 - A task in Airflow. The state of the task instance changes at each step: none, scheduled, queued, running, and success.

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.

Apache Airflow architecture: web interface, Scheduler with the Executor, Workers, DAG directory and metadata databaseThe user interface accesses the Web Server. The Scheduler hosts the Executor, which communicates with the Workers. The Web Server, the Scheduler and the Workers connect to the metadata database. Dashed lines connect the DAG directory to the Scheduler and the Workers.UserInterfaceWeb ServerSchedulerExecutorWorkerWorkerWorkerDAGDirectoryMetadataDatabase
Figure 2 - Airflow architecture: web interface, Scheduler with the Executor, Workers, DAGs folder, and metadata database. The underlined terms lead to the Glossary.

What the figure shows:

  1. The user interface accesses the Web Server and makes it possible to trigger, inspect, and debug DAGs and tasks.
  2. The Web Server serves the web interface. In more recent Airflow versions, it is served by the API Server.
  3. The Scheduler triggers the scheduled workflows and hands the tasks to the Executor, which runs inside it and communicates with the Workers.
  4. The Workers run the tasks.
  5. 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.
  6. 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.
  1. 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.
  2. 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.
  3. 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.
Figure 3 - Each level contains the next: the DAG groups tasks, and each task gets an instance at every run of the DAG.

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.

Local

Tasks run inside the Scheduler process, as with the LocalExecutor: simple to use, with few requirements, but sharing resources with the Scheduler.

Queue with Workers

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.

Container per task

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.

Where it comes from

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​

Available in the TDP editions
EditionVersionDocumentation
TDP Datacenter2.10.5TDP Datacenter components
TDP Kubernetes3.0.2 · chart tdp-airflow 3.0.3Configuration in TDP Kubernetes

In TDP Datacenter​

In TDP Datacenter, Airflow is a stack service, installed and managed by Ambari.

Service components

AIRFLOW_CELERY_FLOWER (slave, one instance), AIRFLOW_SCHEDULER (master, one instance), AIRFLOW_WEBSERVER (master, one or more) and AIRFLOW_WORKER (slave, optional). Component category.

Celery Flower

Airflow Celery Flower is the web interface that monitors the Workers. See Flower.

Executor

Configurable in airflow-core-site, in the executor property, among options such as LocalExecutor, CeleryExecutor, and KubernetesExecutor. See Where the task runs.

Metadata database

A PostgreSQL database, created during the Ambari installation, with the connection configurable in airflow-database-site, in the sql_alchemy_conn property.

Can be enabled in Ambari

Lineage in Apache Atlas, with the Atlas address in airflow-atlas-site (host and port), and Kerberos authentication. See Security in TDP Datacenter.

Providers and libraries installed

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.

Required by

These services require this one in the cluster: OpenMetadata.

Metadata ingestion

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.

Executor

KubernetesExecutor by default, in tdp-airflow.executor: each task instance runs in its own Pod.

DAGs folder

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.

Metadata database

PostgreSQL, through the embedded subchart (tdp-airflow.postgresql.enabled) or through an external PostgreSQL (TDP-Settings.externalDatabase).

Access

The API Server is exposed through a Kubernetes Service. Ingress or Gateway API bring the interface outside the cluster.

Configurable in the chart

Connection to S3-compatible storage, such as Apache Ozone (TDP-Settings.s3Connection). LDAP authentication (tdp-airflow.ldap.enabled).

Providers and libraries installed

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​

Sources​

Apache Airflow - Documentation

Apache Airflow - Architecture Overview

Apache Airflow - Dags

Apache Airflow - Dag Runs

Apache Airflow - Tasks

Apache Airflow - Operators

Apache Airflow - Scheduler

Apache Airflow - Executor

Apache Airflow - Project