Data pipelines and orchestration
A nightly sales report, built from five tasks. See how an orchestrator such as Airflow orders them, schedules them, retries failures, raises alerts and reruns past days.
In 30 seconds
A data pipeline is a chain of tasks that moves and reshapes data: extract it, combine it, load it, report on it. An orchestrator such as Apache Airflow runs those tasks for you.
You describe the tasks and which must finish before which. That forms a graph with no loops, a DAG. The orchestrator starts it on a schedule and runs each task as soon as the ones before it succeed.
When a task fails it is retried; if it keeps failing, later tasks are held back and someone is alerted. A backfill reruns the pipeline for past dates.
Data pipelines and orchestration, step by step
Task names and timings are invented. Airflow details, such as how a run is dated and the backfill command, differ between versions; the ideas are shared by other orchestrators such as Dagster and Prefect.
- Step 1: Tasks and arrows. A pipeline is a set of tasks plus the order they must run in. Here five tasks build a daily sales report. An orchestrator such as Apache Airflow stores this as a DAG, a directed acyclic graph: arrows point one way and never loop back, so there is always a task that can go first.
- Step 2: Dependencies set the order. The arrows are dependencies. A task starts only when every task pointing at it has succeeded. The two extracts depend on nothing, so they run at the same time; join_sales has to wait for both. The orchestrator works this order out from the graph, so nobody writes it down by hand.
- Step 3: The schedule starts runs. The scheduler starts a new run of the whole DAG on a timetable, here every day at midnight. Each run is tied to one day of data: the run that starts at 00:00 on 2 Oct processes the orders of 1 Oct, because only then is that day complete.
- Step 4: A task fails: retry. Tasks fail for boring reasons: a busy API, a dropped connection. So each task gets a retry policy. Here extract_payments times out twice; the orchestrator waits 5 minutes each time and tries again, and the third try works. Nobody had to be woken up.
- Step 5: Out of retries: alert. The next night the payments API stays down and all four tries fail. The task is marked failed, the tasks after it are not run, and an alert goes to the engineer on call. Stopping is deliberate: a report built from half the data is worse than a late one.
- Step 6: Backfill: rerun the past. On 5 Oct a bug in join_sales is fixed, but the reports for 1 to 4 Oct were built with the bug. A backfill runs the same DAG again for those past dates: four runs, each handed its own date. The same trick fills in history when a pipeline is brand new.
- Step 7: Make tasks safe to rerun. Retries and backfills both run a task more than once for the same day, so a rerun must not change the answer. If load_warehouse appends rows, a second run doubles the sales of 1 Oct from 120 to 240. If it replaces that day’s rows, the total stays 120. Such a task is called idempotent.
Try it yourself
Learn this first
Spotted a mistake on this page?