Sunday , November 29 2026
Airflow DAGs, tasks, operators and schedules with a daily ETL example using the TaskFlow API, retries and backfills.

Apache Airflow Tutorial: Schedule ETL Pipelines with DAGs

Updated: 28 November 2026Level: IntermediateReading time: about 10 minutesApache Airflow 2.x / 3.x

Apache Airflow schedules and monitors data pipelines. You describe a workflow in Python as a DAG (directed acyclic graph) of tasks – extract, transform, load, train – and Airflow runs it on schedule, retries failures and shows everything in a web UI.

What You Will Learn

  • DAGs, tasks, operators and schedules
  • Write a daily ETL DAG with the TaskFlow API
  • Dependencies, retries and backfills
  • Run Airflow locally
  • Airflow vs cron

Prerequisites

ETL Pipelines.

Why Not Just cron?

cron Airflow
Runs a command at a time Runs a graph of dependent tasks
No retry or history Retries, alerts, logs and run history
No UI Web UI to see, re-run and backfill

Install and Start

Example
pip install apache-airflow
airflow standalone        # starts the scheduler and the UI at http://localhost:8080
Note: For production, follow the official installation guide (it uses a constraints file) or the official Docker Compose setup. Airflow versions differ slightly in imports; check the docs for yours.

A Daily ETL DAG

dags/orders_etl.py
from datetime import datetime, timedelta
from airflow.decorators import dag, task

@dag(schedule="@daily", start_date=datetime(2026, 1, 1), catchup=False,
     default_args={"retries": 2, "retry_delay": timedelta(minutes=5)},
     tags=["etl"])
def orders_etl():

    @task
    def extract():
        import pandas as pd
        return pd.read_csv("/data/raw_orders.csv").to_dict("records")

    @task
    def transform(rows):
        clean = [r for r in rows if r["amount"] and r["amount"] > 0]
        return clean

    @task
    def load(rows):
        print(f"Loading {len(rows)} rows into the warehouse")

    load(transform(extract()))

orders_etl()

Explanation: Each @task function becomes a task; calling them inside the DAG sets the order extract → transform → load. schedule="@daily" runs it once a day, and failed tasks retry twice, five minutes apart. Small results are passed between tasks automatically (XCom); pass file paths, not large data.

Setting Meaning
schedule “@hourly”, “@daily”, or cron like “0 2 * * *” (2 am)
start_date First date the DAG is considered for
catchup If True, runs all missed intervals since start_date (backfill)
retries How many times to retry a failed task

Operators

Operator Runs
PythonOperator / @task Python code
BashOperator A shell command
SQL operators Queries on Postgres, BigQuery, Snowflake…
Sensors Wait for a file, a table or another DAG
KubernetesPodOperator A container on Kubernetes

ML Pipelines with Airflow

A typical ML DAG: extract new data → validate → train → evaluate → register in MLflow if better → deploy. Airflow handles the scheduling and order; each step can be a Python task or a container.

Common Errors

Problem Cause and fix
DAG not visible The file must be in the dags folder and import without errors – check the UI’s import errors.
Tasks run for old dates Set catchup=False.
XCom too large Save data to files or a database and pass the path.

Series

Data Engineering series: ETL Pipelines · Apache Spark · Apache Kafka · Apache Airflow · Data Warehousing · Data Lakes · Big Data Analytics

Interview Questions

Q: What is a DAG?
A directed acyclic graph: tasks with dependencies and no cycles.

Q: What is backfilling?
Running a DAG for past intervals, for example after fixing a bug.

Practice Exercises

  1. Turn the ETL script from the first tutorial into an Airflow DAG.
  2. Add a task that sends a message when the load finishes.

Summary

Airflow orchestrates pipelines as Python DAGs with schedules, dependencies, retries and a monitoring UI – ideal for ETL and ML retraining workflows.

Next: Data Warehousing · CI/CD for ML

About Machine Learning

Check Also

Apache Kafka Tutorial with Python: Real-Time Data Streaming

Kafka concepts, running Kafka with Docker, Python producer and consumer, consumer groups, offsets and real-time ML uses.