Skip to main content

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 build do?
  • 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:

  1. Your seeds
  2. Your models (staging, intermediate, marts)
  3. Your tests (source tests, generic tests, singular tests)
  4. 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:

  1. Load seed_states into Snowflake.
  2. Run tests on seed_states.
  3. Run source tests on the raw order data.
  4. Build the stg_orders view.
  5. Run tests on stg_orders.
  6. Build the fct_sales table.
  7. 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:

  1. dbt will test the raw source data.
  2. The unique test will FAIL.
  3. dbt will print a red error message.
  4. Crucially, dbt will immediately SKIP building stg_orders and fct_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 build is 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.