Module 3 of 16

The dbt Mental Model

Understand sources, refs, models, DAGs, and materializations without setup friction.

Updated

90 minutes1 exercisesFree

Start here

Learning objectives

  • Explain how dbt compiles SQL models
  • Read a dbt DAG as a dependency graph
  • Know when a model should be a view, table, or incremental model
The dbt Mental Model Follow the arrows. Each box is one idea you will practice in this module. Source step 1 ref() step 2 Model step 3 DAG step 4 Build step 5 Production analytics engineering turns raw records into governed, trusted business meaning.

The Mental Model

dbt lets analytics engineers build data transformations as version-controlled SQL files. The dependency graph comes from source declarations and ref calls.

Think of each dbt model as a recipe. ref() means "use the output of another recipe." dbt reads the recipes and decides the safe build order.

Dataset reference: ecommerce tables and grain assumptions.

Read dependencies from a model

Save the following model as models/marts/fct_orders.sql in a dbt project that already defines stg_orders.

select order_id, customer_id, amount
from {{ ref('stg_orders') }}
where status = 'completed'

The ref call resolves the relation and records a dependency. dbt compiles the template into warehouse SQL; the configured materialization determines whether the result becomes a view, table, or another supported relation. A file named fct_orders does not automatically become a table.

Expected dependency: source orders to stg_orders to fct_orders. Compile the project and inspect the resolved relation before a build. See the dbt ref reference for dependency behavior.

Interactive Check

Question: If fct_orders uses ref("stg_orders"), which model must build first?

Reveal the answer

stg_orders must build first. The ref call creates a dependency edge from fct_orders back to stg_orders.

Practice: Order the dbt DAG

Put shuffled dbt models into the correct build order.

Use the guided lab below to record your result, assumptions, and the check that would catch an incorrect result.

Production notes

Keep these close

  • Review DAG shape in pull requests. A messy graph usually predicts ownership and debugging pain.

Common mistakes

What usually breaks

  • Using raw tables directly in marts
  • Hardcoding schema names instead of using ref/source
  • Creating circular model dependencies

Key terms

Vocabulary used in this module

DAG

Directed acyclic graph; a dependency graph with no circular dependencies.

Materialization

How dbt stores a model, such as view, table, or incremental table.

Exercises

Practice inside the lesson

30-45 minutesBeginner

Order the dbt DAG

Put shuffled dbt models into the correct build order.

  1. Start with sources
  2. Place staging models next
  3. Place intermediate joins after staging
  4. Place marts last
  5. Explain why dashboards should read marts, not raw sources

Expected evidence

A short answer, SQL/YAML snippet, or lineage map that can live directly in the course page notes.

Recap

Key takeaways

  • dbt is SQL plus dependency management, tests, docs, and deployment discipline
  • ref() creates maintainable dependencies
  • The DAG is your first lineage map

Related resources

Keep learning across CodersSecret