Hello and welcome back to our module on Data Pipeline Orchestration.
In the last lesson, you successfully created your first simple, linear Airflow DAG. We saw how to define tasks and set a basic dependency, like task1 >> task2, to ensure a specific order of execution.
Today, we'll move beyond simple chains and explore how to build more realistic and complex workflows. Your learning goal is to implement dependencies between tasks in a data pipeline, covering patterns for parallel execution, grouping, and conditional logic. As a software and enterprise architect, you're accustomed to designing systems with parallel processes, decision points, and logical modules. This lesson will show you how to apply those same architectural patterns to data workflows in Airflow.
1. Beyond Linear: Parallel Dependencies (Fan-Out/Fan-In)
Most data pipelines involve steps that can run in parallel to save time. For instance, after extracting a primary dataset, you might want to perform several independent transformations simultaneously. This is a common architectural pattern.
- Fan-Out: A single upstream task triggers multiple downstream tasks that run in parallel.
- Fan-In: A single downstream task waits for multiple upstream tasks to complete before it starts.
In the previous lesson, you used the >> operator for a single task. To create parallel dependencies, you simply use a Python list or tuple.
Let's imagine a workflow:
start: Begins the process.process_A,process_B,process_C: Three independent processing tasks.end: A final task that runs only after all processing is complete.
The dependency definition would look like this:
# Assuming start, process_A, process_B, process_C, and end are defined tasks
start >> [process_A, process_B, process_C] >> end
start >> [process_A, process_B, process_C]is the fan-out. Thestarttask triggers A, B, and C.[process_A, process_B, process_C] >> endis the fan-in. Theendtask waits for A, B, and C to all succeed.

To solidify this fundamental concept, let's turn to a guide from Astronomer.
Manage task and task group dependencies in Airflow
This guide from Astronomer clearly explains the different ways to set dependencies. We'll start with the basics of setting one-to-many and many-to-one relationships.
Please read the introduction to understand the terms 'upstream' and 'downstream'. Then, read the 'Basic dependencies' section. Pay close attention to the example that uses a list [t2, t3] to create a fan-out dependency.
Test your understanding!
You have a pipeline that ingests customer data. The steps are:
ingest_data: Fetches the raw data.- After ingestion, you need to independently:
validate_schema: Check if the data structure is correct.check_for_duplicates: Look for duplicate records.
load_to_staging: This task should only run after bothvalidate_schemaandcheck_for_duplicatesare complete.
Write the Python code snippet that defines the dependencies for these four tasks.
Show answer
# Assuming ingest_data, validate_schema, check_for_duplicates,
# and load_to_staging are defined task objects.
ingest_data >> [validate_schema, check_for_duplicates] >> load_to_staging
This line concisely defines the fan-out from ingest_data and the fan-in to load_to_staging.
2. Grouping Tasks for Clarity and Control
As workflows grow, managing dependencies for dozens of tasks can become messy. Just as you would group related components in software architecture, you can use TaskGroup in Airflow to logically group tasks. This not only cleans up the UI but also allows you to set dependencies on the entire group at once.
Let's expand our previous example. Imagine process_A, process_B, and process_C are all part of a "processing" stage.
from airflow.utils.task_group import TaskGroup
# ... inside your DAG definition ...
start = EmptyOperator(task_id="start")
end = EmptyOperator(task_id="end")
# Define the TaskGroup
with TaskGroup(group_id="processing_tasks") as processing_group:
process_A = BashOperator(task_id="process_A", bash_command="echo 'Processing A'")
process_B = BashOperator(task_id="process_B", bash_command="echo 'Processing B'")
process_C = BashOperator(task_id="process_C", bash_command="echo 'Processing C'")
# Set dependencies *within* the group
process_A >> process_B >> process_C
# Set dependencies on the group as a whole
start >> processing_group >> end
In this example, the main dependency chain is clean (start >> processing_group >> end), while the internal logic of the processing stage is encapsulated within the TaskGroup.
The Astronomer guide provides a clear illustration of this.
Manage task and task group dependencies in Airflow
Let's return to the Astronomer guide to see how dependencies are set with Task Groups.
Read the 'Task group dependencies' section. Focus on the example showing how dependencies can be set both inside and outside the task group context (t0 >> tg1() >> t3).
3. Conditional Dependencies with Branching
Sometimes, the path of your workflow depends on the outcome of a task. For example:
- If a data quality check passes, proceed with loading the data.
- If it fails, trigger an alert and stop the main pipeline.
This is achieved through branching. A special type of task, a branch operator, dynamically chooses which downstream task(s) to run based on some logic.

The most common way to implement this is with the @task.branch decorator. You decorate a Python function that returns the task_id (or a list of task_ids) of the next task(s) to execute. All other direct downstream paths will be skipped.
from airflow.decorators import task
# ... other task definitions ...
@task.branch
def check_data_quality(**kwargs):
# This is placeholder logic. In reality, you'd check a condition.
data_is_good = True
if data_is_good:
return "continue_processing"
else:
return "send_failure_alert"
# Define the tasks
data_quality_check = check_data_quality()
continue_processing = BashOperator(task_id="continue_processing", ...)
send_failure_alert = BashOperator(task_id="send_failure_alert", ...)
# Set the branching dependency
data_quality_check >> [continue_processing, send_failure_alert]
This setup creates the branches, but it raises a new question: what if you have a task that needs to run after the branch, regardless of which path was taken (e.g., a cleanup task)? This is where trigger rules come in.
4. Controlling Execution with Trigger Rules
By default, an Airflow task only runs if all of its upstream tasks have succeeded. This is the all_success trigger rule.
In our branching example, if data_quality_check returns "continue_processing", the send_failure_alert task will be put in a skipped state. If a join_task is downstream of both, it will also be skipped by default because one of its parents (send_failure_alert) did not succeed.
To handle this, you must change the trigger_rule on the "join" task.
from airflow.utils.trigger_rule import TriggerRule
# ... branching setup from before ...
join_task = BashOperator(
task_id="join_task",
bash_command="echo 'This runs after the branch.'",
trigger_rule=TriggerRule.NONE_FAILED_MIN_ONE_SUCCESS
)
# Set final dependencies
continue_processing >> join_task
send_failure_alert >> join_task
The none_failed_min_one_success rule means the task will run as long as at least one parent succeeded and no parents failed. This is perfect for joining branches, as one path is skipped (not failed) and one succeeds.
Let's consult the official documentation for a deeper dive into these control flow mechanisms.
Dags — Airflow 3.1.6 Documentation
The official Airflow documentation provides a great overview of control flow concepts, including branching and the all-important trigger rules.
First, read the 'Branching' section to see an example of using @task.branch. Then, read the 'Trigger Rules' section. Focus on the list of available rules and the note about why the default all_success rule is often not what you want downstream of a branching operation.
Conclusion
You've now moved well beyond simple, linear pipelines. You have the tools to construct sophisticated workflows that mirror complex business logic, a critical skill for a data architect.
Key Takeaways:
- Parallelism: Use lists/tuples with
>>and<<for fan-out and fan-in dependency patterns. - Abstraction: Use
TaskGroupto logically organize tasks and simplify high-level dependency management. - Conditional Logic: Implement dynamic workflows using the
@task.branchdecorator to choose an execution path. - Execution Control: Use the
trigger_ruleparameter on tasks to override the default "all success" behavior, which is essential for joining branches correctly.
In our next lesson, we will focus on scheduling and monitoring data pipeline executions. Now that you can build complex DAGs, the next step is to learn how to manage their lifecycle—running, scheduling, and observing their performance—using the Airflow UI.