Skip to content
Silver 4 min read · Control flow 1 practice problem ↓

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

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:

Python · dags/charts_refresh.py · a big day gets the full rebuild
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 \ runMar 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 joinBranch ran and succeededBranch ran and failedEvery branch skipped
all_success (default)Skipped (a sibling was skipped)upstream_failedSkipped
all_doneRunsRuns: wrong, it publishes after a failureRuns
one_successRuns, possibly before a slower branch finishesupstream_failed if none succeededSkipped
none_failed_min_one_successRuns, after every branch finishedupstream_failedSkipped

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).

Python · monthly work inside a daily DAG
# 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
Note: decide from the run's 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?"

The branch skips the path it did not choose, and the join's default trigger rule all_success skips a task when any upstream task was skipped. Set the join to none_failed_min_one_success: it waits until every branch is finished, runs if none failed and at least one succeeded, and becomes upstream_failed when the chosen branch fails. all_done would be wrong because it also runs after a failure, and one_success can start before a slower branch finishes.

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?"
It only skips its direct children that were not chosen. Tasks further down are skipped by their trigger rules: under all_success a skipped upstream task skips them too, which is why joins need a different rule.
Scenario"A daily DAG must also run a heavy monthly step on the last day of the month. How?"
A short-circuit task in front of the monthly step that returns whether the logical date is a month end; on other days it returns False and the monthly part is skipped. Or a separate monthly DAG, if the step does not depend on the daily run's output.
Trap"A branch can return a task far downstream to jump to it."
Only direct children are chosen or skipped. Returning a task that is not a direct child skips the direct children, and the target may never run because its upstream tasks were skipped.

Check yourself

3 questions

A 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 read
XCom: 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