dbt & analytics engineering
Models as SELECTs, ref() dependency graph, incremental materializations, snapshots (SCD2 for free), tests and docs. The de facto transform layer of the modern stack.
The mental model
dbt is **version control and a compiler for SQL SELECT statements**. That is the whole idea, and it is more radical than it sounds. Before dbt, a warehouse transformation was a pile of stored procedures and hand-run CREATE TABLE AS scripts, with dependencies living in someone's head and "which ran first" discovered by breakage. dbt says: write each transformation as a plain SELECT, declare where its inputs come from with ref(), and let a compiler figure out the execution order, build the tables, and test the results.
The analogy that sticks: dbt is **make for your warehouse**. In a C project you write source files and a Makefile; make reads the dependency graph, compiles only what changed, and links it in the right order. In dbt you write .sql models; dbt reads the ref() graph, wraps each SELECT in the right CREATE/MERGE DDL for your warehouse, and runs them in topological order. You never write CREATE TABLE, you never write DROP, and you never hand-order your scripts — the graph does it.
The WHY that unlocks everything: **ref() is not a string, it is an edge in a DAG.** When you write select * from {{ ref('stg_orders') }}, dbt does two things at once — it substitutes the correct fully-qualified table name for your target environment (dev vs prod schemas differ), and it records a dependency so stg_orders builds before this model. Lineage, environment isolation, and execution order all fall out of that one function. Analytics engineering — the discipline dbt created — is really just "software engineering practices (version control, modularity, testing, CI, docs) applied to the transform layer of the warehouse."
- Deep dive
- Internal architecture
- Real-world use cases
- Best practices
- Common mistakes
- Performance
- Security
- Production troubleshooting
- Advantages & disadvantages
- Alternatives
- Interview expectations
- Interview questions
- Facts to remember
- Cheat sheet
- Quick revision