Apache Airflow
Build, schedule and operate pipelines with Apache Airflow: DAG files, operators, the TaskFlow API, connections, XComs, scheduling and production best practices.
Intermediate · about 10 hours · difficulty 3/5
Learn first: Orchestration Concepts
Apache Airflow is the most widely used orchestrator and appears in the majority of Indian data engineering job descriptions. Managed versions include AWS MWAA, Google Cloud Composer and Astronomer.
Architecture
- Scheduler decides what should run; executors (Local, Celery, Kubernetes) run tasks; the webserver or API server provides the UI; a metadata database stores state.
- DAGs are Python files in a DAGs folder, parsed regularly.
Writing DAGs
- Define a DAG with
schedule,start_date,catchupand defaultretries. - Operators do work:
BashOperator,PythonOperator, provider operators for S3, BigQuery, Snowflake, Databricks,KubernetesPodOperator. - The TaskFlow API (
@dag,@taskdecorators) makes Python DAGs cleaner and passes small values between tasks via XComs. - Connections and variables store credentials and config outside code (ideally backed by a secrets manager).
- Templating with
{{ ds }}and other macros injects the logical date into commands and SQL.
Running and operating
- Run locally with the official Docker Compose setup or the Astro CLI.
- Trigger runs, clear failed tasks, and run backfills from the CLI or UI.
- Use pools to limit concurrency against fragile sources.
- Datasets or assets let one DAG trigger when another updates a table.
Best practices
- Keep top-level DAG code light; heavy imports and API calls at parse time slow the scheduler.
- Make every task idempotent and parameterised by the logical date.
- Do not pass large data through XComs; pass paths or table names.
Pitfalls
catchup=Truewith an oldstart_datelaunching hundreds of runs on deploy.- Doing heavy pandas processing inside Airflow workers instead of delegating.
You are ready to move on when you can run Airflow in Docker, write a TaskFlow DAG that extracts, loads and triggers dbt for a logical date, and backfill a week of runs.
Key concepts
- Scheduler, executor, metadata DB
- DAG definition and schedules
- Operators and providers
- TaskFlow API
- XComs
- Connections and variables
- Jinja templating and ds
- Backfills and catchup
- Pools and concurrency
- MWAA and Cloud Composer
Other options for this step
- Dagster: Orchestrate pipelines as software-defined assets with Dagster: assets, partitions, resources, sensors and built-in lineage and observability.
- Prefect: Orchestrate Python workflows with Prefect: flows, tasks, retries, caching, deployments, work pools and the Prefect UI.
Mini project
Run Airflow with Docker Compose. Build a DAG that pulls data from a public API for the logical date, writes Parquet to MinIO, loads it into Postgres or DuckDB, runs dbt build, and posts a failure alert. Backfill 7 days and screenshot the grid view.
Check yourself
You deploy a DAG with start_date one year ago and catchup enabled. What happens, and how do you prevent it?
Free resources
- Apache Airflow documentation (Apache Airflow)
- Airflow best practices (Apache Airflow)
- Data Engineering Zoomcamp (DataTalksClub)