Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Tracking, Orchestration and Deployment  ›  Lesson

Orchestrating Pipelines with Airflow

Airflow 15 minAn orchestrator such as Airflow runs a pipeline as a DAG of tasks with dependencies, a schedule and retries, so retraining happens automatically and in the right order.

Orchestrating Pipelines with Airflow

Retraining the churn model each week means five steps: extract a data snapshot, validate it, train, evaluate against the champion, register the winner. A cron job running one big script can do that — until step two fails at 3 a.m. and step three happily trains on bad data. An orchestrator runs the steps as separate tasks that know about each other.

The rule

Tasks, arrows, a schedule: nothing runs before its inputs succeed.

An orchestrator runs a DAG — a directed acyclic graph. Each task is one step. Each arrow says "this task needs that one first". Acyclic means the arrows never loop back, so there is always a valid order.

Apache Airflow is the most widely used orchestrator. A DAG is a Python file:

from datetime import datetime
from airflow.sdk import dag, task

@dag(schedule="@weekly", start_date=datetime(2026, 1, 1), catchup=False)
def churn_retrain():

    @task(retries=2)
    def extract() -> str: ...          # returns the snapshot path

    @task
    def validate(path: str) -> str: ...

    @task
    def train(path: str) -> str: ...   # returns the MLflow run id

    @task
    def evaluate_and_register(run_id: str) -> None: ...

    evaluate_and_register(train(validate(extract())))

churn_retrain()

Passing one task's result into the next draws the arrows. Airflow then gives each task:

  • Its own status and logs, visible in a web UI.
  • Retries — extract retries twice, useful when a database is briefly unavailable.
  • Dependency safety — if validate fails, train and later tasks are marked upstream failed and never run.
  • Rerun from the failure — after a fix, clear the failed task and the rest continue, without repeating the successful ones.

Kubeflow Pipelines solves the same problem inside Kubernetes: each step runs as its own container, which suits teams whose training already runs on a cluster. Airflow is more general and often schedules non-ML data work too.

The shortcut

To design a DAG, draw an arrow only where data flows. If task B reads something A produced, draw A → B. If not, leave them unconnected so they can run in parallel.

Adding two feature tasksStep 1 of 4
  1. New tasks

    listening_features and billing_features both read the validated snapshot.

Drills

Answer fast — trust the rule.

quick drill

In the churn DAG, validate fails. What happens to train?

quick drill

What does "acyclic" in DAG guarantee?

quick drill

Two feature tasks read the same snapshot but not each other's output. How should they be connected?

quick drill

After fixing a bug in train, what is the main advantage of rerunning in Airflow over rerunning a cron script?

Remember

  • Tasks, arrows, a schedule: nothing runs before its inputs succeed.
  • Draw an arrow only where data flows; unconnected tasks run in parallel.
  • Trap: one giant script, where one failure means rerunning everything or training on bad data.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainDesign the DAG

Design the weekly churn retraining DAG: name the tasks, their order, and what happens when the data validation task fails. Say why this is better than a cron job running one big script.