Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. How do you handle branching?

Airflow & DAGs · Advanced Development

How do you handle branching?

Mediumairflow-28
branchingBranchPythonOperator

Question

How do you handle branching in Airflow?

Solution

Branching chooses one path based on a condition:

        Check data
        /        \
     Valid      Invalid
       ↓           ↓
   Process       Alert

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

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