Interview's MateData Engineer
Interview's Mate

Data Engineer

SQL · Spark · Lakehouse · Streaming

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Engineer topics
Lesson 103/ 160
06. Data Transformation (dbt) & Workflow Orchestration

dbt Project Structure (models, seeds, snapshots, macros, tests)

Organize models, seeds, snapshots, macros, and tests so projects stay navigable as they grow.

Beginnermodels · macros · tests3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Source-aligned types and names. Next, intermediate business logic with explicit refs. Finally, tests, macros, seeds, snapshots, docs, and ownership.

Think of it like…

Project structure is a warehouse zoning plan: receiving docks, preparation rooms, reusable tools, audited history, and shipping-floor models should not all be piled in one room.

Where you’ve seen it

models/staging/stripe/stg_payments.sql renames source columns; models/marts/fct_revenue.sql joins trusted refs and exposes one order-line grain; schema.yml declares relationships, not only descriptions.

Words you’ll hear

models
SQL/Jinja files materialized by dbt through a compiled dependency graph.
macros
Reusable Jinja functions that generate SQL with controlled parameters and are reviewed through compiled output.
tests
Assertions on models/sources, including generic YAML expectations and custom SQL/query checks.
Operational boundary
Models that jump from source to a complex mart couple business rules, duplicate tests, and hide circular selection, while oversized seeds quietly become an inappropriate production loader. Use shallow staging renames/type casts, focused intermediate joins, grain-explicit marts, YAML near the owned model, and packages/macros only when reuse has a stable interface.

Visual diagram

Loading interactive diagram

Theory & deep dive

models: the working mechanism

A dbt project separates reusable macros, seeds, source definitions, staging/intermediate/mart models, snapshots, and schema tests so dependency direction and ownership remain legible.

Source-aligned types and names. Intermediate business logic with explicit refs, then grain-owned mart or semantic model; this exposes the state governed by tests.

dbt Project Structure in one concrete design

models/staging/stripe/stg_payments.sql renames source columns; models/marts/fct_revenue.sql joins trusted refs and exposes one order-line grain; schema.yml declares relationships, not only descriptions.

Key takeaway: A dbt project separates reusable macros, seeds, source definitions, staging/intermediate/mart models, snapshots, and schema tests so dependency direction and ownership remain legible

dbt Project Structure: failure mode and production response

Models that jump from source to a complex mart couple business rules, duplicate tests, and hide circular selection, while oversized seeds quietly become an inappropriate production loader.

Use shallow staging renames/type casts, focused intermediate joins, grain-explicit marts, YAML near the owned model, and packages/macros only when reuse has a stable interface. Track Directory ownership as "folder maps to domain and layer", and make Model grain visible to the dataset owner.

Key takeaway: Use shallow staging renames/type casts, focused intermediate joins, grain-explicit marts, YAML near the owned model, and packages/macros only when reuse has a stable interface.

How it works, step by step

Step 1 of 4
models

1. Stage

Source-aligned types and names. A dbt project separates reusable macros, seeds, source definitions, staging/intermediate/mart models, snapshots, and schema tests so dependency direction and ownership remain legible.

source-aligned types and names
Key numbers at this step
Directory ownership
folder maps to domain and layer
macros
Reusable Jinja functions that generate SQL with controlled parameters and are reviewed through compiled output.

When to use it & trade-offs

What it is

A dbt project separates reusable macros, seeds, source definitions, staging/intermediate/mart models, snapshots, and schema tests so dependency direction and ownership remain legible. models/staging/stripe/stg_payments.sql renames source columns; models/marts/fct_revenue.sql joins trusted refs and exposes one order-line grain; schema.yml declares relationships, not only descriptions.

Why it matters: Models that jump from source to a complex mart couple business rules, duplicate tests, and hide circular selection, while oversized seeds quietly become an inappropriate production loader. Use shallow staging renames/type casts, focused intermediate joins, grain-explicit marts, YAML near the owned model, and packages/macros only when reuse has a stable interface.

When to reach for it

  • Organize models, seeds, snapshots, macros, and tests so projects stay navigable as they grow.
  • Choose models because it provides this capability: SQL/Jinja files materialized by dbt through a compiled dependency graph.
  • Keep evidence for Directory ownership at "folder maps to domain and layer" so the last production stage-Support - tests, macros, seeds, snapshots, docs, and ownership-remains testable.

When to avoid or be careful

  • Models that jump from source to a complex mart couple business rules, duplicate tests, and hide circular selection, while oversized seeds quietly become an inappropriate production loader.
  • Do not conflate macros with models. The second concept contributes different behavior: Reusable Jinja functions that generate SQL with controlled parameters and are reviewed through compiled output.
  • Release only after this guardrail is in place: Use shallow staging renames/type casts, focused intermediate joins, grain-explicit marts, YAML near the owned model, and packages/macros only when reuse has a stable interface.

models / macros / tests - roles, limits, and operating cost

models
Best for: SQL/Jinja files materialized by dbt through a compiled dependency graph.

Strengths: SQL/Jinja files materialized by dbt through a compiled dependency graph. A dbt project separates reusable macros, seeds, source definitions, staging/intermediate/mart models, snapshots, and schema tests so dependency direction and ownership remain legible.

Watch out: Models that jump from source to a complex mart couple business rules, duplicate tests, and hide circular selection, while oversized seeds quietly become an inappropriate production loader.

macros
Best for: Reusable Jinja functions that generate SQL with controlled parameters and are reviewed through compiled output.

Strengths: Reusable Jinja functions that generate SQL with controlled parameters and are reviewed through compiled output. In this workflow it supports: Publish - grain-owned mart or semantic model.

Watch out: The operating cost is real: one sentence per mart model.

tests
Best for: Assertions on models/sources, including generic YAML expectations and custom SQL/query checks.

Strengths: Assertions on models/sources, including generic YAML expectations and custom SQL/query checks. Its output can be checked with Seed size.

Watch out: Operating guardrail: Use shallow staging renames/type casts, focused intermediate joins, grain-explicit marts, YAML near the owned model, and packages/macros only when reuse has a stable interface.

Interview signals & numbers to know

When this topic comes up

  • “Where is the failure boundary for models, and how would Directory ownership reveal it?”
  • “Why is macros distinct from this behavior: assertions on models/sources, including generic YAML expectations and custom SQL/query checks?”
  • Production clue: Models that jump from source to a complex mart couple business rules, duplicate tests, and hide circular selection, while oversized seeds quietly become an inappropriate production loader.
  • Design probe: Use shallow staging renames/type casts, focused intermediate joins, grain-explicit marts, YAML near the owned model, and packages/macros only when reuse has a stable interface.

Benchmarks & rules of thumb

Directory ownership -
folder maps to domain and layer
Model grain -
one sentence per mart model
Seed size -
small static reference only, not application data extract

Common mistakes & follow-ups

Common interview mistakes

  • Models that jump from source to a complex mart couple business rules, duplicate tests, and hide circular selection, while oversized seeds quietly become an inappropriate production loader.
  • Reporting success from a job exit code without checking Directory ownership and Model grain.
  • Treating this example as complete without replay, rollback, or access boundaries: models/staging/stripe/stg_payments.sql renames source columns; models/marts/fct_revenue.sql joins trusted refs and exposes one order-line grain; schema.yml declares relationships, not only descriptions.

Likely interviewer follow-ups

  • How would you prove this contract instead of only checking that the command ran: SQL/Jinja files materialized by dbt through a compiled dependency graph.
  • What does the recovery plan do when this occurs? Models that jump from source to a complex mart couple business rules, duplicate tests, and hide circular selection, while oversized seeds quietly become an inappropriate production loader.
  • When is models insufficient for Model grain, and what does adding macros cost in Directory ownership?
Interview tip: Lead with the data path and failure boundary: A dbt project separates reusable macros, seeds, source definitions, staging/intermediate/mart models, snapshots, and schema tests so dependency direction and ownership remain legible. Then make the answer operational: Use shallow staging renames/type casts, focused intermediate joins, grain-explicit marts, YAML near the owned model, and packages/macros only when reuse has a stable interface.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply dbt Project Structure (models, seeds, snapshots, macros, tests) with data engineer interview Q&A and hands-on practice.

Open Data Engineer Q&A →Machine Learning Q&A
Previous topic
Introduction to dbt (Data Build Tool) & Analytics Engineering Workflow
Next topic
Materializations (view, table, incremental, ephemeral)