dbt project structure - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
We want to understand how the time to run a dbt project grows as the project gets bigger.
How does adding more models or files affect the total execution time?
Analyze the time complexity of this dbt project structure snippet.
models/
├── staging/
│ ├── customers.sql
│ ├── orders.sql
├── marts/
├── sales.sql
├── finance.sql
# dbt runs all models in the project folder structure
# Each model is a SQL file that runs a query
This structure shows how dbt organizes SQL models in folders and runs each model.
Look at what repeats when dbt runs the project.
- Primary operation: Running each SQL model file (query execution)
- How many times: Once per model file in the project
As you add more model files, dbt runs more queries.
| Input Size (number of models) | Approx. Operations (queries run) |
|---|---|
| 10 | 10 |
| 100 | 100 |
| 1000 | 1000 |
Pattern observation: The total work grows directly with the number of models.
Time Complexity: O(n)
This means the total time grows linearly as you add more models to the project.
[X] Wrong: "Adding more folders does not affect run time because folders are just containers."
[OK] Correct: Even if folders organize files, dbt runs every model file inside them, so more files mean more queries and more time.
Understanding how project size affects run time helps you plan and explain dbt workflows clearly in real projects.
"What if we added dependencies between models that require sequential runs? How would that affect the time complexity?"
Practice
Solution
Step 1: Understand folder purposes
Themodels/folder is where SQL files for data transformations live.Step 2: Identify correct folder for SQL models
Other folders likemacros/hold reusable code,snapshots/hold snapshot definitions, andtests/hold test files.Final Answer:
models/ -> Option BQuick Check:
Data transformations = models/ folder [OK]
- Confusing macros/ with models/
- Thinking snapshots/ holds models
- Assuming tests/ contains SQL models
Solution
Step 1: Recall main config file name
The main configuration file for dbt projects is nameddbt_project.yml.Step 2: Verify other options
Other options likedbt_config.ymlordbt_settings.ymlare incorrect names.Final Answer:
dbt_project.yml -> Option AQuick Check:
Main config file = dbt_project.yml [OK]
- Using dbt_config.yml instead
- Confusing with generic project.yaml
- Assuming settings file controls project
my_dbt_project/ ├── models/ │ ├── customers.sql │ └── orders.sql ├── macros/ │ └── date_utils.sql └── dbt_project.yml
Which file would you edit to add a reusable SQL function?
Solution
Step 1: Identify purpose of macros/ folder
Themacros/folder holds reusable SQL functions and macros.Step 2: Locate reusable function file
The filemacros/date_utils.sqlis the right place to add reusable SQL functions.Final Answer:
macros/date_utils.sql -> Option CQuick Check:
Reusable SQL functions = macros/ folder [OK]
- Adding functions inside models/ files
- Editing dbt_project.yml for SQL code
- Confusing macros/ with models/
Compilation Error: Could not find model 'sales_summary'. Which is the most likely cause related to project structure?Solution
Step 1: Understand error meaning
The error means dbt cannot find the model named 'sales_summary'.Step 2: Check model file location
Models must be in themodels/folder. If the file is missing there, dbt can't compile it.Final Answer:
The 'sales_summary.sql' file is missing from the models/ folder. -> Option AQuick Check:
Missing model file in models/ causes compilation error [OK]
- Placing model files in macros/ folder
- Assuming missing dbt_project.yml causes this error
- Confusing snapshots/ with models/
models/. How should you update your dbt_project.yml to reflect this structure?Solution
Step 1: Understand folder-specific config in dbt_project.yml
You can specify configs per subfolder insidemodels/by nesting them under your project name.Step 2: Define separate configs for customers and orders folders
Addingcustomers:andorders:keys with materialization settings applies configs to those subfolders.Final Answer:
Add models: my_dbt_project: customers: +materialized: table orders: +materialized: table -> Option DQuick Check:
Use nested keys in dbt_project.yml for subfolder configs [OK]
- Not nesting configs under project name
- Configuring macros instead of models
- Assuming no config needed for subfolders
