dbt Interview Questions and Answers Part 10 - Real-World Manager Scenarios

dbt Interview Q&A · Part 10 of 10

In this post we are going to cover real-world manager scenarios in dbt, through 7 real dbt interview questions for data engineers, asked the way they come up on a real project. The last one is a scenario from the final round: the hiring manager asks you to design a dbt project for a company with five source systems and three business domains.

These questions are not about one feature. A manager wants to know what you do when the 6 AM job fails, when a number is wrong, or when a merge breaks reports. They want to hear that you communicate first, then use evidence, and then fix the process so it does not happen again. That is what separates a senior engineer from someone who only knows the commands.

Part 10 of the Real Time dbt Interview Questions and Answers series on TechBrothersIT.

The short answer

Say this first

Lead with communication, then use evidence: dbt retry after a failure, a layer-by-layer comparison to trace a number, a revert plus tests on the grain and slim CI so bad merges fail before production. Make the case for dbt with a pilot, give new analysts a sandbox and guardrails, measure cost before you cut, and design in layers with domains as groups.

Let's create the project and some sample data

Our project is a small shop with three seeds: raw_orders with six orders, raw_customers with three customers, and raw_payments. Staging views clean them up, a finance mart builds daily revenue, and an exposure connects it to the executive dashboard. The profile has three targets in one DuckDB file: dev writes to dbt_sara, ci to dbt_ci, and prod to analytics. Here are all the starting files.

dbt_project.yml
name: shop
version: '1.0'
profile: shop

models:
  shop:
    staging:
      +materialized: view
    marts:
      +materialized: table
profiles.yml
# demo only: real prod credentials live in the scheduler
shop:
  target: dev
  outputs:
    dev:
      type: duckdb
      path: dev.duckdb
      schema: dbt_sara
      threads: 4
    ci:
      type: duckdb
      path: dev.duckdb
      schema: dbt_ci
      threads: 4
    prod:
      type: duckdb
      path: dev.duckdb
      schema: analytics
      threads: 4
seeds/raw_orders.csv
order_id,customer_id,amount,status,order_date
1,10,120.00,completed,2026-10-24
2,11,80.00,completed,2026-10-24
3,10,45.50,refunded,2026-10-24
4,12,200.00,completed,2026-10-25
5,13,95.00,completed,2026-10-25
6,11,60.00,completed,2026-10-25
seeds/raw_customers.csv
customer_id,name,region
10,Ali Khan,East
11,Sara Lee,West
12,John Smith,East
seeds/raw_payments.csv
payment_id,order_id,method,amount
1,1,card,120.00
2,2,card,50.00
3,2,gift_card,30.00
4,4,card,200.00
5,5,card,95.00
6,6,card,60.00
models/staging/stg_orders.sql
select order_id, customer_id, amount, status, order_date
from {{ ref('raw_orders') }}
models/staging/stg_customers.sql
select customer_id, name, region
from {{ ref('raw_customers') }}
models/staging/stg_payments.sql
select payment_id, order_id, method, amount
from {{ ref('raw_payments') }}
models/marts/finance/fct_daily_revenue.sql
select order_date, count(*) as orders, sum(amount) as revenue
from {{ ref('stg_orders') }}
where status = 'completed'
group by order_date
models/marts/finance/_finance.yml
models:
  - name: fct_daily_revenue
    columns:
      - name: order_date
        data_tests: [unique, not_null]
models/exposures.yml
exposures:
  - name: exec_dashboard
    type: dashboard
    depends_on: [ref('fct_daily_revenue')]
    owner: {name: CFO Office, email: cfo-office@example.com}

Question 1: The 6 AM dbt job failed and the executive dashboard is stale. Walk me through your first thirty minutes.

Communicate first, then debug. In the first five minutes I tell the dashboard owners the data is stale, and when they will hear from me next.

Let's set up the incident. Yesterday the prod build succeeded with dbt build --target prod.

Terminal
$ dbt build --target prod
 Succeeded seed  analytics.raw_customers (table)
 Succeeded seed  analytics.raw_orders (table)
 Succeeded seed  analytics.raw_payments (table)
 Succeeded model analytics.stg_customers (view)
 Succeeded model analytics.stg_orders (view)
 Succeeded model analytics.stg_payments (view)
 Succeeded model analytics.fct_daily_revenue (table)
    Passed test  not_null_fct_daily_revenue_order_date
    Passed test  unique_fct_daily_revenue_order_date

Finished 'build' successfully for target 'prod'
Processed: 4 models | 2 tests | 3 seeds
Summary: 9 total | 9 success

Overnight, the loader renamed amount to amount_usd. We simulate that by reloading the seed.

seeds/raw_orders.csv
order_id,customer_id,amount_usd,status,order_date
1,10,120.00,completed,2026-10-24
2,11,80.00,completed,2026-10-24
3,10,45.50,refunded,2026-10-24
4,12,200.00,completed,2026-10-25
5,13,95.00,completed,2026-10-25
6,11,60.00,completed,2026-10-25
Terminal
$ dbt seed --full-refresh -s raw_orders --target prod
 Succeeded seed  analytics.raw_orders (table)

Finished 'seed' successfully for target 'prod'
Processed: 1 seed
Summary: 1 total | 1 success

Now the 6 AM job runs the same dbt build --target prod.

Terminal (expected error)
$ dbt build --target prod
 Succeeded seed  analytics.raw_customers (table)
 Succeeded seed  analytics.raw_orders (table)
 Succeeded seed  analytics.raw_payments (table)
 Succeeded model analytics.stg_customers (view)
    Failed model analytics.stg_orders (view)
 Succeeded model analytics.stg_payments (view)
   Skipped model analytics.fct_daily_revenue (table)
   Skipped test  not_null_fct_daily_revenue_order_date (models/marts/finance/_finance.yml:5:30)
   Skipped test  unique_fct_daily_revenue_order_date (models/marts/finance/_finance.yml:5:22)

=================== Errors and Warnings ====================
[error] [DbDriverFailed (dbt1308)]: Database Error in model stg_orders
  (target/run/shop/models/staging/stg_orders.sql)
  Binder Error: Referenced column "amount" not found in FROM clause!
  Candidate bindings: "amount_usd", "status", "order_date", "customer_id"

  LINE 5:     select order_id, customer_id, amount, status, order_date
                                            ^
  (in run/shop/models/staging/stg_orders.sql)

Finished 'build' with 1 error for target 'prod'
Processed: 4 models | 2 tests | 3 seeds
Summary: 9 total | 5 success | 1 error | 3 skipped

stg_orders failed: Referenced column "amount" not found, and DuckDB lists the candidate, "amount_usd". fct_daily_revenue and its two tests were skipped, so the dashboard is stale, but not wrong. Skipped models keep yesterday's tables.

That is the triage: data, code, or platform? It is a source change, so I fix forward with a hotfix pull request: staging maps amount_usd back to amount. Then dbt retry --target prod.

models/staging/stg_orders.sql
select order_id, customer_id, amount_usd as amount, status, order_date
from {{ ref('raw_orders') }}
Terminal
$ dbt retry --target prod
  Retrying 4 nodes from previous build command
 Succeeded model analytics.stg_orders (view)
 Succeeded model analytics.fct_daily_revenue (table)
    Passed test  not_null_fct_daily_revenue_order_date
    Passed test  unique_fct_daily_revenue_order_date

Finished 'retry' successfully for target 'prod'

dbt says Retrying 4 nodes from previous build command: only the nodes that failed or were skipped. So the first thirty minutes look like this:

  • Tell the owners: stale, next update
  • Read the error
  • Triage: data, code or platform?
  • Fix forward or roll back: a hotfix PR
  • dbt retry: failed and skipped only
  • Verify, then a post-mortem, with a source schema check to catch the next rename
Pitfall

On dbt v2 here, retry used the default target, so pass the same --target the job used.

Question 2: The revenue number in the dashboard does not match the source system. How do you trace the difference through the dbt lineage?

Don't argue about the numbers. Walk the lineage one layer at a time, and compute the same measure at each layer.

Here is the model behind the revenue by region dashboard, fct_customer_revenue, and its exposure. Let's build it.

models/marts/finance/fct_customer_revenue.sql
select c.region, count(*) as orders, sum(o.amount) as revenue
from {{ ref('stg_orders') }} as o
join {{ ref('stg_customers') }} as c
    on o.customer_id = c.customer_id
where o.status = 'completed'
group by c.region
models/exposures.yml
exposures:
  - name: exec_dashboard
    type: dashboard
    depends_on: [ref('fct_daily_revenue')]
    owner: {name: CFO Office, email: cfo-office@example.com}
  - name: revenue_by_region
    type: dashboard
    depends_on: [ref('fct_customer_revenue')]
    owner: {name: Finance Data Team, email: finance-data@example.com}
Terminal
$ dbt build -s +fct_customer_revenue --target prod
 Succeeded seed  analytics.raw_customers (table)
 Succeeded seed  analytics.raw_orders (table)
 Succeeded model analytics.stg_customers (view)
 Succeeded model analytics.stg_orders (view)
 Succeeded model analytics.fct_customer_revenue (table)

Finished 'build' successfully for target 'prod'
Processed: 3 models | 2 seeds
Summary: 5 total | 5 success

Now we list everything upstream with dbt ls -s +fct_customer_revenue, and run scripts/compare_layers.sql, which counts completed orders and revenue at each layer with the same filter.

scripts/compare_layers.sql
select 'raw_orders' as layer, count(*) as orders,
       sum(amount_usd) as revenue
from analytics.raw_orders where status = 'completed'
union all
select 'stg_orders', count(*), sum(amount)
from analytics.stg_orders where status = 'completed'
union all
select 'fct_customer_revenue', sum(orders), sum(revenue)
from analytics.fct_customer_revenue
Terminal
$ dbt ls -s +fct_customer_revenue
=======================Selected nodes=======================
shop.marts.finance.fct_customer_revenue
shop.staging.stg_customers
shop.staging.stg_orders
shop.raw_customers
shop.raw_orders

Finished 'list' successfully for target 'dev'
SQL - check the table (DuckDB)
select 'raw_orders' as layer, count(*) as orders,
       sum(amount_usd) as revenue
from analytics.raw_orders where status = 'completed'
union all
select 'stg_orders', count(*), sum(amount)
from analytics.stg_orders where status = 'completed'
union all
select 'fct_customer_revenue', sum(orders), sum(revenue)
from analytics.fct_customer_revenue
Result3 rows
layerordersrevenue
raw_orders5555
stg_orders5555
fct_customer_revenue4460

raw_orders and stg_orders agree: 5 orders and 555. The fact table has 4 orders and 460, so the gap is in the fact. Opening the model, it inner joins orders to customers, so an order with a missing customer silently drops out. A left join with an is null filter finds it.

scripts/orphan_orders.sql
select o.order_id, o.customer_id, o.amount
from analytics.stg_orders as o
left join analytics.stg_customers as c
    on o.customer_id = c.customer_id
where c.customer_id is null
SQL - check the table (DuckDB)
select o.order_id, o.customer_id, o.amount
from analytics.stg_orders as o
left join analytics.stg_customers as c
    on o.customer_id = c.customer_id
where c.customer_id is null
Result1 row
order_idcustomer_idamount
51395

Order 5, customer 13, amount 95. Exactly the gap. The fix: the source loads the missing customer, the model becomes a left join with an 'Unknown' region, and a relationships test guards the key. Let's build and compare again.

seeds/raw_customers.csv
customer_id,name,region
10,Ali Khan,East
11,Sara Lee,West
12,John Smith,East
13,Maria Lopez,West
models/marts/finance/fct_customer_revenue.sql
select coalesce(c.region, 'Unknown') as region,
       count(*) as orders, sum(o.amount) as revenue
from {{ ref('stg_orders') }} as o
left join {{ ref('stg_customers') }} as c
    on o.customer_id = c.customer_id
where o.status = 'completed'
group by 1
models/staging/_staging.yml
models:
  - name: stg_orders
    columns:
      - name: order_id
        data_tests: [unique, not_null]
      - name: customer_id
        data_tests:
          - relationships:
              arguments:
                to: ref('stg_customers')
                field: customer_id
Terminal
$ dbt build -s +fct_customer_revenue --target prod
 Succeeded seed  analytics.raw_customers (table)
 Succeeded seed  analytics.raw_orders (table)
 Succeeded model analytics.stg_customers (view)
 Succeeded model analytics.stg_orders (view)
    Passed test  not_null_stg_orders_order_id
    Passed test  relationships_stg_orders_customer_id__customer_id__ref_stg_customers_
    Passed test  unique_stg_orders_order_id
 Succeeded model analytics.fct_customer_revenue (table)

Finished 'build' successfully for target 'prod'
Processed: 3 models | 3 tests | 2 seeds
Summary: 8 total | 8 success
SQL - check the table (DuckDB)
select 'raw_orders' as layer, count(*) as orders,
       sum(amount_usd) as revenue
from analytics.raw_orders where status = 'completed'
union all
select 'stg_orders', count(*), sum(amount)
from analytics.stg_orders where status = 'completed'
union all
select 'fct_customer_revenue', sum(orders), sum(revenue)
from analytics.fct_customer_revenue
Result3 rows
layerordersrevenue
raw_orders5555
stg_orders5555
fct_customer_revenue5555

The relationships test passes, and every layer now shows 5 orders and 555.

Real project tip

Agree on the definition first: which statuses, which date, which currency. Many mismatches are two teams counting different things.

Question 3: A model change you merged yesterday broke three downstream reports. How do you recover, and what do you change in the process?

Recover first, then improve the process: revert, rebuild, then add the test and the CI check that would have caught it.

Let's start with the sales models and their dashboards, before the change.

models/marts/sales/fct_orders.sql
select order_id, customer_id, amount, status, order_date
from {{ ref('stg_orders') }}
models/marts/sales/reports/rpt_daily_orders.sql
select order_date, count(*) as orders, sum(amount) as amount
from {{ ref('fct_orders') }}
group by order_date
models/marts/sales/reports/rpt_region_revenue.sql
select c.region, sum(o.amount) as amount
from {{ ref('fct_orders') }} as o
join {{ ref('stg_customers') }} as c using (customer_id)
group by c.region
models/exposures.yml
exposures:
  - name: exec_dashboard
    type: dashboard
    depends_on: [ref('fct_daily_revenue')]
    owner: {name: CFO Office, email: cfo-office@example.com}
  - name: revenue_by_region
    type: dashboard
    depends_on: [ref('fct_customer_revenue')]
    owner: {name: Finance Data Team, email: finance-data@example.com}
  - name: sales_dashboard
    type: dashboard
    depends_on: [ref('rpt_daily_orders')]
    owner: {name: Sales Ops, email: sales-ops@example.com}
  - name: regional_sales
    type: dashboard
    depends_on: [ref('rpt_region_revenue')]
    owner: {name: Sales Ops, email: sales-ops@example.com}
  - name: finance_close
    type: analysis
    depends_on: [ref('fct_orders')]
    owner: {name: Finance Data Team, email: finance-data@example.com}
Terminal
$ dbt build -s +fct_orders+ --target prod
 Succeeded seed  analytics.raw_orders (table)
 Succeeded model analytics.stg_orders (view)
    Passed test  not_null_stg_orders_order_id
    Passed test  relationships_stg_orders_customer_id__customer_id__ref_stg_customers_
    Passed test  unique_stg_orders_order_id
 Succeeded model analytics.fct_orders (table)
 Succeeded model analytics.rpt_daily_orders (table)
 Succeeded model analytics.rpt_region_revenue (table)

Finished 'build' successfully for target 'prod'
Processed: 4 models | 3 tests | 1 seed
Summary: 8 total | 8 success

Yesterday's change joined fct_orders to payments, for the payment method.

models/marts/sales/fct_orders.sql
-- yesterday's change: show the payment method
select o.order_id, o.customer_id, o.amount, o.status,
       o.order_date, p.method as payment_method
from {{ ref('stg_orders') }} as o
left join {{ ref('stg_payments') }} as p
    on o.order_id = p.order_id
Terminal
$ dbt build -s fct_orders+ --target prod
 Succeeded model analytics.fct_orders (table)
 Succeeded model analytics.rpt_daily_orders (table)
 Succeeded model analytics.rpt_region_revenue (table)

Finished 'build' successfully for target 'prod'
Processed: 3 models
Summary: 3 total | 3 success
SQL - check the table (DuckDB)
select count(*) as row_count, count(distinct order_id) as orders from analytics.fct_orders
Result1 row
row_countorders
76

The build passed, but the check shows 7 rows for 6 orders. Order 2 was paid in two parts, so it appears twice, and nothing tested the grain. Who is affected? We intersect fct_orders+ with resource_type:exposure.

Terminal
$ dbt ls -s "fct_orders+,resource_type:exposure"
=======================Selected nodes=======================
shop.finance_close
shop.regional_sales
shop.sales_dashboard

Finished 'list' successfully for target 'dev'

Three exposures: finance_close, regional_sales and sales_dashboard. Those owners hear from me first. Then roll back, don't patch under pressure:

  • git revert the merge commit
  • Deploy the normal way
  • dbt build -s fct_orders+, and for an incremental model add --full-refresh, because the bad rows are already merged
models/marts/sales/fct_orders.sql
select order_id, customer_id, amount, status, order_date
from {{ ref('stg_orders') }}
Terminal
$ dbt build -s fct_orders+ --target prod
 Succeeded model analytics.fct_orders (table)
 Succeeded model analytics.rpt_daily_orders (table)
 Succeeded model analytics.rpt_region_revenue (table)

Finished 'build' successfully for target 'prod'
Processed: 3 models
Summary: 3 total | 3 success

Now the process. We add a unique test on order_id, the grain, and build the same change in CI with the @ selector, so every child's parents build too.

models/marts/sales/_sales.yml
models:
  - name: fct_orders
    columns:
      - name: order_id
        data_tests: [unique, not_null]
models/marts/sales/fct_orders.sql
-- yesterday's change: show the payment method
select o.order_id, o.customer_id, o.amount, o.status,
       o.order_date, p.method as payment_method
from {{ ref('stg_orders') }} as o
left join {{ ref('stg_payments') }} as p
    on o.order_id = p.order_id
Terminal (expected error)
$ dbt build -s @fct_orders --target ci
 Succeeded seed  dbt_ci.raw_customers (table)
 Succeeded seed  dbt_ci.raw_orders (table)
 Succeeded seed  dbt_ci.raw_payments (table)
 Succeeded model dbt_ci.stg_customers (view)
 Succeeded model dbt_ci.stg_orders (view)
 Succeeded model dbt_ci.stg_payments (view)
    Passed test  not_null_stg_orders_order_id
    Passed test  relationships_stg_orders_customer_id__customer_id__ref_stg_customers_
    Passed test  unique_stg_orders_order_id
 Succeeded model dbt_ci.fct_orders (table)
    Passed test  not_null_fct_orders_order_id
    Failed test  unique_fct_orders_order_id (models/marts/sales/_sales.yml:5:22)
   Skipped model dbt_ci.rpt_daily_orders (table)
   Skipped model dbt_ci.rpt_region_revenue (table)

====================== Test Failures =======================
Test failed (1 failed row(s)): unique_fct_orders_order_id

Finished 'build' with 1 error for target 'ci'
Processed: 6 models | 5 tests | 3 seeds
Summary: 14 total | 11 success | 1 error | 2 skipped

unique_fct_orders_order_id fails with 1 failed row, and both report models are skipped. The pull request is closed, and main keeps the good model.

models/marts/sales/fct_orders.sql
select order_id, customer_id, amount, status, order_date
from {{ ref('stg_orders') }}

And make it stick:

  • Slim CI on every pull request: state:modified+
  • An owner on every exposure: you know who to tell
  • A contract on fct_orders: a shape change is a deliberate decision

Question 4: Leadership asks whether dbt is worth it compared to the stored procedures you have today. How do you make the case?

I don't sell a tool. I sell the outcomes leadership wants: fewer broken dashboards, faster changes, and knowing where every number comes from.

Stored proceduresdbt
LINEAGEin people's headsa graph from ref and source, to the dashboards
TESTINGmanual checks, after the facttests in every build stop bad data
CHANGESedited in place on the serverGit, pull requests and CI
ENVIRONMENTSone copy, usually productiondev, CI and prod from the same code
DOCSa wiki that driftsgenerated from the project

With stored procedures, lineage lives in people's heads. dbt builds the graph from ref and source, out to the dashboards. Testing moves from manual checks after the fact to tests in every build. Changes go through Git, pull requests and CI, not edits on the server, and one codebase builds dev, CI and production. Let's run this project's production build.

Terminal
$ dbt build --target prod
 Succeeded seed  analytics.raw_customers (table)
 Succeeded seed  analytics.raw_orders (table)
 Succeeded seed  analytics.raw_payments (table)
 Succeeded model analytics.stg_customers (view)
 Succeeded model analytics.stg_orders (view)
 Succeeded model analytics.stg_payments (view)
    Passed test  not_null_stg_orders_order_id
    Passed test  relationships_stg_orders_customer_id__customer_id__ref_stg_customers_
    Passed test  unique_stg_orders_order_id
 Succeeded model analytics.fct_customer_revenue (table)
 Succeeded model analytics.fct_daily_revenue (table)
 Succeeded model analytics.fct_orders (table)
    Passed test  not_null_fct_daily_revenue_order_date
    Passed test  not_null_fct_orders_order_id
    Passed test  unique_fct_daily_revenue_order_date
    Passed test  unique_fct_orders_order_id
 Succeeded model analytics.rpt_daily_orders (table)
 Succeeded model analytics.rpt_region_revenue (table)

Finished 'build' successfully for target 'prod'
Processed: 8 models | 7 tests | 3 seeds
Summary: 18 total | 18 success

Eight models and seven tests, all passing, in one command: 18 total | 18 success, with the three seeds.

Be honest about the cost. People need SQL, Git and modeling skills, and dbt is only the T: loading stays with other tools, and scheduling needs the dbt platform or an orchestrator.

Interview tip

Then propose a pilot: one domain, a few weeks, and measure failed runs, time to fix, and hours on manual checks, before and after.

Question 5: A new analyst wants to add models but does not know Git or the project rules. How do you onboard them safely?

Make the safe path the easy path: a personal sandbox, Git as a routine, and CI as the safety net.

First, the sandbox. The dev target, with their own schema dbt_sara, is the default. Production is a separate target that only the scheduler uses. Let's run their first build with the --empty flag.

Terminal
$ dbt build -s +fct_customer_revenue --empty
 Succeeded seed  dbt_sara.raw_customers (table)
 Succeeded seed  dbt_sara.raw_orders (table)
 Succeeded model dbt_sara.stg_customers (view)
 Succeeded model dbt_sara.stg_orders (view)
    Passed test  not_null_stg_orders_order_id
    Passed test  relationships_stg_orders_customer_id__customer_id__ref_stg_customers_
    Passed test  unique_stg_orders_order_id
 Succeeded model dbt_sara.fct_customer_revenue (table)

Finished 'build' successfully for target 'dev'
Processed: 3 models | 3 tests | 2 seeds
Summary: 8 total | 8 success

Everything lands in dbt_sara, never analytics. With --empty, refs return zero rows, so the build checks the SQL, the structure and the test queries for almost no compute: 8 total | 8 success.

Then Git, taught as a routine, with the rules in the repo:

  • A branch per change, small commits
  • A pull request: template, style guide, code owners, so a senior reviews every change
  • Slim CI: state:modified+, and in dbt v2 the strict parse rejects a mistyped YAML key before anyone reviews it
Real project tip

Pair with them on the first change, from branch to merge. Then the guardrails do most of the teaching.

Question 6: The warehouse bill doubled after the team moved to dbt. How do you find and fix the cost?

Measure before you cut, then fix the biggest cause first.

Here is where the numbers come from:

  • Warehouse query history: the most expensive queries
  • Query tags: tie each query back to a model, where supported
  • run_results.json: execution time per model, run after run

Then look for the usual causes. Let's find every model materialized as a table with dbt ls -s config.materialized:table --resource-type model.

Terminal
$ dbt ls -s config.materialized:table --resource-type model
=======================Selected nodes=======================
shop.marts.finance.fct_customer_revenue
shop.marts.finance.fct_daily_revenue
shop.marts.sales.fct_orders
shop.marts.sales.reports.rpt_daily_orders
shop.marts.sales.reports.rpt_region_revenue

Finished 'list' successfully for target 'dev'

Five tables, rebuilt in full on every run, including two small report models, rpt_daily_orders and rpt_region_revenue. The fix: the large fact becomes incremental, keyed on order_id, so each run processes only recent rows, and reports read once a day become views.

dbt_project.yml
name: shop
version: '1.0'
profile: shop

models:
  shop:
    staging:
      +materialized: view
    marts:
      +materialized: table
      sales:
        reports:
          +materialized: view
models/marts/sales/fct_orders.sql
{{ config(materialized='incremental', unique_key='order_id') }}

select order_id, customer_id, amount, status, order_date
from {{ ref('stg_orders') }}
{% if is_incremental() %}
where order_date >= (select max(order_date) from {{ this }})
{% endif %}
Terminal
$ dbt build -s fct_orders+ --target prod
 Succeeded model analytics.fct_orders (incremental)
    Passed test  not_null_fct_orders_order_id
    Passed test  unique_fct_orders_order_id
 Succeeded model analytics.rpt_daily_orders (view)
 Succeeded model analytics.rpt_region_revenue (view)

Finished 'build' successfully for target 'prod'
Processed: 3 models | 2 tests
Summary: 5 total | 5 success

The build shows fct_orders as (incremental) and the two reports as (view). Then CI and dev: slim CI with state:modified+ and --defer builds only what changed, and --empty checks SQL on zero rows. And check the schedule: an hourly run for a daily dashboard burns money.

Real project tip

Add a weekly cost report by model and a budget alert, so the next doubling shows up in a week, not on the invoice.

Scenario 7: In the final round, the hiring manager asks you to design a dbt project for a company with five source systems and three business domains. What is your design?

I'd design it in layers, with each domain as a group that owns its marts.

Let's go layer by layer:

  • Staging: a folder per source (ERP, CRM, Billing, Web events, Support), with its sources file and freshness, and one model per raw table, with renames and casts, nothing else
  • Intermediate: the joins and the business rules
  • Marts: finance, sales and marketing each own theirs
  • Dashboards: exposures connect the marts to them

Governance lives in the project file. Each domain folder is a group with an owner, the marts are public, and staging stays protected. Let's add a marketing mart, then list the interface with dbt ls -s access:public --resource-type model.

dbt_project.yml
name: shop
version: '1.0'
profile: shop

models:
  shop:
    staging:
      +materialized: view
    marts:
      +materialized: table
      +access: public
      finance:
        +group: finance
      sales:
        +group: sales
        reports:
          +materialized: view
      marketing:
        +group: marketing
models/groups.yml
groups:
  - name: finance
    owner: {name: Finance Data Team, email: finance-data@example.com}
  - name: sales
    owner: {name: Sales Ops, email: sales-ops@example.com}
  - name: marketing
    owner: {name: Marketing Analytics, email: marketing@example.com}
models/marts/marketing/mkt_customers_by_region.sql
select region, count(*) as customers
from {{ ref('stg_customers') }}
group by region
Terminal
$ dbt build -s mkt_customers_by_region --target prod
 Succeeded model analytics.mkt_customers_by_region (table)

Finished 'build' successfully for target 'prod'
Processed: 1 model
Summary: 1 total | 1 success
$ dbt ls -s access:public --resource-type model
=======================Selected nodes=======================
shop.marts.finance.fct_customer_revenue
shop.marts.finance.fct_daily_revenue
shop.marts.sales.fct_orders
shop.marts.marketing.mkt_customers_by_region
shop.marts.sales.reports.rpt_daily_orders
shop.marts.sales.reports.rpt_region_revenue

Finished 'list' successfully for target 'dev'

The public interface is six mart models, across finance, sales and marketing. Then the operating model:

  • One Git repo to start, with slim CI on every pull request
  • A production job per domain, using tags and selectors
  • Tests on every primary key, contracts on the public marts
  • Split with dbt Mesh when a domain needs its own release cycle: public refs only, on dbt Enterprise or Enterprise+
Interview tip

Say when you would split. A domain becomes its own project with dbt Mesh when it needs its own release cycle, and refs only the others' public models.

Key points to remember

  • Failed job: tell the owners, triage, fix, dbt retry
  • Wrong number: compare layer by layer down the lineage
  • Bad merge: revert, then test the grain and slim CI
  • The case for dbt: outcomes and a pilot; onboarding: a sandbox and guardrails
  • Cost: measure first; design in layers, domains as groups

The full script

This Python script writes the whole project and runs every dbt command in order; run pip install dbt first.

Show the full script that builds this project and runs every step
Full script - pip install dbt, then run it with Python in an empty folder
# ========================================================================
# dbt Interview Q&A #10 - Real-world manager scenarios
# TechBrothersIT. Sample data is invented for teaching.
# Every step below was run with dbt v2 (dbt OSS 2.0.8) on DuckDB; the outputs in the video and the
# blog post are the real outputs. To run it yourself, in an empty folder:
#   pip install dbt     (dbt v2; adapters are bundled, and DuckDB needs no account or server)
#   python dbt_Interview_QA_10_Code.py
# ========================================================================

import os, subprocess

def write(path, text):
    os.makedirs(os.path.dirname(path) or ".", exist_ok=True)
    with open(path, "w", encoding="utf-8") as f:
        f.write(text.strip("\n") + "\n")

def remove(path):
    if os.path.exists(path):
        os.remove(path)

def dbt(cmd, expect_error=False):
    print("\n$ " + cmd, flush=True)
    rc = subprocess.run(cmd, shell=True).returncode
    if rc != 0 and not expect_error:
        raise SystemExit("stopped: this command was expected to succeed")

# Step 0: the project and its sample data
write('dbt_project.yml', """\
name: shop
version: '1.0'
profile: shop

models:
  shop:
    staging:
      +materialized: view
    marts:
      +materialized: table
""")
write('profiles.yml', """\
# demo only: real prod credentials live in the scheduler
shop:
  target: dev
  outputs:
    dev:
      type: duckdb
      path: dev.duckdb
      schema: dbt_sara
      threads: 4
    ci:
      type: duckdb
      path: dev.duckdb
      schema: dbt_ci
      threads: 4
    prod:
      type: duckdb
      path: dev.duckdb
      schema: analytics
      threads: 4
""")
write('seeds/raw_orders.csv', """\
order_id,customer_id,amount,status,order_date
1,10,120.00,completed,2026-10-24
2,11,80.00,completed,2026-10-24
3,10,45.50,refunded,2026-10-24
4,12,200.00,completed,2026-10-25
5,13,95.00,completed,2026-10-25
6,11,60.00,completed,2026-10-25
""")
write('seeds/raw_customers.csv', """\
customer_id,name,region
10,Ali Khan,East
11,Sara Lee,West
12,John Smith,East
""")
write('seeds/raw_payments.csv', """\
payment_id,order_id,method,amount
1,1,card,120.00
2,2,card,50.00
3,2,gift_card,30.00
4,4,card,200.00
5,5,card,95.00
6,6,card,60.00
""")
write('models/staging/stg_orders.sql', """\
select order_id, customer_id, amount, status, order_date
from {{ ref('raw_orders') }}
""")
write('models/staging/stg_customers.sql', """\
select customer_id, name, region
from {{ ref('raw_customers') }}
""")
write('models/staging/stg_payments.sql', """\
select payment_id, order_id, method, amount
from {{ ref('raw_payments') }}
""")
write('models/marts/finance/fct_daily_revenue.sql', """\
select order_date, count(*) as orders, sum(amount) as revenue
from {{ ref('stg_orders') }}
where status = 'completed'
group by order_date
""")
write('models/marts/finance/_finance.yml', """\
models:
  - name: fct_daily_revenue
    columns:
      - name: order_date
        data_tests: [unique, not_null]
""")
write('models/exposures.yml', """\
exposures:
  - name: exec_dashboard
    type: dashboard
    depends_on: [ref('fct_daily_revenue')]
    owner: {name: CFO Office, email: cfo-office@example.com}
""")

# Step 1: Yesterday: the production build succeeds
dbt('dbt build --target prod')

# Step 2: Overnight, the loader renames amount to amount_usd (simulated with a seed)
write('seeds/raw_orders.csv', """\
order_id,customer_id,amount_usd,status,order_date
1,10,120.00,completed,2026-10-24
2,11,80.00,completed,2026-10-24
3,10,45.50,refunded,2026-10-24
4,12,200.00,completed,2026-10-25
5,13,95.00,completed,2026-10-25
6,11,60.00,completed,2026-10-25
""")
dbt('dbt seed --full-refresh -s raw_orders --target prod')

# Step 3: The 6 AM job fails
dbt('dbt build --target prod', expect_error=True)   # EXPECTED TO FAIL: the video shows this error

# Step 4: Fix staging, then retry only what failed or was skipped
write('models/staging/stg_orders.sql', """\
select order_id, customer_id, amount_usd as amount, status, order_date
from {{ ref('raw_orders') }}
""")
dbt('dbt retry --target prod')

# Step 5: The model behind the revenue dashboard
write('models/marts/finance/fct_customer_revenue.sql', """\
select c.region, count(*) as orders, sum(o.amount) as revenue
from {{ ref('stg_orders') }} as o
join {{ ref('stg_customers') }} as c
    on o.customer_id = c.customer_id
where o.status = 'completed'
group by c.region
""")
write('models/exposures.yml', """\
exposures:
  - name: exec_dashboard
    type: dashboard
    depends_on: [ref('fct_daily_revenue')]
    owner: {name: CFO Office, email: cfo-office@example.com}
  - name: revenue_by_region
    type: dashboard
    depends_on: [ref('fct_customer_revenue')]
    owner: {name: Finance Data Team, email: finance-data@example.com}
""")
dbt('dbt build -s +fct_customer_revenue --target prod')

# Step 6: Walk the lineage, then compare the same measure at each layer
write('scripts/compare_layers.sql', """\
select 'raw_orders' as layer, count(*) as orders,
       sum(amount_usd) as revenue
from analytics.raw_orders where status = 'completed'
union all
select 'stg_orders', count(*), sum(amount)
from analytics.stg_orders where status = 'completed'
union all
select 'fct_customer_revenue', sum(orders), sum(revenue)
from analytics.fct_customer_revenue
""")
dbt('dbt ls -s +fct_customer_revenue')

# Step 7: Find the orders the inner join drops
write('scripts/orphan_orders.sql', """\
select o.order_id, o.customer_id, o.amount
from analytics.stg_orders as o
left join analytics.stg_customers as c
    on o.customer_id = c.customer_id
where c.customer_id is null
""")

# Step 8: The fix: load the missing customer, left join, and a relationships test
write('seeds/raw_customers.csv', """\
customer_id,name,region
10,Ali Khan,East
11,Sara Lee,West
12,John Smith,East
13,Maria Lopez,West
""")
write('models/marts/finance/fct_customer_revenue.sql', """\
select coalesce(c.region, 'Unknown') as region,
       count(*) as orders, sum(o.amount) as revenue
from {{ ref('stg_orders') }} as o
left join {{ ref('stg_customers') }} as c
    on o.customer_id = c.customer_id
where o.status = 'completed'
group by 1
""")
write('models/staging/_staging.yml', """\
models:
  - name: stg_orders
    columns:
      - name: order_id
        data_tests: [unique, not_null]
      - name: customer_id
        data_tests:
          - relationships:
              arguments:
                to: ref('stg_customers')
                field: customer_id
""")
dbt('dbt build -s +fct_customer_revenue --target prod')

# Step 9: The sales models and their dashboards, before the change
write('models/marts/sales/fct_orders.sql', """\
select order_id, customer_id, amount, status, order_date
from {{ ref('stg_orders') }}
""")
write('models/marts/sales/reports/rpt_daily_orders.sql', """\
select order_date, count(*) as orders, sum(amount) as amount
from {{ ref('fct_orders') }}
group by order_date
""")
write('models/marts/sales/reports/rpt_region_revenue.sql', """\
select c.region, sum(o.amount) as amount
from {{ ref('fct_orders') }} as o
join {{ ref('stg_customers') }} as c using (customer_id)
group by c.region
""")
write('models/exposures.yml', """\
exposures:
  - name: exec_dashboard
    type: dashboard
    depends_on: [ref('fct_daily_revenue')]
    owner: {name: CFO Office, email: cfo-office@example.com}
  - name: revenue_by_region
    type: dashboard
    depends_on: [ref('fct_customer_revenue')]
    owner: {name: Finance Data Team, email: finance-data@example.com}
  - name: sales_dashboard
    type: dashboard
    depends_on: [ref('rpt_daily_orders')]
    owner: {name: Sales Ops, email: sales-ops@example.com}
  - name: regional_sales
    type: dashboard
    depends_on: [ref('rpt_region_revenue')]
    owner: {name: Sales Ops, email: sales-ops@example.com}
  - name: finance_close
    type: analysis
    depends_on: [ref('fct_orders')]
    owner: {name: Finance Data Team, email: finance-data@example.com}
""")
dbt('dbt build -s +fct_orders+ --target prod')

# Step 10: Yesterday's merge: fct_orders joins payments, and the build passes
write('models/marts/sales/fct_orders.sql', """\
-- yesterday's change: show the payment method
select o.order_id, o.customer_id, o.amount, o.status,
       o.order_date, p.method as payment_method
from {{ ref('stg_orders') }} as o
left join {{ ref('stg_payments') }} as p
    on o.order_id = p.order_id
""")
dbt('dbt build -s fct_orders+ --target prod')

# Step 11: Who is affected: the exposures downstream of fct_orders
dbt('dbt ls -s "fct_orders+,resource_type:exposure"')

# Step 12: Roll back: revert the merge and rebuild
write('models/marts/sales/fct_orders.sql', """\
select order_id, customer_id, amount, status, order_date
from {{ ref('stg_orders') }}
""")
dbt('dbt build -s fct_orders+ --target prod')

# Step 13: The process fix: a unique test on the grain; the same change now fails in CI
write('models/marts/sales/_sales.yml', """\
models:
  - name: fct_orders
    columns:
      - name: order_id
        data_tests: [unique, not_null]
""")
write('models/marts/sales/fct_orders.sql', """\
-- yesterday's change: show the payment method
select o.order_id, o.customer_id, o.amount, o.status,
       o.order_date, p.method as payment_method
from {{ ref('stg_orders') }} as o
left join {{ ref('stg_payments') }} as p
    on o.order_id = p.order_id
""")
dbt('dbt build -s @fct_orders --target ci', expect_error=True)   # EXPECTED TO FAIL: the video shows this error

# Step 14: The pull request is closed: main keeps the good model
write('models/marts/sales/fct_orders.sql', """\
select order_id, customer_id, amount, status, order_date
from {{ ref('stg_orders') }}
""")

# Step 15: A normal production build: models and tests in one command
dbt('dbt build --target prod')

# Step 16: The new analyst's first build: their own schema, zero rows
dbt('dbt build -s +fct_customer_revenue --empty')

# Step 17: Every model materialized as a table
dbt('dbt ls -s config.materialized:table --resource-type model')

# Step 18: The fix: an incremental fact, and the report models as views
write('dbt_project.yml', """\
name: shop
version: '1.0'
profile: shop

models:
  shop:
    staging:
      +materialized: view
    marts:
      +materialized: table
      sales:
        reports:
          +materialized: view
""")
write('models/marts/sales/fct_orders.sql', """\
{{ config(materialized='incremental', unique_key='order_id') }}

select order_id, customer_id, amount, status, order_date
from {{ ref('stg_orders') }}
{% if is_incremental() %}
where order_date >= (select max(order_date) from {{ this }})
{% endif %}
""")
dbt('dbt build -s fct_orders+ --target prod')

# Step 19: Domains as groups; marts public; staging protected
write('dbt_project.yml', """\
name: shop
version: '1.0'
profile: shop

models:
  shop:
    staging:
      +materialized: view
    marts:
      +materialized: table
      +access: public
      finance:
        +group: finance
      sales:
        +group: sales
        reports:
          +materialized: view
      marketing:
        +group: marketing
""")
write('models/groups.yml', """\
groups:
  - name: finance
    owner: {name: Finance Data Team, email: finance-data@example.com}
  - name: sales
    owner: {name: Sales Ops, email: sales-ops@example.com}
  - name: marketing
    owner: {name: Marketing Analytics, email: marketing@example.com}
""")
write('models/marts/marketing/mkt_customers_by_region.sql', """\
select region, count(*) as customers
from {{ ref('stg_customers') }}
group by region
""")
dbt('dbt build -s mkt_customers_by_region --target prod')
dbt('dbt ls -s access:public --resource-type model')
That is the whole series

All 10 parts are listed on the Real Time dbt Interview Questions and Answers page on this blog.

The sample data on this page is invented for teaching. Every terminal output is the real output of the dbt command above it, run with dbt v2 (dbt OSS 2.0.8) on DuckDB; run times and node counters are left out, and node lines are listed in DAG order. Part of the Real Time dbt Interview Questions and Answers series on TechBrothersIT. Features, limits and their status (GA or preview) are current as of October 2026; check the official dbt documentation (docs.getdbt.com) for anything you quote in an interview.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.