How to Set Task Dependencies with Bitshift Operators (>> and <<) in Apache Airflow®
In Apache Airflow®, a Dag's tasks run in the order you set between them. a >> b says a runs before b, and b << a says the same thing from the other side. Put tasks in a list and they all get the same place in the order, so they can run side by side. This guide sets the order of a four-task Dag on Airflow 3.4.0 and checks it in a real run.
Syntax
<upstream task> >> <downstream task>
<downstream task> << <upstream task>
<task> >> [<task>, <task>] >> <task>
| Part | What it means |
|---|---|
<upstream task> | The task that runs first |
<downstream task> | The task that waits for it |
>> | The task on the left runs before the task on the right |
<< | The task on the right runs before the task on the left |
[<task>, <task>] | A list: each task in it gets the same dependency, and they don't wait for each other |
Airflow's Tasks documentation names the two operators: "There are two ways of declaring dependencies - using the >> and << (bitshift) operators", or the set_upstream and set_downstream methods. It recommends the operators, "as they are easier to read in most cases."
The Example
A Dag called make_breakfast has four tasks. boil_water comes first. brew_tea and toast_bread both wait for it, and neither needs the other. serve waits for both.
Prerequisites
- Apache Airflow® running, for example with
airflow standalone, and itsdagsfolder in yourAIRFLOW_HOME.
Step 1: Write the Four Tasks
Create dags/make_breakfast.py. Each task only prints what it does:
from airflow.sdk import dag, task
@dag(schedule=None, tags=["demo"])
def make_breakfast():
@task
def boil_water():
print("Boiling water")
@task
def brew_tea():
print("Brewing tea")
@task
def toast_bread():
print("Toasting bread")
@task
def serve():
print("Serving breakfast")
Without dependencies, the four tasks have no order: none of them waits for another, so Airflow could start all four at once.
Step 2: Set the Order with >>
Still inside the Dag function, call each task function once and keep what it returns:
boil = boil_water()
tea = brew_tea()
toast = toast_bread()
breakfast = serve()
Calling a task function inside a Dag doesn't run it. It adds the task to the Dag and gives you an object that stands for it, which >> can connect. Now set the order:
boil >> [tea, toast] >> breakfast
Read it left to right: boil first, then both tea and toast, then breakfast. The complete file, with the call to the Dag function at the end:
from airflow.sdk import dag, task
@dag(schedule=None, tags=["demo"])
def make_breakfast():
@task
def boil_water():
print("Boiling water")
@task
def brew_tea():
print("Brewing tea")
@task
def toast_bread():
print("Toasting bread")
@task
def serve():
print("Serving breakfast")
boil = boil_water()
tea = brew_tea()
toast = toast_bread()
breakfast = serve()
boil >> [tea, toast] >> breakfast
make_breakfast()
![The make_breakfast.py Dag file in an editor window: four @task functions, the four calls kept as boil, tea, toast and breakfast, and the line boil >> [tea, toast] >> breakfast.](https://strdewiridedevblogsprod.blob.core.windows.net/images/blog/data-engineering/apache-airflow/2026/airflow-dependencies-01-code.webp)
Step 3: Check the Order in the Graph View
Trigger the Dag (How to Trigger a Dag from the Apache Airflow® UI walks through the dialog), open it and choose the Graph view:

The graph reads left to right in the same order as the line of code. brew_tea and toast_bread sit in one column because they're in one list: both depend on boil_water, and serve depends on both.
Step 4: Check the Start Times
Open the run's Task Instances tab:

boil_water started first, at 10:28:52. brew_tea and toast_bread started in the same second once it had finished, side by side, and serve started at 10:28:55, after both. That's the order boil >> [tea, toast] >> breakfast asked for.
Step 5: Write the Same Order with <<
<< points the other way: the task on the right runs first. A second Dag, make_breakfast_backwards, has the same four tasks and ends with:
breakfast << [tea, toast] << boil
Its graph after a run:

The graph is the same as the first Dag's: << only changes how the line reads, not the order. Pick one direction per Dag so the code reads the same way throughout.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Putting a list on both sides: [a, b] >> [c, d] | Airflow's documentation says that for a list of tasks depending on another list, "you can't use either of the approaches above" | Use cross_downstream, or chain() for pairs |
| Expecting the tasks in a list to run in their listed order | They don't wait for each other: brew_tea and toast_bread started in the same second | Put >> between them if one must finish first |
Reading << as "run in reverse" | It sets the same kind of dependency, pointing the other way | Read the arrow: the task it points to runs second |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| A task runs before the one you expected | The arrow points the wrong way | Check the Graph view, and swap the two sides or use the other operator |
| Two tasks in a list ran at the same time | That's what a list means | Chain them with >> if one must wait for the other |
| A task runs as soon as the Dag starts | It has no upstream task | Add it to the dependency line |
FAQ
What do upstream and downstream mean?
The upstream task runs first and the downstream task waits for it. The Tasks documentation says "We call the upstream task the one that is directly preceding the other task." In boil >> tea, boil is upstream of tea.
Can I use methods instead of operators?
Yes. boil.set_downstream([tea, toast]) means the same as boil >> [tea, toast], and tea.set_upstream(boil) the same as tea << boil. The documentation says they "both do exactly the same thing".
Conclusion
boil >> [tea, toast] >> breakfast made boil_water run first, brew_tea and toast_bread side by side, and serve last, and breakfast << [tea, toast] << boil gave the same graph. >> runs the left side first and << the right side first; a list puts several tasks in the same place in the order.
Additional Resources
- Tasks: Relationships — upstream, downstream and the bitshift operators.
- Dags: Task Dependencies — lists,
cross_downstreamandchain.
Apache®, Apache Airflow and Airflow® are either registered trademarks or trademarks of The Apache Software Foundation in the United States and/or other countries. No endorsement by The Apache Software Foundation is implied by the use of these marks.
