0
0
dbtdata~5 mins

Cross-team model sharing in dbt

Choose your learning style9 modes available
Introduction

Sharing models across teams helps everyone use the same data work without repeating effort. It keeps data consistent and saves time.

When multiple teams need to use the same cleaned or transformed data.
When you want to avoid duplicating SQL code in different projects.
When you want to maintain one source of truth for key business metrics.
When teams work on different parts of a data pipeline but depend on shared outputs.
When you want to improve collaboration and reduce errors in data projects.
Syntax
dbt
ref('model_name')

The ref() function tells dbt to use another model's output.

This creates dependencies so dbt knows the order to run models.

Examples
This uses the customers model output in your SQL.
dbt
select * from {{ ref('customers') }}
This aggregates order amounts using the shared orders model.
dbt
select customer_id, sum(amount) from {{ ref('orders') }} group by customer_id
Sample Program

This example shows three models. The customer_orders model uses ref() to share data from customers and orders models. This way, teams can build on each other's work easily.

dbt
-- models/customers.sql
select id as customer_id, name, email from raw.customers

-- models/orders.sql
select id as order_id, customer_id, total_amount from raw.orders

-- models/customer_orders.sql
select c.customer_id, c.name, sum(o.total_amount) as total_spent
from {{ ref('customers') }} c
join {{ ref('orders') }} o on c.customer_id = o.customer_id
group by c.customer_id, c.name
OutputSuccess
Important Notes

Always use ref() to link models instead of hardcoding table names.

dbt builds a dependency graph to run models in the right order automatically.

Cross-team sharing works best when teams agree on model names and data definitions.

Summary

Cross-team model sharing avoids duplicated work and keeps data consistent.

Use ref() in dbt to connect models across teams.

This helps teams collaborate and build reliable data pipelines.