Orchestrating ML Pipelines with Airflow: Schedule, Retries and Backfill
Apache Airflow as an air traffic controller for your pipeline: what it is made of, the page you look at, and the three jobs it takes over (schedule, retries, backfill), with the ticket pipeline written as an Airflow DAG.
What you will learn
- Explain what an orchestrator does, and what it leaves to your own steps
- Name Airflow's parts: scheduler, workers, database and web page
- Describe the three jobs Airflow takes over: a schedule, retries and backfill
- Read a small Airflow DAG file that wires up the six training steps
Before you start
- The Training Pipeline as a DAG
In the training pipeline as a DAG, our six steps became a graph: ingest, features, baseline, train, evaluate and publish. A small scheduler ran them in order, retried the ones that could heal and blocked the rest. But someone still has to type python scheduler.py run --day 3 every day. Today the steps get a clock, and the tool is Apache Airflow.
An air traffic controller
An air traffic controller doesn't fly a single plane. Its job is deciding who goes when, one plane at a time. When a flight's delayed, it says hold, or try again.
That's Airflow. Your steps do the work, and Airflow decides who goes when. A tool that does this is called an orchestrator.
What Airflow is made of
Your steps stay exactly the same. Around them, Airflow adds four parts:
- The scheduler is the tower. It watches the clock and the graph.
- Workers are the planes. They run your code.
- A database remembers every run.
- A web page shows you all of it.
The page you look at
The Airflow web page has a Graph view for each pipeline. Each box is one task, and each line is an arrow, the same kind of graph we drew. There's also a list of pipelines, where each row is one pipeline. A failed run shows up in red, so a break at night is the first thing you see in the morning. The UI page in the Airflow docs shows each of these views.
Three jobs Airflow takes over
- Schedule. You say daily, and it starts a run every day.
- Retries. A step fails on a network blip, Airflow tries again, and the third try works. This is the same idea as our
RETRYABLErule, now set per task. - Backfill. You pick Backfill, give it a date range, and it fills in the missed days. Our scheduler had
backfill --start 1 --end 6; Airflow gives you a window in the web page for it.
For a small project, Prefect is a lighter option with the same ideas.
The ticket pipeline as an Airflow DAG
The project includes airflow_dag.py, the same six steps handed to Airflow. It needs an Airflow setup to run, so treat it as a file to read, not something to run on your laptop as-is:
"""The ticket-priority pipeline as an Airflow DAG (needs an Airflow setup)."""
import os
from datetime import timedelta
from pathlib import Path
import pendulum
from airflow.sdk import DAG, task
from steps import STEPS, LAST_DAY
FIRST = pendulum.parse(os.environ["FIRST_DAY"])
RUNS = Path("runs")
@task
def run_step(name, logical_date=None):
day = (logical_date - FIRST).days + 1
out = RUNS / f"day-{day}"
out.mkdir(parents=True, exist_ok=True)
return STEPS[name](day, out)
with DAG(
"ticket_priority",
schedule="@daily",
start_date=FIRST,
end_date=FIRST.add(days=LAST_DAY - 1),
catchup=False,
default_args={
"retries": 2,
"retry_delay": timedelta(seconds=1),
},
):
s = {n: run_step.override(task_id=n)(n)
for n in STEPS}
s["ingest"] >> s["features"]
s["features"] >> [s["baseline"], s["train"]]
[s["baseline"], s["train"]] >> s["evaluate"]
s["evaluate"] >> s["publish"]
Read it against what you already know:
STEPSis imported from the samesteps.py. The step code doesn't change.schedule="@daily"is the clock.start_dateandend_datefix the window of days."retries": 2gives every task up to three tries, like our scheduler.>>draws an arrow. The four lines at the bottom are the same graph as theDAGdictionary: the split after features and the join at evaluate.- The day number comes from the run's
logical_date, so each daily run writes into its ownruns/day-Nfolder.
Common mistakes
- Putting the heavy work in the orchestrator. Airflow decides who goes when. The steps stay plain Python you can run and test without it.
- Retries without a reason. Retries help with blips. A bug fails the same way three times. See retries and backoff for how to choose what to retry.
- Ignoring the red runs. The page only helps if someone looks at it. A failed run is a missing model for that day.
Recap
| Idea | What it means |
|---|---|
| Orchestrator | Decides who goes when; your steps do the work |
| Parts | Scheduler, workers, database, web page |
| Three jobs | Schedule, retries, backfill |
| One page | Graph view, pipeline list, failed runs in red |
Try it yourself: open the Airflow docs UI overview page and find the Graph view, the pipeline list and the backfill window.
Built this? Share your solution in the StudyEasy AI Community.
Join free on Skool →The Training Pipeline as a DAG: Steps, Files, Retries and a Safe Rerun
Next →Retries and Backoff for Reliable Tasks: Retry What Heals, Wait Longer, Add Jitter, Set Limits
StudyEasy AI Community
Learn AI engineering, share what you build, and connect with other learners.
Free resources: lesson files, notebooks and code
Ask questions and join engineering discussions
Meet real people learning and building with AI
Machine Learning Engineer: From First Model to ML Engineer
Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (opens in a new tab)Related articles
Python Virtual Environments: One Project, One Toolbox
Why every Python project gets its own virtual environment: two projects that need different versions of requests, python -m venv .venv, activation, pip install and the PyCharm setting that activates it for you.
Git and GitHub Fundamentals: Commits, Branches, Push and Pull
The Git you use every day, on a tiny hello-ml project: commits as save points, the staging area, a branch merged with a fast-forward, then push, clone, pull and pull requests with a teammate.
Testing a FastAPI App with pytest: Three Small Tests
A tiny FastAPI app with a Hello World route and a name route that refuses numbers, three pytest tests that check it, and what happens when the validation is deleted by mistake.
Config and Logging Instead of Hard-Coded Values in ML Training
Take the hard-coded values out of a car price training script: one config.toml read with tomllib, logging with levels and a run id on every line, and secrets read from the environment. Same RMSE, 2195, before and after.