The dbt Build Command
In previous modules, we introduced several individual dbt commands:
dbt seed(to load CSVs)dbt run(to execute SQL models)dbt test(to validate data)dbt snapshot(to capture historical changes)
Running these commands individually is fine for local development. However, trying to stitch them together into a Production pipeline (e.g., in Apache Airflow or GitHub Actions) is a nightmare.
To solve this, dbt introduced the single most important command in the framework: dbt build.
Topics Covered
- What does
dbt builddo? - Topological Execution Order
- The Data Quality Gate
1. What does dbt build do?
The dbt build command is the "unified execution command." When you type dbt build into your terminal, dbt executes every resource type in your project in a single continuous process.
It automatically runs:
- Your seeds
- Your models (staging, intermediate, marts)
- Your tests (source tests, generic tests, singular tests)
- Your snapshots
You no longer have to guess the correct order of operations. dbt handles everything for you.
2. Topological Execution Order
The true magic of dbt build is how it orders the execution. It does not run all the models, and then run all the tests. Instead, it weaves them together using Topological Execution Order.
It walks through your Directed Acyclic Graph (DAG) node-by-node.
Example Execution Flow:
Let's assume you have a simple pipeline: seed_states -> stg_orders -> fct_sales.
If you type dbt build, dbt will execute exactly in this order:
- Load
seed_statesinto Snowflake. - Run tests on
seed_states. - Run source tests on the raw order data.
- Build the
stg_ordersview. - Run tests on
stg_orders. - Build the
fct_salestable. - Run tests on
fct_sales.
dbt will never proceed to step 6 until step 5 successfully passes.
3. The Data Quality Gate
Because of this topological execution, dbt build acts as an automated Data Quality Gate.
Imagine your Indian e-commerce startup receives raw data from a third-party payment gateway. Today, that gateway has a bug and sends duplicate transaction IDs.
If you orchestrate your pipeline using dbt build:
- dbt will test the raw source data.
- The
uniquetest will FAIL. - dbt will print a red error message.
- Crucially, dbt will immediately SKIP building
stg_ordersandfct_sales.
By halting the execution mid-DAG, dbt build prevents the bad data from propagating into your final presentation tables. The CEO's Tableau dashboard remains safe (it will just show yesterday's clean data), giving your Data Engineering team time to fix the upstream bug.
(Note: We will cover this concept in much more depth in the Data Quality module later in this course.)
Summary
dbt buildis the unified execution command for production pipelines.- It automatically runs seeds, models, tests, and snapshots in a single run.
- It executes nodes in topological order (interweaving models and tests).
- If a test fails, it immediately skips downstream models, acting as a Data Quality Gate to protect your final dashboards.