Airflow Datasets

A dataset is a named piece of data that Airflow tracks. One DAG declares that it updates the dataset. Another DAG declares that it needs the dataset. Airflow starts the second DAG the moment the first one finishes its update. This style is called data-aware scheduling.

The Newspaper Picture

A newspaper printing press starts printing only after the editor finishes the front page. The press does not look at the clock. The finished page is the signal. Datasets work the same way. The update of the data triggers the next job, and the time of day does not matter.

 Time-based:   Producer runs at 6:00   Consumer runs at 7:00   (guess)
 Data-based:   Producer updates data ──► Consumer starts at once

Why Datasets Help

Time-based chains break easily. A producer that runs late leaves the consumer working on old data. A producer that runs early wastes waiting time. Datasets remove the guesswork, and each DAG reacts to real events.

Producer and Consumer

The Producer DAG

A task lists the dataset in its outlets. When the task succeeds, Airflow records an update to that dataset.

from datetime import datetime
from airflow import DAG, Dataset
from airflow.operators.python import PythonOperator

sales_data = Dataset("s3://company-data/sales/daily.csv")

def build_sales_file():
    print("Sales file updated")

with DAG("sales_producer", start_date=datetime(2024, 1, 1),
         schedule="@daily", catchup=False) as dag:

    build = PythonOperator(
        task_id="build_sales_file",
        python_callable=build_sales_file,
        outlets=[sales_data],
    )

The Consumer DAG

The consumer sets the dataset as its schedule. The scheduler starts a run after each producer update.

def make_report():
    print("Report built from fresh sales data")

with DAG("sales_consumer", start_date=datetime(2024, 1, 1),
         schedule=[sales_data], catchup=False) as dag:

    report = PythonOperator(task_id="make_report", python_callable=make_report)

The Flow

┌────────────────────┐   success   ┌──────────────────┐
│ sales_producer     │ ──────────► │  Dataset updated │
│  build_sales_file  │             └────────┬─────────┘
└────────────────────┘                      │ triggers
                                            ▼
                                  ┌──────────────────┐
                                  │ sales_consumer   │
                                  │  make_report     │
                                  └──────────────────┘

The Dataset Name

The string you pass to Dataset acts as a label. Airflow does not open the file or check its content. It only tracks that a task claimed to update it. Pick a clear, unique string, such as a storage path or a table name.

Waiting for Several Datasets

schedule=[sales_data, customer_data]

A list means the consumer waits until every listed dataset has an update since its last run. Newer Airflow versions also support logical expressions, so a consumer can start when either dataset updates.

Seeing Datasets in the UI

Open the Datasets page from the top menu. The page lists each dataset, shows which DAGs produce it, which DAGs consume it, and when the latest update arrived. A graph view displays the full chain across DAGs.

Datasets Compared with Other Options

MethodTrigger Based OnBest For
Cron scheduleClock timeIndependent jobs
ExternalTaskSensorState of another DAG taskTight date alignment
DatasetsUpdate of a named datasetProducer and consumer pipelines

Version Note

Airflow 3 renames datasets to assets. The idea stays identical, and the code uses Asset in place of Dataset. Check the version of your installation before you copy an example.

Good Habits

  • Declare outlets only on the task that truly writes the data.
  • Use one clear naming pattern for dataset labels across the team.
  • Keep consumers fast, since an update can arrive many times a day.

Key Takeaways

  • Outlets announce an update and the schedule list listens for it.
  • Data-aware scheduling replaces fragile timing guesses.
  • The UI maps all producer and consumer links.