Branching and short-circuiting
Some pipelines take different paths depending on the data: a full reload on Sundays, an incremental load otherwise. Branching lets a task choose which tasks run next. This lesson shows how, and how skipped tasks affect the rest of the DAG.
Pipelines in production · Airflow · Silver · Control flow, lesson 1 of 3
On this page
Read first: Trigger rules and run state (skip if you know it)
In plain words first
At a fork in the road, the driver picks one way and the other road is simply not taken. Further on, the roads may meet again, and the meeting point must not wait for a car on the road nobody took.
A branch tasktask: One step of a DAG, such as running a query or calling an API. Each run of a task for one date is a task instance. Learn more → picks the path; the other tasks are skipped, and the task where paths meet needs the right trigger ruletrigger rule: The condition that lets a task start, based on its upstream tasks: all succeeded (the default), one failed, all done, and so on. Learn more →.
Choosing a path at run time
A branch task returns the task_id (or a list of them) to follow. Every other task directly downstream of it is skipped, and under the default trigger rule the skip travels on to their downstream tasks. The choice can depend on the date or on data an upstream task computed:
import pendulum from airflow.sdk import DAG, task from airflow.providers.standard.operators.bash import BashOperator with DAG( dag_id="charts_refresh", schedule="@daily", start_date=pendulum.datetime(2026, 3, 1, tz="UTC"), catchup=True, ): @task def count_new_releases(ds=None): return {"2026-03-01": 3, "2026-03-02": 41}.get(ds, 0) @task.branch def pick_refresh(new_releases): return "rebuild_all" if new_releases > 20 else "update_changed" rebuild = BashOperator( task_id="rebuild_all", bash_command="rebuild_charts --day {{ ds }}" ) update = BashOperator( task_id="update_changed", bash_command="update_charts --day {{ ds }}" ) notify = BashOperator( task_id="notify", bash_command="notify_editors --day {{ ds }}", trigger_rule="none_failed_min_one_success" ) pick_refresh(count_new_releases()) >> [rebuild, update] >> notify
What the schedulerscheduler: The Airflow process that reads DAG files, creates runs when they are due, and queues the tasks whose upstream tasks are done. Learn more → does · deployed Mar 1, 00:00 UTC · grid as of Mar 2, 01:00 UTC · @daily (CronTriggerTimetable)
| task \ run | Mar 1 00:00 | Mar 2 00:00 |
|---|---|---|
| count_new_releases | ||
| pick_refresh | ||
| rebuild_all | ||
| update_changed | ||
| notify |
successskipped· the bar on top is the run's state; a number is how many tries
Each day one refresh runs and the other is skipped, and notify runs after whichever ran. With the default all_success it would be skipped every day, because one of its upstream tasks is always skipped.
Joining branches
| Rule on the join | Branch ran and succeeded | Branch ran and failed | Every branch skipped |
|---|---|---|---|
all_success (default) | Skipped (a sibling was skipped) | upstream_failed | Skipped |
all_done | Runs | Runs: wrong, it publishes after a failure | Runs |
one_success | Runs, possibly before a slower branch finishes | upstream_failed if none succeeded | Skipped |
none_failed_min_one_success | Runs, after every branch finished | upstream_failed | Skipped |
Short-circuit: run the rest or skip it
When the question is not "which path" but "anything at all today?", a short-circuit task is simpler. It returns a truthy or falsy value; falsy skips everything downstream of it (by default all the way down, regardless of trigger rules).
# build_royalty_statements and email_labels are two tasks of this DAG @task.short_circuit def is_month_end(logical_date=None): return (logical_date + timedelta(days=1)).day == 1 is_month_end() >> build_royalty_statements >> email_labels
logical_date or upstream results, never from the clock: a rerun of last month-end must take the month-end path again.Common mistakes
- The join after a branch keeps all_success — It is skipped on every run.
- all_done on the join — It runs even when the chosen branch failed.
- Returning a task_id that is not directly downstream — Its siblings are skipped but it may never run; branch only to direct children.
- Branching on datetime.now() — Reruns take today's branch, not the run's.
Key takeaways
- A branch returns the task_ids to follow; other direct children are skipped.
- Skips travel down under all_success.
- Join branches with none_failed_min_one_success.
- A short-circuit skips everything downstream on a falsy result.
Interview prep
THE QUESTION
"After a branch, the join task is skipped every day. Why, and what is the fix?"
Avoid: branching on datetime.now() or a Variable read at parse time. The branch must depend on the run, so a rerun takes the same path.
Follow-ups · answer out loud, then open
Follow-up"What does a branch task do to tasks further down, not directly after it?"
Scenario"A daily DAG must also run a heavy monthly step on the last day of the month. How?"
Trap"A branch can return a task far downstream to jump to it."
Check yourself
3 questionsA branch returns "a". Its direct children are a and b. What happens to b?
Show the answer
It is skipped. Every direct child not chosen is skipped.
Which trigger rule fits the join after a branch?
Show the answer
none_failed_min_one_success. It accepts skipped branches, refuses failed ones and needs one success.
A short-circuit returns False. What happens downstream?
Show the answer
Everything downstream is skipped. By default it skips all downstream tasks, ignoring their trigger rules.
Practise this
Problems that use this, graded on hidden tests
Keep going
Up next · Control flow · lesson 2 of 3 · 4 min readXCom: passing data between tasks
Return values, TaskFlow arguments and xcom_pull, and what should never go through XCom.
Related lessons
Previous: Trigger rules and run state
Primary sources: Branching · ShortCircuitOperator