Bird
Raised Fist0
dbtdata~10 mins

Cross-team model sharing in dbt - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Cross-team model sharing
Create model in Team A
↓
Test and document model
↓
Publish model to shared dbt package
↓
Team B adds dependency on shared package
↓
Team B references Team A's model
↓
Run dbt to build combined models
↓
Teams collaborate on improvements
Teams create and test models, publish them as shared packages, then other teams add dependencies and reference these models to build combined data workflows.
Execution Sample
dbt
models/team_a/my_model.sql
-- select statement

models/team_b/analysis.sql
-- select from {{ ref('my_model') }}
Team A creates a model, Team B references it in their own model using dbt's ref function.
Execution Table
StepActionEvaluationResult
1Team A writes my_model.sqlSQL compilesModel my_model created
2Team A runs dbt buildModel builds successfullyTable/view my_model created in warehouse
3Team A packages model in shared dbt packagePackage readyPublished for sharing
4Team B adds dependency on Team A's packageDependency resolvedTeam B can reference my_model
5Team B writes analysis.sql referencing my_modelReference compilesModel analysis ready
6Team B runs dbt buildBuild runsanalysis model created using my_model data
7Teams collaborate on updatesModels updatedImproved shared models
8ExitNo more changesProcess complete
💡 Teams finish sharing and building models; collaboration cycle ends
Variable Tracker
VariableStartAfter Step 2After Step 4After Step 6Final
my_modelNot createdCreated in warehouseAvailable in packageUsed by analysis modelShared and updated
analysis_modelNot createdNot createdNot createdCreated in warehouseBuilt and updated
Key Moments - 3 Insights
How does Team B access Team A's model?
Team B adds Team A's dbt package as a dependency and uses the ref function to reference Team A's model, as shown in execution_table step 4 and 5.
Why is testing and documenting important before sharing?
Testing ensures the model works correctly and documentation helps other teams understand how to use it, preventing errors during referencing (see step 2).
What happens if Team A updates their model?
Teams rerun dbt build to update dependent models, enabling collaboration and continuous improvement (step 7).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step does Team B first use Team A's model?
AStep 3
BStep 4
CStep 5
DStep 6
💡 Hint
Check the 'Action' column where Team B writes analysis.sql referencing my_model (step 5).
According to variable_tracker, what is the state of 'my_model' after Step 4?
AAvailable in package
BCreated in warehouse
CNot created
DUsed by analysis model
💡 Hint
Look at the 'my_model' row under 'After Step 4' column in variable_tracker.
If Team A skips testing before sharing, what step in execution_table might fail?
AStep 4
BStep 2
CStep 5
DStep 7
💡 Hint
Testing happens before or during Step 2 when Team A runs dbt build.
Concept Snapshot
Cross-team model sharing in dbt:
- Team A creates and tests models
- Models are packaged and published
- Team B adds dependency on shared package
- Team B references Team A's models with ref()
- Run dbt build to compile and run combined models
- Teams collaborate to improve shared models
Full Transcript
Cross-team model sharing in dbt involves one team creating and testing data models, then packaging and publishing them as shared dbt packages. Other teams add these packages as dependencies and reference the shared models using dbt's ref function. Running dbt build compiles and runs all models, creating combined data outputs. This process enables teams to collaborate by sharing tested, documented models and improving them together over time.

Practice

(1/5)
1. What is the main benefit of using ref() in dbt for cross-team model sharing?
easy
A. It allows teams to write raw SQL without any dependencies.
B. It automatically creates new tables in the database without configuration.
C. It connects models from different teams to avoid duplication and ensure consistency.
D. It disables model version control to speed up development.

Solution

  1. Step 1: Understand the purpose of ref() in dbt

    ref() is used to reference other models, enabling dependency tracking and collaboration.
  2. Step 2: Identify the benefit in cross-team sharing

    By using ref(), teams avoid duplicating models and keep data consistent across projects.
  3. Final Answer:

    It connects models from different teams to avoid duplication and ensure consistency. -> Option C
  4. Quick Check:

    Cross-team sharing = ref() connects models [OK]
Hint: Remember: ref() links models to share work [OK]
Common Mistakes:
  • Thinking ref() creates tables automatically
  • Believing ref() removes dependencies
  • Confusing ref() with raw SQL execution
2. Which of the following is the correct syntax to reference a model named sales_summary in dbt?
easy
A. select * from ref('sales_summary')
B. select * from {{ ref('sales_summary') }}
C. select * from sales_summary
D. select * from {{ sales_summary }}

Solution

  1. Step 1: Recall dbt syntax for referencing models

    dbt uses Jinja templating with double curly braces and ref() to reference models.
  2. Step 2: Identify correct syntax

    The correct syntax is select * from {{ ref('model_name') }} to properly resolve the model.
  3. Final Answer:

    select * from {{ ref('sales_summary') }} -> Option B
  4. Quick Check:

    Use {{ ref('model') }} for model references [OK]
Hint: Use double curly braces with ref() for model references [OK]
Common Mistakes:
  • Omitting curly braces around ref()
  • Using ref() without quotes
  • Trying to reference model without ref()
3. Given two teams with models 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_id
medium
A. A joined table of orders and customers combining data from both teams.
B. An error because ref() cannot reference models from other teams.
C. A table with only orders data, ignoring customers.
D. A table with only customers data, ignoring orders.

Solution

  1. Step 1: Understand ref() cross-team referencing

    ref() allows referencing models across teams if they are in the same dbt project or properly configured.
  2. Step 2: Analyze the SQL query

    The query joins orders and customers on customer_id, combining data from both models.
  3. Final Answer:

    A joined table of orders and customers combining data from both teams. -> Option A
  4. Quick Check:

    ref() joins models across teams = combined data [OK]
Hint: ref() joins models across teams if configured [OK]
Common Mistakes:
  • Assuming ref() cannot cross teams
  • Expecting only one model's data returned
  • Ignoring join condition effect
4. You wrote this dbt model to share data across teams:
select * from {{ ref('team_a.orders') }}

But it fails with an error. What is the likely cause?
medium
A. You cannot use dot notation inside ref(); only model names are allowed.
B. The model team_a.orders does not exist in the project.
C. You forgot to wrap ref() in double curly braces.
D. You need to use source() instead of ref() for cross-team models.

Solution

  1. Step 1: Check ref() usage rules

    ref() accepts only model names without schema or dot notation.
  2. Step 2: Identify error cause

    Using team_a.orders inside ref() causes syntax error; correct usage is just orders.
  3. Final Answer:

    You cannot use dot notation inside ref(); only model names are allowed. -> Option A
  4. Quick Check:

    ref() = model name only, no dots [OK]
Hint: Use only model names inside ref(), no dots [OK]
Common Mistakes:
  • Using schema or team prefix inside ref()
  • Confusing ref() with source()
  • Missing curly braces around ref()
5. Your company has two teams: 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?
hard
A. Duplicate the campaign_performance SQL in sales_analysis to avoid dependencies.
B. Use select * from marketing.campaign_performance without ref().
C. Use select * from {{ source('marketing', 'campaign_performance') }}.
D. Use select * from {{ ref('campaign_performance') }} assuming both models are in the same dbt project.

Solution

  1. 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.
  2. Step 2: Choose correct referencing method

    Using ref('campaign_performance') is the correct way to share models and track dependencies.
  3. Final Answer:

    Use select * from {{ ref('campaign_performance') }} assuming both models are in the same dbt project. -> Option D
  4. Quick Check:

    Cross-team sharing = ref() within same project [OK]
Hint: Use ref() with model name for cross-team sharing in same project [OK]
Common Mistakes:
  • Using raw schema.table without ref()
  • Duplicating SQL instead of referencing
  • Using source() incorrectly for models
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard