Learn Data Engineering Intermediate

Building Data Pipelines with dbt and Dagster: From SQL to Orchestration

Try This First

Test your knowledge before reading. Don't worry if you get it wrong — that's part of learning.

Key Insights

  • Learn dbt fundamentals (models, tests, docs, sources), Dagster's software-defined asset approach, and how to build end-to-end pipelines combining both tools with best practices and a comparison of orchestration frameworks.
Difficulty: Intermediate Type: Learn

What is dbt?

dbt (data build tool) is the industry-standard SQL-first transformation framework. It enables analytics engineers and data analysts to define data transformations as version-controlled SQL SELECT statements. dbt handles the T in ELT — transforming data that is already loaded into your warehouse or lakehouse.

  • Models: The core unit of dbt. Each model is a .sql file containing a SELECT statement. dbt compiles and executes these against your warehouse, materializing the results as tables, views, or incremental models.
  • Tests: Built-in and custom data quality tests. Generic tests (unique, not_null, accepted_values, relationships) are defined in YAML. Custom tests are written as SQL SELECT statements that return failing rows.
  • Documentation: dbt auto-generates documentation from model definitions and inline description blocks. The docs site includes lineage graphs (Lineage DAG), column-level descriptions, and test coverage.
  • Sources and Freshness: Define source tables with freshness assertions. dbt tracks when each source was last loaded and alerts if data is stale.
  • Materializations:table (full refresh), view (no storage), incremental (append/merge new records), ephemeral (CTE), and materialized_view (database-native).
  • dbt Mesh: Decentralize dbt projects across domain teams while sharing a common cross-project reference layer. Each domain owns its models and contracts.

A simple dbt model looks like this:

-- models/orders_summary.sql
{{ config(materialized='incremental', unique_key='order_id') }}

SELECT
 o.order_id,
 o.customer_id,
 o.order_date,
 o.total_amount,
 c.customer_segment
FROM {{ source('ecommerce', 'orders') }} o
LEFT JOIN {{ ref('customer_segments') }} c
 ON o.customer_id = c.customer_id
{% if is_incremental() %}
 WHERE o.order_date >= (SELECT max(order_date) FROM {{ this }})
{% endif %}

What is Dagster?

Dagster is a next-generation data orchestrator designed for the modern data stack. Unlike traditional orchestrators (Airflow) that treat pipelines as task DAGs, Dagster treats them as software-defined assets — each asset knows its upstream dependencies and how it is materialized.

  • Assets: The core abstraction. An asset is a data product (table, file, ML model) with a known producer function. Assets form a DAG based on their dependencies.
  • Ops and Jobs: Lower-level building blocks. An op is a single computation. A job is a graph of ops. Assets are built on top of ops.
  • Schedules and Sensors: Schedules trigger jobs on a cron interval (e.g., daily at 6 AM). Sensors trigger jobs based on external events (e.g., a file landing in S3).
  • dbt Integration: Dagster has a native dbt integration (dagster-dbt) that loads your dbt models as Dagster assets. Dagster orchestrates dbt runs, provides asset-level lineage, and enables cross-tool dependencies (e.g., "run dbt model A, then run Python op B, then run dbt model C").
  • Software-Defined Assets (SDA): Assets are declared in Python with their upstream dependencies, partition definitions, and freshness policies. Dagster materializes only what's stale or upstream of a changed asset.
  • Observability: Dagster's Dagit UI shows asset lineage, run history, logs, and alerts. Each asset has a "last materialized" timestamp, upstream/downstream lineage, and launch history.

Building a Pipeline with dbt + Dagster

The modern data stack often pairs dbt for transformations with Dagster for orchestration. Here's how they work together:

definitions.py — Dagster project root

from dagster import Definitions, load_assets_from_modules from dagster_dbt import dbt_assets, DbtCliResource from pathlib import Path @dbt_assets(manifest=Path("target", "manifest.json")) def my_dbt_assets(context, dbt: DbtCliResource): yield from dbt.cli(["build"], context=context).stream() defs = Definitions(assets=[my_dbt_assets])

This single file loads your entire dbt project as Dagster assets. Dagster handles scheduling, alerting, and lineage — dbt handles the actual SQL transformations.

A Complete Pipeline Example

Here's a practical pattern combining dbt, Dagster, and Python for a complete data pipeline:

assets.py

from dagster import asset, AssetIn import pandas as pd @asset def raw_transactions() -> pd.DataFrame: """Extract: load raw data from source""" return pd.read_parquet("s3://landing/transactions/") @asset def cleaned_transactions(raw_transactions: pd.DataFrame) -> pd.DataFrame: """Transform: clean and validate""" df = raw_transactions.dropna(subset=["amount", "timestamp"]) df["amount"] = df["amount"].clip(lower=0) return df

dbt models handle the SQL transformations (aggregations, joins, etc.)

defined in models/ directory as .sql files

loaded via @dbt_assets(...)

@asset def alerts(cleaned_transactions: pd.DataFrame) -> None: """Serve: check thresholds and send alerts""" high_value = cleaned_transactions[ cleaned_transactions["amount"] > 10_000 ] if len(high_value) > 0: print(f"Alert: {len(high_value)} high-value transactions detected")

Dagster's asset graph automatically determines execution order: raw_transactionscleaned_transactions → dbt models → alerts. If a partition of raw_transactions is reprocessed, only downstream assets for that partition are re-materialized.

Key Patterns and Best Practices

  • Start with dbt-first: Use dbt for all SQL transformations. Only bring in custom Python when SQL is insufficient (e.g., ML inference, API calls, complex business logic).
  • Use incremental models for large tables: dbt's incremental materialization appends or merges only new/changed records, avoiding full table scans.
  • Define data contracts: Use dbt's contract enforcement to guarantee column names, types, and constraints between dbt models.
  • Leverage Dagster partitions: Partition your assets by date, region, or other dimensions. Dagster tracks which partitions are materialized and can materialize only stale partitions.
  • Automate backfills: When upstream source data is corrected, Dagster's "re-materialize upstream" feature cascades the backfill through the entire dependency graph.
  • Test in CI: Run dbt build --select state:modified in CI to test only changed models. Use dbt source freshness to validate data recency.

Comparing the Orchestrators

FeatureDagsterAirflowPrefect
Asset abstractionNative (SDA)No (task-only)Partial (flows)
dbt integrationDeep (native)Via operatorsVia tasks
Partition supportFirst-classManualFirst-class
Local dev experienceExcellent (Dagit)Good (local executor)Good (Orion)
Learning curveModerateLow (basic) / High (advanced)Low

Dagster's software-defined asset approach is a paradigm shift from traditional orchestrators. It treats data as the central concern, not task execution. For teams building modern data platforms, Dagster + dbt is becoming the default stack.

Article Metadata

Review with Spaced Repetition

Add this lesson's 7 flashcards to your SM-2 study queue. They will appear when due in the Study Queue.

Feynman Concept Cards

Master each building block: read the ELI5, explore the analogy, work the example, find your gaps, teach it back, build it.

Data Lake is a concept in foundations. In simple terms, Data Lake covers foundational knowledge in Data Engineering. This data engineering concept addresses key topics in the foundational knowledge in data engineering domain. Also known as: data lakehouse.

Analogy
Think of Data Lake like the foundation of a building — invisible but load-bearing — it helps you handle foundations tasks more effectively.
Example
Consider a scenario where Data Lake applies: Data Lake covers foundational knowledge in Data Engineering. This data engineering concept addresses key topics in the foundational knowledge in data engineering domain. Also known as: data lakehouse....
Find Gaps
What are the key components or steps involved in Data Lake?
Can you explain Data Lake without using jargon?
What happens if Data Lake is not applied correctly?
How does Data Lake relate to other concepts in foundations?
Teach Back

Explain Data Lake as if teaching a colleague who is new to foundations. Cover: what it is, how it works, and why it matters.

Create

Create a diagram that demonstrates Data Lake in a real-world foundations scenario. Walk through your design decisions.

Show solution
A diagram for Data Lake should include: 1. The core components of data lake 2. How they interact 3. Expected outcomes or outputs
Difficulty: Beginner-friendly — 2/5

DataOps is a concept in best practices. In simple terms, DataOps covers best practices in Data Engineering. This data engineering concept addresses key topics in the best practices in data engineering domain. Also known as: DataOps practices, data operation

Analogy
Think of DataOps like a maintenance checklist for a power plant — it helps you handle best practices tasks more effectively.
Example
Consider a scenario where DataOps applies: DataOps covers best practices in Data Engineering. This data engineering concept addresses key topics in the best practices in data engineering domain. Also known as: DataOps practices, data operation...
Find Gaps
What are the key components or steps involved in DataOps?
Can you explain DataOps without using jargon?
What happens if DataOps is not applied correctly?
How does DataOps relate to other concepts in best practices?
Teach Back

Explain DataOps as if teaching a colleague who is new to best practices. Cover: what it is, how it works, and why it matters.

Create

Create a checklist that demonstrates DataOps in a real-world best practices scenario. Walk through your design decisions.

Show solution
A checklist for DataOps should include: 1. The core components of dataops 2. How they interact 3. Expected outcomes or outputs
Difficulty: Advanced — 4/5

Extract-Transform-Load is a concept in foundations. In simple terms, Extract-Transform-Load covers foundational knowledge in Data Engineering. This data engineering concept addresses key topics in the foundational knowledge in data engineering domain. Also known as: ET

Analogy
Think of Extract-Transform-Load like the foundation of a building — invisible but load-bearing — it helps you handle foundations tasks more effectively.
Example
Consider a scenario where Extract-Transform-Load applies: Extract-Transform-Load covers foundational knowledge in Data Engineering. This data engineering concept addresses key topics in the foundational knowledge in data engineering domain. Also known as: ET...
Find Gaps
What are the key components or steps involved in Extract-Transform-Load?
Can you explain Extract-Transform-Load without using jargon?
What happens if Extract-Transform-Load is not applied correctly?
How does Extract-Transform-Load relate to other concepts in foundations?
Teach Back

Explain Extract-Transform-Load as if teaching a colleague who is new to foundations. Cover: what it is, how it works, and why it matters.

Create

Create a diagram that demonstrates Extract-Transform-Load in a real-world foundations scenario. Walk through your design decisions.

Show solution
A diagram for Extract-Transform-Load should include: 1. The core components of etl 2. How they interact 3. Expected outcomes or outputs
Difficulty: Intermediate — 3/5

Extract-Load-Transform is a concept in foundations. In simple terms, Extract-Load-Transform covers foundational knowledge in Data Engineering. This data engineering concept addresses key topics in the foundational knowledge in data engineering domain. Also known as: EL

Analogy
Think of Extract-Load-Transform like the foundation of a building — invisible but load-bearing — it helps you handle foundations tasks more effectively.
Example
Consider a scenario where Extract-Load-Transform applies: Extract-Load-Transform covers foundational knowledge in Data Engineering. This data engineering concept addresses key topics in the foundational knowledge in data engineering domain. Also known as: EL...
Find Gaps
What are the key components or steps involved in Extract-Load-Transform?
Can you explain Extract-Load-Transform without using jargon?
What happens if Extract-Load-Transform is not applied correctly?
How does Extract-Load-Transform relate to other concepts in foundations?
Teach Back

Explain Extract-Load-Transform as if teaching a colleague who is new to foundations. Cover: what it is, how it works, and why it matters.

Create

Create a diagram that demonstrates Extract-Load-Transform in a real-world foundations scenario. Walk through your design decisions.

Show solution
A diagram for Extract-Load-Transform should include: 1. The core components of elt 2. How they interact 3. Expected outcomes or outputs
Difficulty: Intermediate — 3/5

dbt (data build tool) is a concept in advanced techniques. In simple terms, dbt (data build tool) covers advanced techniques in Data Engineering. This data engineering concept addresses key topics in the advanced techniques in data engineering domain. Also known as: data buil

Analogy
Think of dbt (data build tool) like a specialized tool in a data engineer's workshop — it helps you handle advanced techniques tasks more effectively.
Example
Consider a scenario where dbt (data build tool) applies: dbt (data build tool) covers advanced techniques in Data Engineering. This data engineering concept addresses key topics in the advanced techniques in data engineering domain. Also known as: data buil...
Find Gaps
What are the key components or steps involved in dbt (data build tool)?
Can you explain dbt (data build tool) without using jargon?
What happens if dbt (data build tool) is not applied correctly?
How does dbt (data build tool) relate to other concepts in advanced techniques?
Teach Back

Explain dbt (data build tool) as if teaching a colleague who is new to advanced techniques. Cover: what it is, how it works, and why it matters.

Create

Create a diagram that demonstrates dbt (data build tool) in a real-world advanced techniques scenario. Walk through your design decisions.

Show solution
A diagram for dbt (data build tool) should include: 1. The core components of dbt 2. How they interact 3. Expected outcomes or outputs
Difficulty: Intermediate — 3/5

Dagster Orchestrator is a concept in advanced techniques. In simple terms, Dagster Orchestrator covers advanced techniques in Data Engineering. This data engineering concept addresses key topics in the advanced techniques in data engineering domain. Also known as: dagster. R

Analogy
Think of Dagster Orchestrator like a specialized tool in a data engineer's workshop — it helps you handle advanced techniques tasks more effectively.
Example
Consider a scenario where Dagster Orchestrator applies: Dagster Orchestrator covers advanced techniques in Data Engineering. This data engineering concept addresses key topics in the advanced techniques in data engineering domain. Also known as: dagster. R...
Find Gaps
What are the key components or steps involved in Dagster Orchestrator?
Can you explain Dagster Orchestrator without using jargon?
What happens if Dagster Orchestrator is not applied correctly?
How does Dagster Orchestrator relate to other concepts in advanced techniques?
Teach Back

Explain Dagster Orchestrator as if teaching a colleague who is new to advanced techniques. Cover: what it is, how it works, and why it matters.

Create

Create a diagram that demonstrates Dagster Orchestrator in a real-world advanced techniques scenario. Walk through your design decisions.

Show solution
A diagram for Dagster Orchestrator should include: 1. The core components of dagster 2. How they interact 3. Expected outcomes or outputs
Difficulty: Advanced — 4/5

ELT Pipeline Architecture is a concept in architecture. In simple terms, ELT Pipeline Architecture covers architectural patterns for Data Engineering. This data engineering concept addresses key topics in the architectural patterns for data engineering domain. Also known a

Analogy
Think of ELT Pipeline Architecture like a blueprint for a complex machine — it helps you handle architecture tasks more effectively.
Example
Consider a scenario where ELT Pipeline Architecture applies: ELT Pipeline Architecture covers architectural patterns for Data Engineering. This data engineering concept addresses key topics in the architectural patterns for data engineering domain. Also known a...
Find Gaps
What are the key components or steps involved in ELT Pipeline Architecture?
Can you explain ELT Pipeline Architecture without using jargon?
What happens if ELT Pipeline Architecture is not applied correctly?
How does ELT Pipeline Architecture relate to other concepts in architecture?
Teach Back

Explain ELT Pipeline Architecture as if teaching a colleague who is new to architecture. Cover: what it is, how it works, and why it matters.

Create

Create a diagram that demonstrates ELT Pipeline Architecture in a real-world architecture scenario. Walk through your design decisions.

Show solution
A diagram for ELT Pipeline Architecture should include: 1. The core components of elt pipeline 2. How they interact 3. Expected outcomes or outputs
Difficulty: Intermediate — 3/5

Lakehouse Architecture is a concept in architecture. In simple terms, The Lakehouse architecture, formalized by Armbrust et al. (2021), combines the flexibility of data lakes (cheap object storage, diverse data types) with the reliability of data warehouses (ACID transa

Analogy
Think of Lakehouse Architecture like a blueprint for a complex machine — it helps you handle architecture tasks more effectively.
Example
Consider a scenario where Lakehouse Architecture applies: The Lakehouse architecture, formalized by Armbrust et al. (2021), combines the flexibility of data lakes (cheap object storage, diverse data types) with the reliability of data warehouses (ACID transa...
Find Gaps
What are the key components or steps involved in Lakehouse Architecture?
Can you explain Lakehouse Architecture without using jargon?
What happens if Lakehouse Architecture is not applied correctly?
How does Lakehouse Architecture relate to other concepts in architecture?
Teach Back

Explain Lakehouse Architecture as if teaching a colleague who is new to architecture. Cover: what it is, how it works, and why it matters.

Create

Create a diagram that demonstrates Lakehouse Architecture in a real-world architecture scenario. Walk through your design decisions.

Show solution
A diagram for Lakehouse Architecture should include: 1. The core components of lakehouse architecture 2. How they interact 3. Expected outcomes or outputs
Difficulty: Advanced — 5/5

Feynman Synthesis — Prove You Understand

1. The One-Pager

Explain this lesson's core idea to a smart 15-year-old. No jargon allowed.

2. The Gap Map

List 3 things you are still unsure about. Be specific.

Knowledge Check

Test your understanding of this lesson.

Flashcards

Space = flip · 1-4 = grade · Swipe on mobile

Related Research

Related Knowledge

Stay Updated

Get the latest research summaries delivered to your inbox.