Skip to content
Bronze 6 min read · Basics 1 practice problem ↓

What dbt is (and is not)

dbt is the transformation layer of a modern data stack: you write SELECT statements, and dbt turns them into tables and views in your warehouse, in the right order, with tests and documentation.

Pipelines in production · dbt · Bronze · Project basics, lesson 1 of 2

In plain words first

Think of a cookbook for your warehouse. Each recipe (a model) is a SELECT that says how to make one table from others. dbt reads all the recipes, works out which must be cooked first, cooks them in the right order inside the warehouse, and checks the results taste right (tests).

The T in ELT

Older pipelines transformed data before loading it (ETL). Cloud warehouses made storage and compute cheap enough to load raw data first and transform it inside the warehouse with SQL (ELT). dbt owns that last step.

  1. Extract + load

    Fivetran, Airbyte, custom jobs

  2. Raw tables

    In the warehouse

  3. Transform

    dbt models

  4. Consume

    BI, ML, reverse ETL

dbt does not move data between systems, schedule itself or store data. It connects to one warehouse (Snowflake, BigQuery, Databricks, Redshift, Postgres, DuckDB and others through adapters) and runs SQL there. The warehouse does all the computing.

A model is a SELECT

A model is one .sql file in models/ that contains one SELECT. The file name becomes the name of the table or view dbt builds. You never write CREATE TABLE or INSERT: dbt wraps your query in the right DDL for the materializationmaterialization: How dbt stores a model: as a view, a table, an incremental table that only adds new rows, or ephemeral (inlined, not stored). Learn more → you chose.

dbt · models/marts/fct_invoices.sql
select
    i.invoice_id,
    i.account_id,
    i.issued_at,
    i.total,
    coalesce(sum(c.amount), 0) as amount_charged
from {{ ref('stg_invoices') }} as i
left join {{ ref('stg_charges') }} as c
    on c.invoice_id = i.invoice_id
group by 1, 2, 3, 4

The examples in this track use one imaginary product: a music subscription app with accounts, invoices, card charges and song plays. The {{ ref(...) }} calls are JinjaJinja: The template language dbt runs before sending SQL: {{ }} inserts a value, {% %} runs logic such as loops and ifs. Learn more →, a template language. They are how dbt learns that fct_invoices depends on two other models, so it can build them first.

Compile, then run

  1. 1
    Parse: dbt reads every model, YAML file and macromacro: A reusable piece of Jinja, like a function that returns SQL. You call it with {{ my_macro(...) }}. Learn more → and builds the dependency graph (the DAGDAG: The graph of models that ref() calls create. dbt uses it to build models in dependency order. Learn more →).
  2. 2
    Compile: Jinja is rendered into plain SQL. {{ ref('stg_invoices') }} becomes a fully qualified name such as analytics.dbt_alice.stg_invoices. The result is written to target/compiled/.
  3. 3
    Run: dbt wraps the compiled query in DDL (for a table: create or replace table ... as (select ...)), sends it to the warehouse, and walks the DAG so every model runs after its parents, several at a time.
Shell · The commands you use most
dbt compile --select fct_invoices   # render Jinja only, nothing runs
dbt run --select fct_invoices       # build the model
dbt test --select fct_invoices      # run its data tests
dbt build                         # run, test, snapshot and seed everything in DAG order
Tip: When a model fails with a SQL error, read the compiled SQL in target/compiled/ (or target/run/ for the wrapped DDL). The error is about that SQL, not your Jinja.

What dbt adds on top of SQL files

Dependencies

ref() and source() build the DAG, so order and parallelism are automatic.

Environments

The same code builds into a personal dev schema or into production, chosen by the target.

Tests

Assertions such as unique and not_null run as queries after each build.

Documentation

dbt docs generate builds a site with every model, column description and the lineage graph.

Reuse

Jinja macros and packages remove copy-pasted SQL.

Incremental builds

Large tables process only new rows instead of being rebuilt.

Core, the platform and Fusion

NameWhat it is
dbt CoreThe open-source command-line tool (Python). You run it yourself, usually from an orchestrator such as Airflow, Dagster or a CI job.
The dbt platformdbt Labs' hosted product (formerly dbt Cloud): an IDE, job scheduler, CI on pull requests, hosted docs and the semantic layer.
dbt FusionA newer engine written in Rust that parses projects much faster and understands the SQL it compiles. Same project files.

Everything in this track works the same in all three: projects are plain files, and the concepts (models, refs, tests, materializations) do not change.

Common mistakes

  • Expecting dbt to load data — Pointing a model at a file in S3 or an API does not work: a model can only SELECT from tables already in the warehouse. Load them first with Fivetran, Airbyte or a custom job.
  • Writing CREATE TABLE in a model — dbt wraps the file in its own DDL, so CREATE TABLE fct_invoices AS SELECT ... becomes create or replace table ... as (CREATE TABLE ...) and the warehouse rejects it. Keep only the SELECT and choose a materialization.
  • Hard-coding table names — FROM analytics.stg_invoices reads production even in your dev schema, and dbt does not know about the dependency, so it may build this model first. Use {{ ref('stg_invoices') }}.

Key takeaways

  • The warehouse does all the computing: a slow model is fixed in its SQL and the warehouse, not in dbt.
  • When a model fails, read target/compiled/: it holds the plain SQL dbt sent, with every ref resolved.
  • The same project runs in dbt Core, the dbt platform and Fusion; models, refs, tests and materializations do not change.
  • Interview angle: a SELECT per model, a DAG from ref(), and software practices for SQL: version control, environments, tests and docs.

Interview prep

THE QUESTION

"What is dbt, and what problem does it solve?"

dbt is a transformation framework for the T in ELT. Each model is a SELECT; dbt compiles the Jinja in it, works out dependencies from ref() and source(), and builds tables and views in the warehouse in DAG order. It brings software practices to SQL: version control, environments, tests, documentation, code reuse through macros, and incremental builds. The warehouse does the compute; dbt does not extract, load or store data.

Avoid: "dbt is an ETL tool". dbt does not extract or load anything: it compiles SELECTs and the warehouse runs them.

Follow-ups · answer out loud, then open

Follow-up"What happens, step by step, when you type dbt run?"
dbt parses the project (models, YAML, macros) into a graph, compiles each selected model's Jinja into SQL, wraps it in the materialization's DDL, and sends it to the warehouse in dependency order, up to threads models at a time. It writes manifest.json and run_results.json to target/.
Scenario"A team has 300 SQL scripts run by cron in a fixed order. What would moving to dbt give them?"
Dependencies inferred from ref() instead of a hand-maintained order, parallel runs, a dev schema per developer, tests after each model, generated docs and lineage, macros instead of copy-pasted SQL, and incremental models for the big tables. The SQL itself mostly stays.
Trap"Does dbt make queries faster?"
Not by itself: the warehouse runs the same SQL. dbt can save cost and time through materialization choices, incremental models and building only what changed, but a slow query stays slow.

Check yourself

3 questions

What does a dbt model file contain?

Show the answer

A single SELECT statement, optionally with Jinja. dbt wraps the SELECT in the DDL that the materialization needs.

Where does the computation in a dbt run happen?

Show the answer

In the warehouse dbt connects to. dbt sends SQL; the warehouse executes it.

How does dbt know that fct_invoices must run after stg_invoices?

Show the answer

fct_invoices uses {{ ref('stg_invoices') }}. ref() records the dependency in the DAG.

Practise this

Problems that use this, graded on hidden tests

Keep going

Up next · Project basics · lesson 2 of 2 · 5 min read
A dbt project, file by file
dbt_project.yml, profiles and targets, and the staging, intermediate and marts layout teams use.

Related lessons

Primary sources: What is dbt?