Airflow & DAGs · Advanced Development

How do you handle branching?

MediumbranchingBranchPythonOperator

Interview question

How do you handle branching in Airflow?

How to answer

The short answer

Branching chooses one path based on a condition:

BranchPythonOperator (or TaskFlow branching) returns the task id(s) to follow; non-selected branches are skipped.

Python
def choose_branch():
    return "process" if data_is_valid else "alert"