dbt Fundamentals
Build transformation pipelines as SQL models with dbt: sources, ref, materializations, project structure, documentation and the DAG.
Intermediate · about 10 hours · difficulty 3/5
Learn first: ETL vs ELT and Load Patterns, Dimensional Modeling: Star and Snowflake Schemas, Git and Collaborative Workflows
dbt (data build tool) turns SQL SELECT statements into a managed, tested, documented transformation pipeline inside your warehouse. It is now a default skill for data and analytics engineers, and dbt Core is free and open source.
The core idea
Each model is a .sql file containing a SELECT. dbt wraps it in the right DDL and builds it as a view or table. Models reference each other with {{ ref('stg_orders') }}, which lets dbt build a DAG and run models in dependency order.
Key building blocks
- Sources: declare raw tables in YAML and reference them with
{{ source('razorpay', 'payments') }}. You can check source freshness. - Materializations:
view,table,incremental,ephemeral. Choose per model. - Project structure:
staging(one model per source table, renames and casts),intermediate,marts(facts and dimensions). - YAML properties: descriptions, column docs and tests live next to models.
- Seeds: small CSVs (like a mapping of state codes) version-controlled with the project.
Commands
dbt run, dbt test, dbt build (run and test in order), dbt docs generate and dbt docs serve for a browsable catalog with lineage graphs. Select subsets with --select stg_orders+.
Environments
Use separate targets (dev schema per developer, prod schema) in profiles.yml. CI runs dbt on pull requests before merging.
Pitfalls
- Hard-coding table names instead of using ref and source, breaking lineage and environments.
- Putting all logic in one 500-line model.
You are ready to move on when you can build a dbt project with sources, staging and mart models, generate docs with a lineage graph, and run it against DuckDB, Postgres or a warehouse.
Key concepts
- Models and ref
- Sources and freshness
- Materializations
- Staging, intermediate, marts
- Seeds
- dbt build and node selection
- dbt docs and lineage
- Profiles and targets
Mini project
Create a dbt Core project using dbt-duckdb or BigQuery over a sample e-commerce dataset. Build staging models for each source, a fct_orders and dim_customers mart, add descriptions, and publish the generated docs site via GitHub Pages.
Check yourself
What does ref() give you that writing the full table name does not?
Free resources
- dbt documentation (dbt Labs)
- How we structure our dbt projects (dbt Labs)
- Data Engineering Zoomcamp (analytics engineering module) (DataTalksClub)