BlogResearch

What is a DAG in data engineering? Plain explanation

A DAG is a graph of tasks with one-way links and no loops. See how data pipelines use it to set run order.

Aymeric ZhuoAymeric Zhuo5 min read

Summarize with AI

What is a DAG in data engineering? Plain explanation
On this page

A DAG in data engineering is a directed acyclic graph: a set of tasks joined by one-way dependencies, with no path that loops back to its start. The graph tells a pipeline which tasks must finish before others begin. Apache Airflow describes a Dag as "a model that encapsulates everything needed to execute a workflow" (Airflow documentation, version 3.3.2, checked 30 Oct 2026).

Key Takeaways

  • A DAG has nodes (tasks) and directed edges (dependencies), and no cycles.
  • The graph sets run order: a task starts only after all its upstream tasks finish.
  • Tasks with no dependency between them can run at the same time.
  • Airflow, dbt, Prefect and Dagster all build pipelines from this structure.
  • A DAG is the plan. Data lineage is the record of what actually ran.

What is a DAG in data engineering?

A DAG in data engineering is a directed acyclic graph of pipeline tasks. "Directed" means each link has a direction, so Task A runs before Task B. "Acyclic" means no chain of links returns to its start, so Task B cannot also be a prerequisite of Task A. The graph is the schedule's blueprint.

The three words map to three rules. Tasks are the nodes. Dependencies are the edges. A pipeline is valid only when following the edges never leads back to the task you started from.

Why do data engineers use DAGs?

Data engineers use DAGs because the graph encodes dependencies once and lets the orchestrator handle order, parallel runs and failures. Without a DAG, a script author must hard-code the order of every step, and any change to one step risks breaking the sequence of the others.

  • Dependency management. A join task needs both source tables fresh. The DAG makes both extraction tasks finish before the join starts.
  • Parallel runs. Tasks with no link between them can run at the same time, which shortens total pipeline time.
  • Failure isolation. When a task fails, the orchestrator knows which downstream tasks to skip. Independent branches can continue.

How is a DAG structured?

A DAG has two parts: nodes and edges. Nodes are tasks such as an extraction, a transformation, a model run or a notification. Edges are directed dependencies that fix the order. The example below is a five-task pipeline, and the table shows which tasks can run together.

StageTasksDepends on
1Extract from PostgreSQL, extract from the Salesforce APINothing, so both run in parallel
2Transform and joinBoth extractions
3Load to the warehouseTransform and join
4Send a Slack notificationLoad to the warehouse

Airflow declares this with the >> operator, for example first_task >> [second_task, third_task] (Airflow documentation, 2026). The arrow reads as "runs before".

How does a DAG decide the run order?

A DAG decides the run order by topological ordering: a sequence in which every task appears after all of its upstream tasks. A scheduler computes this order from the edges and starts every task whose upstream tasks have finished. Several valid orders usually exist for one graph.

Python's standard library includes this algorithm as graphlib.TopologicalSorter (Python documentation). Run on the five tasks above, it returned the two extractions first, then the join, then the load, then the notification. The two extractions came out as one ready group, which is how a scheduler knows they can run in parallel.

Which tools use DAGs?

Apache Airflow, dbt, Prefect and Dagster all organize work as a graph of tasks. They differ in how the graph is written: Airflow in Python code, dbt from SQL references, and Prefect and Dagster in Python. Each tool runs tasks in dependency order.

ToolHow the graph is built
Apache AirflowPython code declares tasks and the >> dependencies between them.
dbtref() calls between SQL models "automatically build the dependency graph" (dbt documentation, 2026).
Prefect and DagsterPipelines are defined in Python as graphs of tasks or assets.
CodeWordsCody writes the workflow as Python code. Steps that do not depend on each other can run in parallel with asyncio.gather (CodeWords docs, 2026).

For orchestration concepts beyond one tool, read what is a workflow engine and workflow orchestration.

What happens when a DAG has a cycle?

A DAG with a cycle is no longer a DAG, and no valid run order exists for it. Task A would wait for Task B while Task B waits for Task A. A dependency sorter cannot produce an order for it. Python's graphlib raises CycleError for {"a": {"b"}, "b": {"a"}}.

When a workflow needs repetition, such as polling an API until a condition is met, put the loop inside one task. The graph stays acyclic, and the task handles the repeat. A new run of the whole DAG on the next schedule is the other way to repeat work.

DAG or data lineage: what is the difference?

A DAG is the plan and data lineage is the record. The DAG defines which tasks run in what order. Data lineage records which data flowed through which steps after a run. Teams use the DAG to build pipelines and lineage to trace where a value came from. See what is data lineage.

FAQs: What Is a DAG in Data Engineering

How to visualize a DAG?

Visualize a DAG by drawing tasks as boxes and dependencies as arrows that run left to right, or by using the graph view of an orchestrator. Airflow documents a Graph view in its user interface, and a TaskGroup can organize tasks into groups there [Airflow documentation, 2026].

How do I create a DAG?

Create a DAG by listing each task, then declaring which tasks must finish before others start. In Airflow, define the tasks in Python and join them with the >> operator, for example first_task >> second_task. Check that no chain of dependencies returns to its start before you schedule it [Airflow documentation, 2026].

What is a DAG in LLM?

A DAG in an LLM application is a graph of steps, such as a retrieval, a model call or a validation check, where each step passes its output to later steps. Dependencies point one way and never loop back. DB-GPT, an LLM framework, uses a DAG class to define tasks and their dependencies [DB-GPT AWEL documentation, 2026].

Why is a DAG not a tree?

A DAG is not a tree because a node in a DAG can have more than one parent. A tree gives every node exactly one parent. In the five-task example, the join task depends on two extraction tasks, so it has two parents. That makes the graph a DAG and not a tree.

Get started today

Your first workflow is free to build.

Describe what you need. Cody handles the build, the connections, and the deployment.