Lesson 04 Airflow Basics
Theme:
Lesson 04 · Slide 1

Lesson 04 — Airflow Basics

From a Python script to a scheduled, monitored, replayable pipeline.

Data Engineering Module 2 Orchestration
Lesson 04 · Slide 2

Why orchestration?

A cron line is fine until it isn't. Here's what breaks first:

Four jobs of an orchestrator

Schedule · Dependency · Retry · Observability

Lesson 04 · Slide 3

What is Airflow?

Apache Airflow is an open-source workflow scheduler originally created at Airbnb in 2014 and donated to the Apache Software Foundation in 2016, where it graduated as a top-level project. It is now the dominant data-pipeline orchestrator in the industry.

Lesson 04 · Slide 4

Three core abstractions

AbstractionWhat it isExample
DAG The workflow — a Python file declaring tasks and their execution order gharchive_hourly
Task One unit of work; one task instance is created per DagRun extract, transform
Operator The type of task — defines what code runs when the task executes PythonOperator, BashOperator, BranchPythonOperator
Lesson 04 · Slide 5

What a DAG looks like in code

from airflow import DAG
from airflow.operators.python import PythonOperator
from datetime import datetime

with DAG(
    dag_id="gharchive_hourly",
    start_date=datetime(2026, 5, 1),
    schedule=None,         # we'll schedule it in Lesson 05
    catchup=False,
) as dag:
    extract = PythonOperator(task_id="extract", python_callable=extract_hour)
    transform = PythonOperator(task_id="transform", python_callable=transform_hour)
    extract >> transform   # task dependency

>> is Airflow's "set downstream" operator. extract >> transform means: run transform only after extract succeeds.

Lesson 04 · Slide 6

The Airflow stack at runtime

Core components

  • Scheduler — the loop that reads DAGs, decides what to queue, and sends task instances to the executor
  • Executor — runs the tasks; LocalExecutor for one machine, CeleryExecutor or KubernetesExecutor for distributed workloads
  • Webserver — the Flask-based UI at port 8080
  • Metadata DB — Postgres (or MySQL) that stores every DAG run, task state, and log pointer

For this course

All four components run as Docker containers on your laptop via docker compose up. The LocalExecutor is sufficient for development workloads.

Lesson 04 · Slide 7

Running Airflow locally

cd data-engineering/sample-pipeline/airflow
docker compose up -d
open http://localhost:8080  # admin / admin
Note: Not production-grade — no TLS, no secret rotation, no resource limits. Purpose-built for course labs.
Lesson 04 · Slide 8

The DAGs folder

Airflow continuously scans the dags/ directory every 30 seconds (configurable via dag_dir_list_interval). Each .py file that contains a DAG object becomes a discoverable workflow in the UI.

The first DAG we add is gharchive_hourly — a thin wrapper that calls the Module 1 extract_hour and transform_hour functions.

Lesson 04 · Slide 9

Triggering a manual run

In Lesson 04 the DAG has schedule=None — it only ever runs when you explicitly trigger it. This is intentional: learn the mechanics before adding a schedule.

Lesson 04 · Slide 10

The task instance lifecycle

none → scheduled → queued → running → success

On failure: failed → (if retries > 0) up_for_retry → scheduled → queued → running → ...

Or: skipped (upstream failed or branched away)

Every box in the UI Grid view represents one task instance in one of these states. Click any box to see the full lifecycle history and logs for that attempt.

Lesson 04 · Slide 11

Where the Module 1 script fits

The DAG is a thin wrapper — it does not duplicate the extract or transform logic. It calls the functions that already exist in sample-pipeline/extract/ and sample-pipeline/transform/.

def _extract(**context) -> None:
    """L04: hardcoded hour. L05 replaces with context['data_interval_start']."""
    from extract.gharchive import fetch_hour
    fetch_hour(hour="2026-05-01-12")  # hardcoded for L04; parameterized in L05

Note the deferred import inside the function body. Airflow re-imports every DAG file every 30s — keeping heavy imports inside the callable keeps the scheduler heartbeat fast.

Lesson 04 · Slide 12

Web UI tour

Lesson 04 · Slide 13

Common gotchas

Lesson 04 · Slide 14

Recap & what's next

Coming up: Lesson 05 — schedules, catchup, and the data-interval-aware DAG pattern.
1 / ?