dbt interview questions: models, incremental logic, tests and CI

dbt interview questions test whether you know what dbt actually does when it runs: it compiles Jinja and SQL SELECT statements into tables and views inside the warehouse, in an order worked out from ref() and source(). Expect questions on materializations, how incremental models decide what to process, snapshots, the kinds of tests, macros, and how to build and test only what changed in CI.

By Published 10 min read

Where dbt questions come from

dbt shows up in analytics engineer, data engineer, BI developer and analyst interviews wherever the warehouse is Snowflake, BigQuery, Redshift, Databricks or Postgres. The questions split into two kinds. Modeling questions (grain, layers, metric definitions) are covered in analytics engineer interview questions. This page covers the tool itself: what happens between typing dbt build and tables appearing, why a model ran in the wrong order, why an incremental model double counts, and how a team ships changes safely. Many companies also give a take-home: a small project to extend with a model, tests and documentation.

How a dbt project works

Fundamentals
QuestionWhat it testsWhat a strong answer shows
What does dbt do, and what does it not do?ScopeIt handles the transform step inside the warehouse: you write SELECTs, dbt wraps them in CREATE or MERGE statements and runs them in dependency order. It does not extract or load data, and it does not process data on its own machine.
Why use ref() instead of the table name?The DAGref() tells dbt about the dependency, so models run in the right order, lineage appears in docs, and the name resolves to the right database and schema for each environment. A hard-coded name silently reads production from a dev run.
What does source() add?Raw dataA declared entry point for loaded tables, with an owner, a description, tests and freshness rules. It also marks where lineage starts, so you can select everything downstream of one source.
What lives in dbt_project.yml versus profiles.yml?ConfigurationThe project file holds the project name, paths and default configs per folder. profiles.yml holds connection details and targets such as dev and prod, and sits outside the repository (or reads credentials from environment variables).
Compile versus run versus build?Commandscompile renders Jinja to plain SQL in the target folder without changing the warehouse. run executes models. build runs seeds, models, snapshots and tests together in graph order, so a failing test stops its dependents.
What are seeds for, and what are they not for?SeedsSmall, slowly changing CSV lookups kept in Git, such as country codes or account mappings. They are not a loading tool for real source data.
What is a target, and how do you use it in SQL?EnvironmentsThe connection profile in use. target.name lets a model limit data in dev, for example sampling three days when the target is not prod, so development runs stay fast and cheap.
How do packages work?ReuseListed in packages.yml and installed with dbt deps. Packages such as dbt_utils add macros and generic tests; pin versions so an upgrade does not change builds without review.
Fundamentals. Scroll sideways on a small screen.

Materializations and configuration

  • Name the built-in materializations. View, table, incremental and ephemeral, plus materialized views on adapters that support them. Snapshots and seeds are separate resource types, not materializations of a model.
  • Where can a config be set, and which wins? In dbt_project.yml for a folder, in a properties YAML file for a model, or in a config() block inside the model. The most specific place wins: the in-file config() overrides YAML, which overrides the project file.
  • What happens to an ephemeral model? It is never built. dbt inlines it as a CTE into every model that refs it. That saves a relation but makes debugging harder, since there is nothing to query, and heavy logic gets repeated in each dependent.
  • What do pre-hooks and post-hooks do? Run SQL before or after a model builds, for example to grant access or to log row counts. on-run-start and on-run-end do the same around the whole invocation. Grants are better handled with the grants config where the adapter supports it.
  • What is the schema naming trap with custom schemas? By default dbt appends the custom schema to the target schema, so a model set to schema marts builds in analytics_marts, not marts. Teams override the generate_schema_name macro to get exact names in production.
  • Can dbt models be written in Python? On some adapters (such as Snowflake, Databricks and BigQuery), a model can be a Python function returning a DataFrame that runs on the warehouse's own compute. Most projects keep Python for logic SQL handles badly.

Incremental models

Interviewers dwell on incremental models because they are where dbt projects break. Know the exact condition: is_incremental() returns true only when the model is configured as incremental, its table already exists in the warehouse and the run is not a full refresh. On the first run the filter inside the if block is skipped and the whole history is built. On later runs, {{ this }} refers to the existing table, so the filter can ask it for the latest timestamp already loaded.

{{
  config(
    materialized = 'incremental',
    unique_key = 'order_id',
    incremental_strategy = 'merge',
    on_schema_change = 'append_new_columns'
  )
}}

with changes as (

    select order_id, customer_id, status, amount, updated_at
    from {{ source('shop', 'orders') }}

    {% if is_incremental() %}
    -- look back three days from the newest row already loaded
    where updated_at >= (
        select {{ dbt.dateadd('day', -3, 'max(updated_at)') }}
        from {{ this }}
    )
    {% endif %}

),

ranked as (

    select
        *,
        row_number() over (
            partition by order_id
            order by updated_at desc
        ) as rn
    from changes

)

select order_id, customer_id, status, amount, updated_at
from ranked
where rn = 1
models/marts/fct_orders.sql: an incremental model that reprocesses a three-day window so late updates still land, and keeps one row per order. Rendered with jinja2 and run in SQLite with stubbed dbt functions; incremental runs matched a full refresh in random tests where rows arrived up to 2.5 days late, and differed at 5 days. dbt itself was not run.
Incremental questions
QuestionWhat it testsWhat a strong answer shows
What does unique_key do?Merge behaviorIt tells the strategy which rows to replace. Without it, most adapters just append, so a reprocessed window creates duplicates. With it, a changed order replaces its old row.
Which incremental strategies exist?Strategiesappend, merge, delete+insert and insert_overwrite, plus microbatch in recent dbt versions, which processes time-based batches you can retry one by one. Support and defaults depend on the adapter, so check yours.
What does on_schema_change control?Schema driftWhat happens when the model's columns change: ignore (the default), fail, append_new_columns or sync_all_columns. None of them backfill the new column for old rows; that needs a full refresh.
Why would an incremental model miss rows?Late dataThe filter compares to the max timestamp loaded, so rows that arrive later than the lookback window are skipped forever. Widen the window, filter on a load timestamp instead of an event timestamp, or schedule full refreshes.
The first incremental run after creating an empty table loaded nothing. Why?Edge casesmax() over an empty table is NULL, and a comparison with NULL matches no rows. Wrap it in coalesce with an early date.
When is --full-refresh needed?RebuildsAfter changing logic that affects old rows, adding a column you need populated historically, or fixing a bug in past data. On huge tables, plan it, or rebuild a date range with a variable instead.
Incremental questions. Scroll sideways on a small screen.

Snapshots

  • What problem do snapshots solve? The source overwrites rows, but you need history. A snapshot compares the current source to what it stored last time and records changes as type 2 slowly changing dimension rows with dbt_valid_from and dbt_valid_to.
  • Timestamp versus check strategy? Timestamp uses a reliable updated_at column to detect changes, which is cheap. Check compares a list of columns (or all of them) when no trustworthy timestamp exists, which costs more and records any change in those columns.
  • How are deleted source rows handled? By default they stay current in the snapshot. A config can close them out, and recent versions offer an option to add a deletion record instead. Check which setting your version uses.
  • Why can snapshots not be rebuilt? They hold history that no longer exists in the source. Run them on a schedule from the start, never drop them casually, and keep them out of full-refresh habits.

Tests, freshness and contracts

version: 2

models:
  - name: fct_orders
    description: One row per order, latest status.
    columns:
      - name: order_id
        tests:
          - unique
          - not_null
      - name: customer_id
        tests:
          - relationships:
              to: ref('dim_customers')
              field: customer_id
      - name: status
        tests:
          - accepted_values:
              values: ['placed', 'shipped', 'returned', 'cancelled']
      - name: amount
        tests:
          - non_negative:
              config:
                severity: warn

sources:
  - name: shop
    schema: raw_shop
    loaded_at_field: _loaded_at
    freshness:
      warn_after: {count: 6, period: hour}
      error_after: {count: 24, period: hour}
    tables:
      - name: orders
models/marts/_marts.yml and models/staging/_sources.yml: generic tests on a model and freshness rules on a source. Reviewed by hand, not run. Recent dbt versions also accept data_tests as the key name.
{% test non_negative(model, column_name) %}

select {{ column_name }}
from {{ model }}
where {{ column_name }} < 0

{% endtest %}
tests/generic/non_negative.sql: a custom generic test. Like every dbt test, it passes when the query returns zero rows. Reviewed by hand, not run.
  • Generic versus singular tests? A generic test is a parameterized query applied to many columns from YAML, such as unique or a custom one like the above. A singular test is one SQL file in the tests folder for one specific rule. Both fail when they return rows.
  • How do you stop a noisy test from blocking deploys? Set severity to warn, or use warn_if and error_if thresholds such as more than ten failing rows, and add a where config to scope it. Then fix the cause; a permanent warning nobody reads is a removed test.
  • What are unit tests in dbt? Introduced in recent versions, they feed fixed input rows to a model and compare its output to expected rows, so you can test logic such as a CASE expression before running on real data. Data tests check the data; unit tests check the code.
  • How does source freshness work? dbt source freshness compares the newest loaded_at_field value to now and warns or errors past the thresholds. Run it before the build so a stale load fails loudly instead of producing quiet, outdated dashboards.
  • What is a model contract? With an enforced contract, dbt checks that a model's columns and data types match what the YAML declares before building it, and can add constraints where the warehouse supports them. It protects downstream consumers from accidental shape changes.
  • What are model versions and access levels for? Versions let a breaking change ship as v2 while v1 stays available during a migration. Access (private, protected, public) and groups limit which models other teams or projects may ref.

Jinja, macros and running in production

Senior questions
QuestionWhat it testsWhat a strong answer shows
When should logic become a macro?ReuseWhen the same SQL pattern appears in several models, such as currency conversion or a surrogate key. Not for one-off logic: macros hide SQL from reviewers, so keep them small and documented.
Why guard run_query with execute?Parse versus rundbt renders every model during parsing, before any query can run. A macro that queries the warehouse must check execute, or it fails or returns nothing at parse time.
What is adapter.dispatch for?PortabilityIt picks a warehouse-specific version of a macro, so a package can support Snowflake and BigQuery syntax under one name. Cross-database helpers such as dbt.dateadd are built this way.
How do you build only what changed in a pull request?Slim CICompare against production artifacts with --select state:modified+ and --defer --state, so changed models and their children build in a CI schema while unchanged parents are read from production.
Explain the graph operators.Selection+model selects its parents, model+ its children, @model its children plus their parents, and a number limits depth, as in 2+model. Selection also works by tag, path, source and resource type.
Which artifacts does dbt write, and who uses them?Metadatamanifest.json (the full project graph), run_results.json (timings and statuses) and catalog.json (warehouse column info). CI state comparison, docs, observability tools and orchestrators read them.
How do you schedule dbt in production?Orchestrationdbt Cloud jobs, or dbt Core run by an orchestrator such as Airflow on a schedule or after a load finishes. Run freshness, then build, alert on failures, and keep artifacts from each run.
A model ran before the table it reads was rebuilt. Why?DAG bugsIt reads a hard-coded table name instead of ref(), so dbt does not know about the dependency. Search the project for direct references to schemas that dbt manages.
Senior questions. Scroll sideways on a small screen.

Replacing hand-written SQL pipelines with dbt

A common interview scenario is a team running stored procedures, scheduled SQL scripts or HiveQL jobs that only one person understands. A good answer moves in steps: declare the raw tables as sources; turn each script's final SELECT into a model and replace table names with ref() so dbt can order them; start with table materializations and change the biggest ones to incremental later; add unique and not-null tests on every key before touching logic; compare row counts and sums between the old and new outputs for a few weeks; then switch dashboards over and retire the scripts. If the source scripts are HiveQL, mention that dbt adapters exist for Spark and Databricks, and see Hive interview questions for the table behavior you will be translating.

Fictional example

Answering "Your revenue model started double counting. What do you do?"
Interviewer
Yesterday finance noticed revenue in the orders mart is about 4% higher than in the billing system. The model is incremental. How do you approach it?
Candidate
First I would confirm the gap is real by comparing order counts and sums by day between the mart and billing, which tells me whether it is spread out or concentrated on recent days. If it is recent, my first suspect is the incremental logic. I would check that the model has a unique_key and that the strategy actually merges on this adapter, because without a key a three-day lookback appends the same orders again on every run. I would then run the compiled SQL for the incremental branch from the target folder and look for duplicate order IDs in its output, for example from a join to payments that fans out. The fix depends on the cause: add or correct the unique key, dedupe before the join, then run a full refresh or rebuild the affected dates. Finally I would add a unique test on order_id and a singular test comparing daily totals to billing within a tolerance, so this shows up in the build instead of in a finance meeting.

How to prepare for dbt interview questions

  1. Build a small project locallyUse dbt Core with a local warehouse adapter or a trial warehouse. Add two sources, staging models, one mart, seeds for a lookup, and tests on every key.
  2. Make an incremental model misbehaveRemove its unique_key and run it twice, then send in a row older than the lookback window. Seeing the duplicates and the missed row makes the answers easy to give.
  3. Read compiled SQLAfter every change, open the files in target/compiled and target/run and explain what dbt sent to the warehouse. Interviewers often ask exactly that.
  4. Practice selection and CIWrite the commands for building one model and its children, everything tagged nightly, and only modified models against saved production artifacts.
  5. Write one macro and one custom testKeep both short, document them, and be ready to say when you would not use a macro.

For the platforms dbt usually runs on, see Snowflake interview questions and Databricks interview questions. Airflow interview questions covers scheduling dbt alongside loads, and data modeling interview questions covers the schema design underneath.

Debugging questions like the double counting one reward a calm order of steps, which is hard to find the first time you hear the question. Natively, an AI interview assistant for Mac and Windows, can transcribe a mock dbt round, read a model, a YAML file or a failed test's output from a screenshot, and put a suggested line of reasoning next to your own while you answer. On Pro or during the free trial, the résumé and job description you add shape those suggestions, and the transcript and notes of each session stay available for review.

Questions people ask

What are common dbt interview questions?

Why ref() matters, the difference between run and build, the materializations, how is_incremental() and unique_key work, snapshot strategies, generic versus singular tests, source freshness, macros, and how to run only changed models in CI.

What is the difference between dbt run and dbt build?

dbt run executes models only. dbt build runs seeds, models, snapshots and tests together in dependency order, and skips anything downstream of a model or test that fails.

How does an incremental model work in dbt?

On the first run dbt builds the whole table. On later runs is_incremental() is true, so a filter limits the SELECT to new or recent rows, and the incremental strategy merges or appends them using the unique_key.

What is the difference between dbt tests and unit tests?

Data tests query the built data and fail when they return rows, such as duplicate keys. Unit tests, added in recent dbt versions, run a model on fixed input rows and compare its output to expected rows to check the logic itself.

Where to go next

Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.

Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.

Keep reading

Put it on your own machine.

A live-conversation assistant that runs locally. Your conversations stay on your machine.

macOS 12+ · Windows 10/11

© 2026 Natively AI Private Limited

Source-available under the Natively Personal Use Source License v1.0 · IP geolocation by DB-IP