Cross-team model sharing in dbt - Time & Space Complexity
When teams share dbt models, it's important to know how the work grows as more models and teams join.
We want to see how the time to build or update models changes with more shared models.
Analyze the time complexity of the following dbt model sharing setup.
-- models/team_a/model_a.sql
select * from source_table
-- models/team_b/model_b.sql
select * from {{ ref('model_a') }}
-- models/team_c/model_c.sql
select * from {{ ref('model_b') }}
This shows three teams sharing models where each model depends on the previous team's model.
Look for repeated steps in building models across teams.
- Primary operation: Running each model's SQL query once per build.
- How many times: Once for each model in the dependency chain.
As the number of shared models grows, the total work grows too.
| Input Size (n models) | Approx. Operations (model runs) |
|---|---|
| 3 | 3 |
| 10 | 10 |
| 100 | 100 |
Pattern observation: The total work grows directly with the number of models shared.
Time Complexity: O(n)
This means the time to build all shared models grows in a straight line as more models are added.
[X] Wrong: "Sharing models means the build time stays the same no matter how many models there are."
[OK] Correct: Each model still needs to run once, so more models mean more total work.
Understanding how shared models affect build time helps you explain teamwork impact on data pipelines clearly and confidently.
What if models were built in parallel instead of one after another? How would the time complexity change?
Practice
ref() in dbt for cross-team model sharing?Solution
Step 1: Understand the purpose of
ref()in dbtref()is used to reference other models, enabling dependency tracking and collaboration.Step 2: Identify the benefit in cross-team sharing
By usingref(), teams avoid duplicating models and keep data consistent across projects.Final Answer:
It connects models from different teams to avoid duplication and ensure consistency. -> Option CQuick Check:
Cross-team sharing =ref()connects models [OK]
ref() links models to share work [OK]- Thinking
ref()creates tables automatically - Believing
ref()removes dependencies - Confusing
ref()with raw SQL execution
sales_summary in dbt?Solution
Step 1: Recall dbt syntax for referencing models
dbt uses Jinja templating with double curly braces andref()to reference models.Step 2: Identify correct syntax
The correct syntax isselect * from {{ ref('model_name') }}to properly resolve the model.Final Answer:
select * from {{ ref('sales_summary') }} -> Option BQuick Check:
Use {{ ref('model') }} for model references [OK]
- Omitting curly braces around ref()
- Using ref() without quotes
- Trying to reference model without ref()
team_a.orders and team_b.customers, what will be the result of this dbt model SQL?select o.order_id, c.customer_name
from {{ ref('orders') }} o
join {{ ref('customers') }} c on o.customer_id = c.customer_idSolution
Step 1: Understand
ref()cross-team referencingref()allows referencing models across teams if they are in the same dbt project or properly configured.Step 2: Analyze the SQL query
The query joins orders and customers oncustomer_id, combining data from both models.Final Answer:
A joined table of orders and customers combining data from both teams. -> Option AQuick Check:
ref() joins models across teams = combined data [OK]
- Assuming ref() cannot cross teams
- Expecting only one model's data returned
- Ignoring join condition effect
select * from {{ ref('team_a.orders') }}But it fails with an error. What is the likely cause?
Solution
Step 1: Check
ref()usage rulesref()accepts only model names without schema or dot notation.Step 2: Identify error cause
Usingteam_a.ordersinsideref()causes syntax error; correct usage is justorders.Final Answer:
You cannot use dot notation insideref(); only model names are allowed. -> Option AQuick Check:
ref() = model name only, no dots [OK]
- Using schema or team prefix inside ref()
- Confusing ref() with source()
- Missing curly braces around ref()
marketing and sales. Marketing built a model campaign_performance. Sales wants to use it in their model sales_analysis. How should sales correctly reference marketing's model in dbt to ensure cross-team sharing?Solution
Step 1: Understand dbt project structure for cross-team models
If both teams' models are in the same dbt project,ref()can reference models across folders or teams by model name.Step 2: Choose correct referencing method
Usingref('campaign_performance')is the correct way to share models and track dependencies.Final Answer:
Useselect * from {{ ref('campaign_performance') }}assuming both models are in the same dbt project. -> Option DQuick Check:
Cross-team sharing = ref() within same project [OK]
- Using raw schema.table without ref()
- Duplicating SQL instead of referencing
- Using source() incorrectly for models
Ready to prove it?
Pass the test and this pattern moves unknown
