Skip to the page

Orchestration and dbt · core

dbt models, refs and tests

dbt is the transformation step inside the warehouse: SQL models run in dependency order with tests. It does not extract or load data and is not a scheduler.

The notes

What you must know

  • dbt compiles SQL with Jinja into plain SQL and runs it in dependency order. A model is one SELECT in a file that becomes a table or view.
  • ref('model') builds the dependency graph and points to the right schema for each environment. source() declares raw tables and enables freshness checks. Hard-coded schema names break this.
  • Materializations: view, table, incremental (only new or changed rows), ephemeral (inlined as a CTE), plus snapshots for SCD type 2.
  • In production run dbt build (models and tests in order) from Airflow, the dbt platform or CI. Slim CI builds state:modified+ and defers the rest to production.
  • Data tests: generic (unique, not_null, accepted_values, relationships), package tests (row counts, ranges, recency) and singular tests (a SQL file that returns bad rows). Unit tests (dbt 1.8 and later) check the logic with fixed input and expected rows.
  • Source freshness: loaded_at_field with warn_after and error_after, run by dbt source freshness. Model contracts enforce column names and types, so a change in shape fails the build.
  • Severity: warn or error, thresholds (warn_if, error_if), and store_failures to keep failing rows. dbt build skips everything downstream of a failed test, so yesterday's data stays: stale but not wrong.
  • For a revenue fact: unique order_id, non-null keys, relationships to dimensions, non-negative amounts, a row count within a band. Keep the set small and owned so warnings are not ignored.
  • dbt Core 1.x stays open source (Apache 2.0). dbt's newer engine has a separate licence for some parts.

The red pen

Common traps: mistake → fix

  • Mistake: dbt moves data from the sources

    Fix: it only transforms data already in the warehouse.

  • Mistake: Hard-code the schema name

    Fix: use ref so environments and lineage work.

  • Mistake: Only not_null tests are enough

    Fix: add uniqueness, relationships, ranges, freshness and volume.

Easy to hard

Questions interviewers ask, easy to hard

  1. What does dbt do and what does it not do?
  2. What are the main materializations?
  3. How do you test data in a dbt project?
  4. What happens when a test fails at 4 am?

Practise

Practise with these questions

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview