Request a demo

Glossary · Pipelines and tooling

What is DAG (directed acyclic graph)?

A DAG, or directed acyclic graph, is a set of steps connected by one-way dependencies with no cycles. Orchestrators such as Airflow, and transformation tools such as dbt and Dataform, use DAGs to decide what runs first, what can run in parallel and what a failure blocks.

Also called: directed acyclic graph, Airflow DAG, dbt DAG, dependency graph, pipeline graph

What the three words mean

  • Graph: nodes (tasks, models, tables) connected by edges (dependencies).
  • Directed: each edge has a direction. "A before B" is not the same as "B before A".
  • Acyclic: following the edges never leads back to where you started.

Those properties guarantee a valid run order (a topological sort): run the nodes with no unfinished upstream nodes, then the nodes they unblock, and so on. Nodes without a path between them can run in parallel.

DAGs in data tools

  • Apache Airflow: a DAG is a Python-defined workflow of tasks with a schedule; each run of it is a DAG run.
  • dbt: the DAG is inferred from ref() and source() calls between models; selectors such as +orders run a model with everything upstream of it.
  • Dataform: ${ref()} builds the dependency graph, shown as an interactive compiled graph.
  • Data lineage: the graph of which tables feed which, often reconstructed from query logs rather than declared, and spanning tools.

Example: everything downstream of a table

If you keep dependencies as edges in a table, for example exported from lineage, a recursive query walks the graph:

WITH RECURSIVE
  edges AS (
    SELECT * FROM UNNEST([
      STRUCT('raw.orders' AS upstream, 'staging.orders' AS downstream),
      STRUCT('staging.orders', 'marts.fct_orders'),
      STRUCT('staging.customers', 'marts.fct_orders'),
      STRUCT('marts.fct_orders', 'marts.revenue_daily'),
      STRUCT('marts.fct_orders', 'marts.customer_ltv')
    ])
  ),
  downstream AS (
    SELECT downstream AS table_name, 1 AS depth
    FROM edges
    WHERE upstream = 'raw.orders'
    UNION ALL
    SELECT e.downstream, d.depth + 1
    FROM downstream AS d
    JOIN edges AS e ON e.upstream = d.table_name
  )
SELECT table_name, MIN(depth) AS depth
FROM downstream
GROUP BY table_name
ORDER BY depth, table_name;

It returns staging.orders at depth 1, marts.fct_orders at depth 2, and marts.customer_ltv and marts.revenue_daily at depth 3: every table a problem in raw.orders can reach. On a graph with a cycle the recursion would not converge and BigQuery would stop it with an error, one more reason pipelines must stay acyclic. See WITH RECURSIVE.

Practical advice

  • Keep tasks small and named after what they produce. A failure then points to one table.
  • Avoid hidden dependencies. A model that reads a table without ref(), or an Airflow task that assumes another DAG already ran, is a dependency the graph doesn't know about; use sources, sensors or dataset-triggered scheduling instead.
  • Watch fan-in. A node with many upstream dependencies waits for the slowest one, and its delay propagates to everything downstream.
  • Prune leaves nobody reads. A leaf node that is built but never consumed is a dead-end table.

FAQ

Why can't a DAG have cycles?

A cycle means a step depends, directly or indirectly, on its own output, so there is no order in which to run it. Orchestrators reject cycles when they parse the graph; dbt, for example, stops with a cycle error.

Is an Airflow DAG the same as a dbt DAG?

Both are directed acyclic graphs, at different levels. An Airflow DAG connects tasks, which might be a dbt run, a load job or an API call. A dbt DAG connects models through ref() calls inside one project. Often a single Airflow task runs a whole dbt DAG.

Read next

Browse the full glossary

Observability for every BigQuery table, in about 15 minutes

Masthead detects freshness, volume and schema anomalies, monitors pipeline errors and maps column-level lineage across all your projects, from logs and metadata only.