DBT Interview Questions and Answers for Analytics Engineers
Preparing for an analytics engineering interview that covers dbt means getting comfortable with a wide range of topics, from project structure and model design to testing, snapshots, Jinja macros, and production deployment. This guide covers 38 role-relevant dbt interview questions and answers to help you prepare effectively, whether you are a data analyst moving into an analytics engineering role or an experienced data engineer looking to sharpen your dbt knowledge before an interview.
Advanced and Scenario-Based dbt Interview Questions
1. A dbt model is taking too long to run. How would you debug and optimize it?
Start by running dbt run --select model_name in isolation and checking the warehouse query profile or execution plan for the underlying SQL. Common causes include full table scans on large source tables due to missing or unused partitioning or clustering, expensive joins without proper key indexing, or a view materialization that recomputes a complex query every time it is queried downstream. Solutions include switching the materialization from view to table or incremental, adding partition or cluster keys at the warehouse level, simplifying the SQL logic, and pushing expensive aggregations to a dedicated intermediate model so that multiple downstream models do not recompute the same logic independently.
2. How would you design a dbt project for a large analytics team with multiple business domains?
Organize models into domain-specific subdirectories under models/marts/, such as models/marts/finance/, models/marts/marketing/, and models/marts/product/. Use a shared staging layer (models/staging/) for source-specific cleaning logic and an intermediate layer for cross-domain joins. Assign model ownership using dbt meta fields or tags, and use exposures to declare which BI dashboards or tools consume which marts. Apply folder-level configurations in dbt_project.yml to enforce materialization and schema conventions per domain without needing config blocks in every model file.
3. How do you decide between building logic in dbt vs the BI layer?
Logic belongs in dbt when it is shared across multiple reports or consumers, needs to be tested and documented, involves joins or aggregations that are expensive to recompute in the BI tool, or represents a canonical business definition that should be consistent everywhere. Logic belongs in the BI layer when it is specific to a single report's visualization needs, involves display formatting, or is a user-specific filter. The guiding principle is that business definitions and metrics should be defined once in dbt so that all downstream consumers agree on the same numbers.In a CI/CD setup, a pull request to the main branch triggers a pipeline that runs dbt build --select state:modified+ to build and test only the models changed in the PR and their downstream dependencies, using dbt's state comparison against the production artifact. This is natively supported in dbt Cloud as a CI job triggered by a pull request webhook. In dbt Core, the same logic can be orchestrated with GitHub Actions or another CI tool. The pipeline should fail the PR if any dbt test fails, preventing broken transformations from reaching production.
4. How would you set up CI/CD for a dbt project?
In a CI/CD setup, a pull request to the main branch triggers a pipeline that runs dbt build --select state:modified+ to build and test only the models changed in the PR and their downstream dependencies, using dbt's state comparison against the production artifact. This is natively supported in dbt Cloud as a CI job triggered by a pull request webhook. In dbt Core, the same logic can be orchestrated with GitHub Actions or another CI tool. The pipeline should fail the PR if any dbt test fails, preventing broken transformations from reaching production.
5. How would you handle breaking schema changes from a source system?
Source schema changes, such as a column being renamed or dropped, will cause dependent dbt models to fail at compile or run time. The mitigation strategy involves monitoring source freshness and compile errors in CI before the change reaches production. When a breaking change is known in advance, update the staging model that references the source first, run the full downstream lineage to identify all affected models, and deploy the fix as a coordinated change. For unplanned breaks, dbt's source() declarations concentrate the impact to the staging layer, limiting how many models need to be updated.
Learn via our Video Courses
dbt Basics Interview Questions
1. How is dbt different from traditional ETL tools?
Traditional ETL tools extract data from sources, transform it outside the warehouse in a dedicated processing layer, and load the results into the destination. dbt operates only on the transformation step and runs entirely inside the data warehouse, making it part of an ELT pattern. Unlike drag-and-drop ETL tools, dbt transformations are written in SQL with Jinja templating, stored in version control, and can be tested and documented alongside the code. This makes dbt transformations more auditable, reproducible, and collaborative.
2. What is the role of dbt in an ELT pipeline?
In an ELT pipeline, raw data is first loaded into the data warehouse by separate ingestion tools such as Fivetran, Airbyte, or custom pipelines. dbt handles the T in ELT, taking that raw data and transforming it into clean, structured, and business-ready models through a series of SQL models. dbt does not extract or load data; its responsibility begins once raw data is already in the warehouse and ends when the transformed output is ready for BI tools and downstream consumers.
3. What does an analytics engineer do with dbt?
An analytics engineer uses dbt to build and maintain the transformation layer between raw data and business-facing reports. This involves writing SQL models that clean and join raw source data, defining tests to validate data quality, documenting models and columns so that consumers understand the data, building incremental models for performance, managing snapshots for historical tracking, and coordinating with data engineers on source data quality and with analysts on business logic requirements.
4. What is the difference between dbt Core and dbt Cloud?
| Feature | dbt Core | dbt Cloud |
|---|---|---|
| Deployment | Open-source CLI, self-hosted | Managed SaaS platform by dbt Labs |
| Scheduling | External orchestrators (Airflow, etc.) | Built-in job scheduler |
| IDE | Local code editor | Browser-based IDE |
| CI/CD | Manually configured | Natively supported |
| Observability | External logging | Built-in run history, alerts, lineage UI |
| Cost | Free | Paid tiers with a free developer tier |
dbt Core is the open-source engine that any team can install and run locally or in their own infrastructure. dbt Cloud wraps dbt Core with a managed environment, job scheduling, a browser IDE, and collaboration features. Most interview questions apply to both, but dbt Cloud-specific questions focus on job setup, environments, and CI integration.
5. What is dbt, and why is it used in modern data teams?
dbt, which stands for data build tool, is an open-source transformation framework that allows analysts and engineers to write SQL-based data transformations as version-controlled, testable, and documented code. It is used by modern data teams to bring software engineering best practices like modularity, testing, and CI/CD into the analytics layer. dbt runs transformations inside the data warehouse by compiling SQL and executing it against the warehouse directly, rather than moving data outside it. The official overview is available at the dbt Developer Hub.
dbt Models and Materializations Interview Questions
1. What is the difference between ref() and source() in dbt?
ref() is used to reference another dbt model within the project. It creates a dependency between models that dbt tracks in the DAG and ensures models execute in the correct order. source() is used to reference raw tables that dbt did not create, such as data loaded by an ingestion tool. Declaring sources in YAML allows dbt to track freshness, generate documentation for raw tables, and include them in the lineage graph. Using source() instead of hardcoding raw table names also makes it easier to change schema locations in a single place.
2. What is a dbt model?
A dbt model is a single SQL file (or Python file) in the models directory that defines a transformation. Each model represents one node in the project's DAG and compiles to a SQL SELECT statement that dbt executes against the warehouse. Models can reference other models using the ref() function, which creates a dependency tracked in the lineage graph. When you run dbt run, dbt executes all models in dependency order, materialized according to their configured strategy.
3. What are dbt materializations?
A materialization defines how dbt persists the results of a model in the data warehouse. It controls whether the model runs as a query view, a physical table rebuild, an incremental append or merge, or a temporary ephemeral subquery. The chosen materialization affects warehouse cost, query performance, and how frequently data is refreshed. Materializations can be set at the project level in dbt_project.yml or overridden at the individual model level in a config block.
4. What is the difference between view, table, incremental, and ephemeral materializations?
| Materialization | What It Creates | Rebuilt on Each Run | Best For |
|---|---|---|---|
| view | A database view | Yes (view definition updated) | Light transformations queried infrequently |
| table | A physical table | Yes (full rebuild) | Stable, frequently queried models |
| incremental | A table updated with new/changed rows | No (only new rows processed) | Large fact tables where full rebuild is expensive |
| ephemeral | A CTE, no warehouse object | Not persisted | Reusable logic with no direct querying need |
5. When would you use an incremental model in dbt?
Use an incremental model when a full table rebuild on every run would be too slow or too expensive, typically for large event or transaction tables where new rows are appended regularly and historical rows rarely change. An incremental model processes only the rows that have arrived or changed since the last run, keeping compute costs proportional to the volume of new data rather than total table size. It requires a reliable timestamp or unique key column to identify new and updated records.
6. How do you handle late-arriving data in an incremental dbt model?
Late-arriving data refers to records that arrive after the timestamp window used in the incremental filter, meaning they would be missed on the standard incremental run. The common approach is to define a lookback window in the incremental filter, for example processing rows from the last 3 days rather than only since the last run timestamp. This reprocesses a small overlap of recent data on every run to capture late arrivals without reprocessing the entire table. Alternatively, a full refresh can be scheduled periodically as a safety net.
-- models/events.sql
{{ config(materialized='incremental', unique_key='event_id') }}
SELECT *
FROM {{ source('raw', 'events') }}
{% if is_incremental() %}
WHERE event_timestamp >= DATEADD(day, -3, (SELECT MAX(event_timestamp) FROM {{ this }}))
{% endif %}
dbt Project Structure and Configuration Questions
1. What is the purpose of dbt_project.yml?
dbt_project.yml is the central configuration file for a dbt project. It defines the project name, the dbt version, the paths to models, seeds, snapshots, and tests, and the default configurations for models such as materialization strategy and schema assignments. It also allows you to set folder-level configurations so that all models within a given directory inherit the same materialization or schema without needing individual configuration blocks in each model file.
2. What is profiles.yml, and how is it different from dbt_project.yml?
profiles.yml stores connection credentials and environment-specific configuration for connecting dbt to a data warehouse, such as Snowflake account details, BigQuery project IDs, or Redshift host information. It is stored locally on the developer's machine (or as a secret in CI/CD pipelines) and is not committed to version control, since it contains sensitive credentials. dbt_project.yml is committed to version control and defines project-level logic, while profiles.yml defines how to connect to the target environment.
3. What are the common folders in a dbt project?
A standard dbt project contains a models directory for SQL and Python transformation files, a tests directory for singular test SQL files, a seeds directory for CSV files loaded as tables, a snapshots directory for snapshot definitions, a macros directory for reusable Jinja functions, an analyses directory for ad-hoc SQL not materialized as models, and a docs directory or inline schema YAML files for documentation. The dbt_project.yml file sits at the root alongside packages.yml and any environment configuration files.
4. How do you organize staging, intermediate, and mart models in dbt?
The widely adopted convention is a layered folder structure inside the models directory. Staging models (models/staging/) sit closest to the raw source data and perform light transformations like renaming columns, casting data types, and filtering out deleted records. Intermediate models (models/intermediate/) contain join logic and business transformations that are not yet ready for end consumers. Mart models (models/marts/) are the final, business-facing tables consumed by BI tools and analysts, organized by business domain such as finance or marketing. This structure keeps logic separated by purpose and makes lineage easier to follow.
5. How do you manage different dev, staging, and production environments in dbt?
In dbt Core, environments are managed through separate targets in profiles.yml, each pointing to a different schema or database. Developers run against a personal development schema to avoid affecting shared data. In dbt Cloud, environments are configured in the UI with separate credentials, and jobs are associated with specific environments. A common pattern is to use a variable like target.schema in model configurations so that each environment writes to its own isolated schema, preventing dev runs from polluting production tables.
dbt Testing and Documentation Interview Questions
1. What is the difference between generic tests and singular tests?
| Feature | Generic Tests | Singular Tests |
|---|---|---|
| Definition | Defined in schema YAML, applied to columns | Standalone SQL files in the tests directory |
| Reusability | Reusable across multiple models and columns | Written for a specific one-off assertion |
| Built-in options | unique, not_null, relationships, accepted_values | Custom SQL query |
| Custom generics | Yes, via macros | No |
| Best for | Standard data quality checks | Complex cross-model business logic assertions |
2. How do you test uniqueness, not null, relationships, and accepted values in dbt?
These four tests are built into dbt Core and can be applied in schema.yml by listing them under a column's tests key. unique checks that no two rows share the same value in the column. not_null checks that the column contains no null values. relationships checks referential integrity by verifying that every value in the column exists in a specified column of another model. accepted_values checks that the column only contains values from a defined list.
models:
- name: orders
columns:
- name: order_id
tests:
- unique
- not_null
- name: status
tests:
- accepted_values:
values: ['placed', 'shipped', 'returned', 'completed']
- name: customer_id
tests:
- relationships:
to: ref('customers')
field: customer_id
3. How do you document models and columns in dbt?
Documentation is written in schema.yml files using description fields on models and individual columns. For longer descriptions, dbt supports doc blocks defined in .md files using {% raw %}{% docs block_name %}{% endraw %} syntax, which can be referenced from YAML with {% raw %}{{ doc('block_name') }}{% endraw %}. Running dbt docs generate compiles all descriptions, test results, and lineage into a static documentation site, and dbt docs serve launches it locally for review.
4. What is schema.yml used for in dbt?
schema.yml (or any YAML file in the models directory) is used to declare model and column metadata in one place. It defines tests for data quality, descriptions for documentation, tags for selection and filtering, and column-level configuration such as accepted values. It is also where sources, seeds, snapshots, and exposures are declared. A well-maintained schema.yml is the primary interface through which collaborators understand what a model contains and how it behaves.
5. What are data tests in dbt?
Data tests in dbt are SQL-based assertions that validate the quality and integrity of data in your models. When a test runs, dbt executes the test SQL and expects it to return zero rows. If any rows are returned, the test fails. Tests can be attached to models, sources, seeds, and snapshots. The dbt Developer Hub on data tests provides the complete reference for writing and configuring tests.dbt parses all ref() and source() calls across every model in the project and constructs a directed acyclic graph (DAG) representing the dependency relationships. When you run dbt run, dbt executes models in the order dictated by the DAG, ensuring that upstream models are materialized before downstream models that depend on them. The lineage graph is visualized in dbt docs generate and dbt docs serve, and in dbt Cloud's built-in lineage explorer. This makes it easy to understand the impact of changing any model and to trace data from a BI dashboard back to its raw source.
Frequently Asked Questions About dbt Interviews
1. What are the most important dbt interview topics?
The most frequently tested topics are dbt models and materializations (especially incremental), the difference between ref() and source(), sources and source freshness, snapshots and SCD handling, generic and singular tests, Jinja and macros, and scenario-based questions on CI/CD setup, performance optimization, and handling source schema changes. Senior-level interviews also test project design for scale and stakeholder communication around data quality.
2. Is dbt used by data engineers or analytics engineers?
dbt is used by both, but it is most closely associated with the analytics engineering role. Analytics engineers own the transformation layer between raw data and BI tools and are the primary users of dbt's model, test, and documentation features. Data engineers increasingly use dbt as part of broader pipeline orchestration, particularly for the transformation step in ELT pipelines on Snowflake, BigQuery, Redshift, and Databricks.
3. What is the difference between dbt Core and dbt Cloud?
dbt Core is the open-source CLI tool that any team can install and run in their own environment. dbt Cloud is a managed SaaS platform that wraps dbt Core with a browser-based IDE, job scheduling, CI/CD integration, built-in lineage visualization, and alerting. Most interview questions apply to both, but dbt Cloud-specific questions focus on environment configuration, job setup, and the native CI/CD pipeline for pull request validation.
4. What SQL skills are required for dbt interviews?
You need to be comfortable writing CTEs, window functions, aggregate queries, and multi-table joins. An understanding of how Snowflake, BigQuery, or Redshift handles partitioning, clustering, and query optimization is valuable for incremental model and performance questions. dbt itself does not require advanced SQL beyond what you would write for data analysis, but senior-level interviews may ask about query optimization and warehouse-specific SQL features.
5. What are the most common dbt scenario-based interview questions?
The most common scenarios cover designing a project folder structure for a multi-domain team, debugging a slow-running model, setting up CI/CD to prevent broken models from reaching production, handling late-arriving data in an incremental model, and explaining what happens when a source schema changes unexpectedly. These scenarios test whether you can apply dbt concepts to real production problems rather than just reciting definitions.
6. How should freshers prepare for dbt interviews?
Start by setting up a free dbt Core project connected to a trial Snowflake or BigQuery instance and working through the official dbt Developer Hub tutorials on models, sources, tests, and snapshots. Build a small project with a staging layer, at least one incremental model, generic tests on key columns, and a macro for a repeated SQL pattern. Understanding the layered project structure (staging, intermediate, marts) and being able to explain ref() vs source() and view vs table vs incremental materializations will cover the majority of fresher-level dbt interview questions.
Jinja, Macros, and Packages Interview Questions
1. What is Jinja, and how is it used in dbt?
Jinja is a templating language originally from Python that dbt uses to add dynamic logic to SQL files. In dbt, Jinja enables you to use variables, write conditional logic with {% raw %}{% if %}{% endraw %} blocks, loop with {% raw %}{% for %}{% endraw %} blocks, call built-in functions like ref() and source(), and invoke reusable macros. dbt compiles Jinja-templated SQL into plain SQL before executing it against the warehouse. This allows logic like environment-specific filters, dynamic column generation, and reusable transformation patterns without duplicating SQL.
2. What are macros in dbt?
Macros are reusable Jinja functions defined in .sql files inside the macros directory. They work like functions in a programming language: they accept arguments, contain logic, and return a SQL string that gets inserted at the call site. dbt ships with a set of built-in macros such as is_incremental(), and the dbt-utils package provides a widely used library of additional macros. You can also write custom macros for logic specific to your project or organization.
3. When would you write a custom macro instead of repeating SQL?
Write a macro when the same SQL logic appears in multiple models with only minor variations, such as a custom date spine generation, a consistent NULL handling pattern, or a standard way to classify events into buckets. Moving repeated SQL into a macro reduces the risk of inconsistency when the logic needs to change, since the update is made in one place and propagates everywhere the macro is called. A good rule of thumb is that if you find yourself copying the same block of SQL into three or more models, it belongs in a macro.
4. What are dbt packages, and how do they improve development?
dbt packages are collections of models, macros, and tests published to the dbt Package Hub and installed via packages.yml. The most widely used package is dbt-utils, which provides utility macros for common SQL operations like generating surrogate keys, date spines, and pivot operations. dbt-expectations provides a suite of data quality tests modeled after the Great Expectations framework. Packages reduce the amount of custom code a team needs to maintain and provide battle-tested implementations of common patterns.
5. How do you debug compiled SQL generated by Jinja or macros?
Run dbt compile to generate compiled SQL files in the target/compiled directory without executing them. Open the compiled file for the model in question to see the exact SQL that dbt would run against the warehouse, with all Jinja resolved. For macro-specific debugging, use {% raw %}{{ log(variable, info=true) }}{% endraw %} to print values to the console during a run. If the SQL looks correct when compiled but fails at runtime, run it directly against the warehouse using your SQL client to isolate the warehouse-level error from any dbt-level issue.
Sources, Seeds, Snapshots, and Lineage Questions
1. What are sources in dbt, and why should you define them?
Sources are raw tables in the warehouse that are loaded by external tools and referenced by dbt staging models. Defining them in a sources.yml file allows dbt to generate documentation for raw tables, include them in the lineage DAG, check their freshness, and make the reference portable through source() calls rather than hardcoded schema and table names. Defining sources also makes it easy to change the raw schema location in one place if it ever moves. The dbt Developer Hub on sources covers the full configuration options.
2. What is source freshness in dbt?
Source freshness is a dbt feature that checks whether raw source tables have been updated within an expected time window. You define loaded_at_field and freshness thresholds (warn and error) in the source YAML. Running dbt source freshness queries the max value of the loaded_at field and compares it against the thresholds. This gives the team an early warning if an upstream ingestion pipeline is delayed before that staleness propagates into downstream dashboards.
3. What are seeds in dbt, and when should you use them?
Seeds are CSV files stored in the seeds directory of a dbt project that dbt loads into the warehouse as tables using dbt seed. They are used for small, static reference datasets such as country codes, cost center mappings, or campaign category lookups that change infrequently and benefit from being version-controlled alongside the transformation code. Seeds are not appropriate for large datasets or data that changes frequently, where a proper ingestion pipeline is a better fit.
4. What are snapshots in dbt?
Snapshots are a dbt feature for capturing the historical state of a mutable source table over time. They implement slowly changing dimension (SCD) logic by recording when rows were inserted, when they changed, and when they became inactive. dbt snapshots use either a timestamp strategy (comparing an updated_at column) or a check strategy (comparing specified columns for any change) to detect changes, then append new rows with dbt_valid_from and dbt_valid_to metadata columns. The dbt Developer Hub on snapshots covers both strategies in detail.
5. How do snapshots help track slowly changing dimensions?
A slowly changing dimension (SCD) is a dimension whose attributes change over time, such as a customer's address, plan tier, or sales region. Without snapshots, a simple overwrite of the source table loses the historical record of what the value was at a given point in time. dbt snapshots maintain a full history by writing a new row each time an attribute changes, with valid-from and valid-to timestamps. This allows downstream models to join to the snapshot at any historical point and reconstruct what the dimension looked like at that time.