Skip to main content

An Introduction to Apache Airflow

Airflow is a platform to programmatically author, schedule, and monitor workflows. In this blog we will understand the basics of Airflow 3

Updated Nov 2026 for Airflow 3.4. The original 2022 version of this post used the Airflow 1.x/2.x style (DAG(...) objects, PythonOperator, schedule_interval). Everything below uses the Airflow 3 TaskFlow style, and the code samples have been run against Airflow 3.4.0.

What is Airflow?

Airflow is a platform created by the community to programmatically author, schedule, and monitor workflows.

Machine learning is the hot topic of the industry. It won’t be so cool if not for the data processing involved.

Airflow is a workflow orchestration tool. It started as a way to run ETL (Extract, Transform, Load) pipelines, and that is still its sweet spot, but anything you can express as “run these steps in this order, on this schedule, and tell me when something breaks” fits.

Uses of Airflow

Imagine you have an ML model that does twitter sentiment analysis. Now you want to run that model for your favorite people on twitter for their tweets every day. Such a workflow would look something like this: fetch the tweets, score each one, store the results.

As you can see, the data flows from one end of the pipeline to the other end. There can be branches, but no cycles. That shape is what gives the “DAG” (Directed Acyclic Graph) its name. Airflow 3’s own docs now spell it “Dag”, but I’ll stick with DAG here.

What problems does Airflow solve?

Crons are an age-old way of scheduling tasks.

  1. With cron creating and maintaining a relationship between tasks is a nightmare, whereas, in Airflow, it is as simple as writing Python code.
  2. Cron needs external support to log, track, and manage tasks. Airflow comes with a UI to track and monitor the workflow execution.
  3. Cron jobs are not reproducible unless externally configured. Airflow keeps an audit trail of all tasks executed.
  4. Scalable. You can start on a laptop and move the same DAG to a cluster by changing the executor.

Quickstart: run Airflow locally

This is the quickest way to see a DAG run. It follows the official quickstart. Airflow 3.4 needs Python 3.11 or newer (see the PyPI listing).

python3 -m venv .venv
source .venv/bin/activate

AIRFLOW_VERSION=3.4.0
PYTHON_VERSION="$(python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')"
CONSTRAINT_URL="https://raw.githubusercontent.com/apache/airflow/constraints-${AIRFLOW_VERSION}/constraints-${PYTHON_VERSION}.txt"
pip install "apache-airflow==${AIRFLOW_VERSION}" --constraint "${CONSTRAINT_URL}"

The constraints file pins every dependency to a combination the Airflow release was tested with. Skip it and you are likely to spend an afternoon on version conflicts.

Now save the DAG from the next section as ~/airflow/dags/tweet_sentiment.py (Airflow keeps its files in ~/airflow unless you set AIRFLOW_HOME, and the default DAG folder is a dags folder inside it), then start everything with one command:

airflow standalone

airflow standalone runs the API server, scheduler, DAG processor and triggerer together on SQLite. It is for development only, never for production. Open http://localhost:8080 and log in as admin. The password is printed in the terminal the first time you run it, and stored in ~/airflow/simple_auth_manager_passwords.json.generated after that. New DAGs show up paused, so unpause tweet_sentiment and trigger it from the UI.

If you only want to check that a DAG works without starting any services, airflow dags test tweet_sentiment runs a full DAG run in your terminal.

How to define a workflow in Airflow?

Workflows are defined using Python files. In Airflow 3 you import everything you need to write DAGs from airflow.sdk, the authoring interface that is kept separate from Airflow’s internals. The old paths such as airflow.models.DAG and airflow.operators.python are deprecated, as the upgrade guide points out.

DAG and tasks with the TaskFlow API

The TaskFlow API lets you write a DAG as plain Python. @dag turns a function into a DAG and @task turns a function into a task. Return values are passed between tasks for you.

import pendulum
from airflow.sdk import dag, task
from airflow.providers.standard.operators.bash import BashOperator


@dag(
    schedule="@daily",
    start_date=pendulum.datetime(2026, 1, 1, tz="UTC"),
    catchup=False,
    tags=["intro"],
)
def tweet_sentiment():
    @task
    def extract() -> list[str]:
        return ["airflow is great", "cron is painful", "dags are neat"]

    @task
    def score(tweet: str) -> dict:
        positive = {"great", "neat"}
        hits = sum(word in positive for word in tweet.split())
        return {"tweet": tweet, "score": hits}

    @task
    def load(results: list[dict]) -> None:
        for row in results:
            print(f"{row['score']}  {row['tweet']}")

    announce = BashOperator(task_id="announce", bash_command="echo 'pipeline done'")

    tweets = extract()
    scored = score.expand(tweet=tweets)
    load(scored) >> announce


tweet_sentiment()

The tweets are hard-coded so that the example runs anywhere. Swap extract() for a real API call and score() for your model.

A few things to notice.

schedule is how often the DAG runs. It takes a cron expression such as '* * * * *' (every minute), a preset such as "@daily", or a timedelta. If cron syntax scratches your brain, play around with it on https://crontab.guru/. The old schedule_interval argument from the Airflow 1.x/2.x days is gone in Airflow 3; use schedule.

start_date is the date from which the DAG is eligible to run, and catchup=False tells Airflow not to backfill every missed interval between start_date and today.

Calling one task with the output of another (load(scored)) both passes the data (through XCom, Airflow’s small-message store) and sets the dependency. The extract() task runs first, then score, then load.

Operators

Behind every @task is an operator. Operators define the nodes of the DAG, and each one is an independent task. @task wraps a Python function for you, but you can still use the classic operators when you want to run something else. In the DAG above, BashOperator runs a shell command.

Since Airflow 3, the common operators such as BashOperator live in the standard provider, airflow.providers.standard. The >> operator links tasks together, which is how load(scored) >> announce makes the bash task wait for the load. For a tour of the other operators, see Airflow operators comparison.

Assets and data-aware scheduling

A cron-style schedule says “run at 9 am”. Often what you actually mean is “run when the data is ready”. Airflow calls a piece of data an Asset. A task that produces it lists the asset as an outlet, and a DAG that depends on it uses the asset as its schedule.

import pendulum
from airflow.sdk import Asset, dag, task

daily_report = Asset("file:///tmp/daily_report.csv")


@dag(schedule="@daily", start_date=pendulum.datetime(2026, 1, 1, tz="UTC"), catchup=False)
def build_report():
    @task(outlets=[daily_report])
    def build():
        print("writing /tmp/daily_report.csv")

    build()


@dag(schedule=[daily_report], start_date=pendulum.datetime(2026, 1, 1, tz="UTC"))
def publish_report():
    @task
    def publish():
        print("report updated, publishing")

    publish()


build_report()
publish_report()

Every time build succeeds, Airflow marks daily_report as updated and publish_report is triggered. According to the asset scheduling docs, the asset only counts as updated if the producing task succeeds. The asset URI is an identifier Airflow tracks; it does not read or write the file for you.

I ran both DAGs above with airflow dags test, which runs each one on its own. The trigger from producer to consumer happens when the scheduler is running, so you will see it in the UI under airflow standalone.

This is also how Airflow 3 replaces the old SubDAGs and cross-DAG sensors: the upgrade guide lists “TaskGroups, Assets, and Data Aware Scheduling” as the replacement for SubDAGs. If the producer is outside Airflow (a message on a queue, say), the docs describe an AssetWatcher that pulls those events in; see the asset scheduling docs linked above.

Dynamic task mapping

Sometimes you don’t know how many tasks you need until the DAG runs: one task per file in a bucket, per customer, per tweet. Dynamic task mapping creates those tasks at runtime. You’ve already seen it in the quickstart:

scored = score.expand(tweet=tweets)

.expand() creates one score task instance per item returned by extract(). A task that receives the mapped output, like load, gets all the results back and acts as the “reduce” step. If a parameter should be the same for every mapped task, pass it with .partial():

@task
def add(x: int, y: int):
    return x + y

added_values = add.partial(y=10).expand(x=[1, 2, 3])

By default, expand can create at most 1024 tasks, which is the max_map_length setting. If an upstream task returns more than that, it fails. The .partial() example and the limit come from the dynamic task mapping docs. I also wrote about this in Dynamic Task Mapping.

Deferrable operators and the triggerer

Waiting is the most wasteful thing a task can do. A normal sensor that waits an hour for a file holds a worker slot for the whole hour, doing nothing. A deferrable operator hands the waiting over: it suspends itself, a small async process called the triggerer watches for the event, and the task goes back to a worker only when there is something to do. The docs say it plainly: during the deferred phase “the task no longer occupies a worker slot.”

Many built-in sensors and provider operators accept deferrable=True:

import pendulum
from datetime import timedelta
from airflow.sdk import dag, task
from airflow.providers.standard.sensors.time_delta import TimeDeltaSensor


@dag(schedule=None, start_date=pendulum.datetime(2026, 1, 1, tz="UTC"))
def wait_without_a_worker():
    wait = TimeDeltaSensor(task_id="wait_5s", delta=timedelta(seconds=5), deferrable=True)

    @task
    def after():
        print("resumed after the trigger fired")

    wait >> after()


wait_without_a_worker()

The flow is: the task defers, the triggerer picks up the trigger, the trigger fires, and the scheduler queues the task to resume on a worker. Deferrable operators need at least one triggerer process running next to the scheduler, otherwise deferred tasks never resume. airflow standalone starts one for you. Waiting for five seconds is silly, but the same pattern applies to anything that waits on the outside world, like a file landing in a bucket or a job finishing in a warehouse.

Airflow Architecture

Airflow 3 changed the architecture quite a bit from the Airflow 2 diagrams you’ll still find on the internet. The architecture overview splits the components into required and optional.

A minimal installation has these:

Scheduler

The scheduler triggers scheduled workflows and submits tasks to the executor. The executor is responsible for getting tasks to a place where they run, and it runs inside the scheduler process.

DAG processor

The DAG processor parses your DAG files and writes the result to the metadata database. In Airflow 3 it is a required component of every deployment.

DAG bundle

A DAG bundle is the place the DAG processor reads your DAG files from. By default that is a local folder (LocalDagBundle). There is also a GitDagBundle that pulls DAGs from a Git repository and records the commit each DAG run used, so a rerun can use the same code even after the repo has moved on. The local bundle doesn’t do this, so tasks always run the latest code.

API server

The API server replaces the old webserver. It serves the REST API and the UI, and it is also how tasks report their state, without talking to the database directly.

Metadata database

The metadata database stores the state of tasks, DAGs and variables. It is usually PostgreSQL or MySQL; SQLite is fine for learning on your laptop.

And these are optional, depending on how you run Airflow:

Worker

Workers run the tasks that the scheduler assigns. In a basic installation, the worker is part of the scheduler process. With the Celery or Kubernetes executors, workers are separate machines or pods.

Triggerer

The triggerer runs deferred tasks in an asyncio event loop. You don’t need it unless you use deferrable operators.

Types of Executor

The executor decides where and how your tasks run. You choose it in the config, and the DAG code stays the same.

SequentialExecutor, the first one I described in the original post, is gone. The upgrade guide says it was “replaced by LocalExecutor, which can be used with SQLite for local development use cases.”

LocalExecutor

LocalExecutor is the default, and the executor docs call it the simplest option. It runs tasks as processes inside the scheduler process, on one machine, and can run multiple tasks at a time.

Pros

  1. Simple, nothing extra to install
  2. Works with SQLite, so it is good for development

Cons

  1. Not scalable beyond one machine
  2. Single point of failure
  3. The docs warn that running tasks inside the scheduler process can hurt the scheduler’s performance

CeleryExecutor

Celery is used for running distributed asynchronous python tasks. CeleryExecutor (now in the Celery provider) has been a part of Airflow for a long time, even before Kubernetes. Tasks go to a central queue, and a fixed pool of workers started with airflow celery worker picks them up as they get scheduled.

Pros

  1. It provides scalability: add workers to add capacity.
  2. The workers are already running, so tasks start with little latency. The Kubernetes executor docs make this point when comparing it with Kubernetes.

Cons

  1. Celery needs a broker such as RabbitMQ or Redis to queue the tasks, plus a database-backed result backend, as the Celery executor docs describe. That is more to run, monitor and secure.
  2. The above dependencies also make the setup more complex.

KubernetesExecutor

KubernetesExecutor runs each task in an individual Kubernetes pod. Unlike CeleryExecutor, it spins up worker pods on demand, hence enabling maximum usage of resources. Per the docs, “the pod is created when the task is queued, and terminates when the task completes.”

Pros

  1. It does not need extra components like Redis or RabbitMQ, which CeleryExecutor does.
  2. Fine-grained control over resources allocated to tasks. You can define the amount of CPU/memory required at a task level, using executor_config with a pod_override.
  3. Each task runs in its own isolated environment.

Cons

  1. It needs access to a Kubernetes cluster, and someone has to run that cluster.
  2. A pod has to start for every task, so task latency tends to be higher than with Celery workers that are already up. The docs say as much.
  3. The backend database can’t be SQLite.
  4. Without persistent or remote logging, logs are lost when the worker pods shut down.

Running more than one executor

Since Airflow 2.10 you can configure several executors at once (a comma-separated list, with the first as the default), and pick one per task. This replaced the old hybrid CeleryKubernetesExecutor and LocalKubernetesExecutor, which are no longer supported as of Airflow 3.0.


Now that we have understood Airflow’s basics, let’s learn how to put these pieces to work. Start with Dynamic Task Mapping or Airflow operators comparison.