0
0
Apache Airflowdevops~10 mins

Task dependencies (>> and << operators) in Apache Airflow - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Task dependencies (>> and << operators)
Define Task A
Set Dependency
Execution Order
Task Runs in Order
This flow shows how two tasks are defined and linked using >> or << operators to set execution order.
Execution Sample
Apache Airflow
task1 >> task2
# or
# task2 << task1
This code sets task1 to run before task2 using the >> operator (or equivalently << operator).
Process Table
StepActionOperatorDependency SetResulting Order
1Define task1N/ANoneNo order yet
2Define task2N/ANoneNo order yet
3Set dependency task1 >> task2>>task1 before task2task1 runs before task2
4Check dependency task2 << task1<<task1 before task2task1 runs before task2
5Execute tasksN/Atask1 before task2task1 runs first, then task2
6EndN/AN/AExecution complete
💡 Execution stops after tasks run in the defined order.
Status Tracker
VariableStartAfter Step 3After Step 5Final
task1DefinedDependency set as upstreamExecuted firstCompleted
task2DefinedDependency set as downstreamExecuted secondCompleted
Key Moments - 3 Insights
Why does task1 >> task2 mean task1 runs before task2?
Because the >> operator sets the left task as upstream, so task2 waits for task1 to finish (see execution_table step 3).
Is task2 << task1 the same as task1 >> task2?
Yes, << sets the right task as downstream, so task2 << task1 means task1 runs before task2 (see execution_table step 4).
What happens if no dependencies are set between tasks?
Tasks run independently and may execute in any order or in parallel (see execution_table steps 1 and 2).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what dependency is set at step 3?
ANo dependency set
Btask2 runs before task1
Ctask1 runs before task2
DTasks run in parallel
💡 Hint
Check the 'Dependency Set' column at step 3 in the execution_table.
At which step do tasks actually execute in order?
AStep 2
BStep 5
CStep 3
DStep 6
💡 Hint
Look for 'Execute tasks' action in the execution_table.
If we remove the dependency operator, what changes in the execution?
ATasks run independently or in parallel
BTasks run in defined order
CTasks fail to run
DTasks run twice
💡 Hint
Refer to key_moments about no dependencies set (execution_table steps 1 and 2).
Concept Snapshot
Task dependencies in Airflow use >> and << operators.
'task1 >> task2' means task1 runs before task2.
'task2 << task1' means the same.
Without dependencies, tasks run independently.
Use these operators to control execution order.
Full Transcript
In Airflow, you define tasks and set their execution order using the >> and << operators. For example, 'task1 >> task2' means task1 must finish before task2 starts. The >> operator sets the left task as upstream, so the right task waits. The << operator works the opposite way but achieves the same result. If no dependencies are set, tasks run independently and may execute in any order or in parallel. This visual trace showed defining tasks, setting dependencies, and the resulting execution order step-by-step.