In this lesson, you will learn how to trigger downstream DAGs automatically whenever a specific data file or object is successfully updated, decoupling your workflows from rigid time-based schedules.
Moving Beyond Time-Based Scheduling
Until now, you have likely relied on schedule_interval (like CRON strings) to run your DAGs. However, in modern data pipelines, your downstream DAGs often don't need to run at 2:00 AM; they need to run the moment the upstream "Producer" DAG finishes writing its output. Airflow’s Dataset feature allows you to shift from "schedule-based" to "data-driven" orchestration.
How Datasets Work
A Dataset represents a logical data unit, such as an S3 file path or a database table. When a task in an upstream DAG finishes successfully, it "updates" a dataset. Downstream DAGs can then be configured to listen for these updates, triggering themselves automatically.
Here is how you define a producer and a consumer:
from airflow import DAG, Dataset
from airflow.operators.bash import BashOperator
# The logical definition of our data dependency
my_data_file = Dataset("s3://logs/daily_report.csv")
# Producer DAG
with DAG(dag_id="producer_dag", schedule="@daily", ...) as dag:
BashOperator(
task_id="write_data",
bash_command="echo 'data' > /tmp/report.csv",
outlets=[my_data_file] # This marks the dataset as updated on success
)
# Consumer DAG
with DAG(dag_id="consumer_dag", schedule=[my_data_file], ...) as dag:
BashOperator(
task_id="process_data",
bash_command="cat /tmp/report.csv"
)
Why Use This?
- Efficiency: The
consumer_dagonly runs when the data is actually ready, preventing wasted compute cycles on empty or missing data. - Decoupling: You no longer need to know the internal schedule of the upstream DAG. You simply express a dependency on the data itself.
- Multi-source Dependencies: You can pass a list of datasets to a DAG’s
scheduleparameter; the DAG will trigger only after all listed datasets have been updated.
This mechanism turns your individual DAGs into a cohesive, responsive pipeline where the data flow, not the clock, dictates execution.
Key Takeaway: Dataset scheduling allows you to move away from rigid temporal triggers by creating reactive, event-driven workflows that execute precisely when the underlying data dependencies are satisfied.