Data mesh helps teams share and manage data easily across an organization. Using dbt makes building and organizing data models simple and clear.
Data mesh patterns with dbt
model_name.sql -- SQL code for transforming data models/ └─ model_name.sql dbt_project.yml -- Configuration file for dbt project schema.yml -- File to define tests and documentation
dbt uses simple SQL files to build data models step-by-step.
Each model is a SQL file that creates a table or view in your data warehouse.
-- models/orders.sql select * from raw.orders where status = 'completed'
-- models/customers.sql
select id, name, email from raw.customersversion: 2 models: - name: orders description: 'Cleaned orders data' tests: - unique: column_name: id - not_null: column_name: id
This example creates a sales summary model using the orders model. It also adds tests to ensure customer IDs are valid and linked to the customers table.
-- models/sales_summary.sql select customer_id, count(*) as total_orders, sum(amount) as total_amount from {{ ref('orders') }} where order_date >= '2024-01-01' group by customer_id -- schema.yml version: 2 models: - name: sales_summary description: 'Summary of sales by customer' tests: - not_null: column_name: customer_id - relationships: column_name: customer_id to: ref('customers') field: id
Use {{ ref('model_name') }} to link models and build dependencies.
Tests help catch data problems early and keep data reliable.
Organize models by domain to match data mesh ownership.
Data mesh patterns help teams share clean, trusted data.
dbt makes building and testing data models easy with SQL files.
Use refs and tests to connect models and ensure data quality.
Practice
Solution
Step 1: Understand data mesh goals
Data mesh patterns focus on decentralizing data ownership and sharing clean, trusted data across teams.Step 2: Role of dbt in data mesh
dbt helps build and test data models, making data reliable and easy to share.Final Answer:
To enable teams to share clean and trusted data easily -> Option BQuick Check:
Data mesh = share clean data [OK]
- Confusing dbt with dashboard tools
- Thinking data mesh stores raw data only
- Assuming dbt runs Python scripts
Solution
Step 1: Recall dbt ref syntax
dbt uses the Jinja function ref() inside double curly braces to reference models.Step 2: Match syntax with options
SELECT * FROM {{ ref('model_name') }} uses the correct syntax: {{ ref('model_name') }} inside SQL.Final Answer:
SELECT * FROM {{ ref('model_name') }} -> Option CQuick Check:
dbt ref() = {{ ref('model') }} [OK]
- Omitting curly braces around ref()
- Using parentheses after model name
- Using incorrect variable syntax
SELECT user_id, COUNT(*) AS order_count
FROM {{ ref('orders') }}
GROUP BY user_idSolution
Step 1: Analyze SELECT and GROUP BY
The query selects user_id and counts rows grouped by user_id, so output has user_id and order_count.Step 2: Confirm aggregation correctness
GROUP BY user_id matches the aggregation COUNT(*), so query runs correctly and outputs two columns.Final Answer:
user_id and order_count columns with counts per user -> Option DQuick Check:
GROUP BY user_id + COUNT(*) = user_id, order_count [OK]
- Thinking all orders columns appear
- Missing GROUP BY causes error
- Ignoring COUNT(*) aggregation
SELECT * FROM {{ ref('customers') }} WHERE customer_id IS NULL
But it always fails even when nulls exist. What is the likely issue?Solution
Step 1: Understand dbt test logic
dbt tests pass if the query returns zero rows (no errors found).Step 2: Analyze test query behavior
This query returns rows where customer_id is null, so if nulls exist, rows are returned and test fails.Final Answer:
The test should return zero rows to pass, but it returns rows with nulls -> Option AQuick Check:
dbt test passes if zero rows returned [OK]
- Expecting test to pass when rows are returned
- Misusing ref without quotes
- Thinking dbt can't test nulls
Solution
Step 1: Understand data mesh domain ownership
Each domain owns its data models; shared models combine them via references.Step 2: Use dbt refs to combine domain models
dbt's ref() function allows building shared models that depend on domain models cleanly.Step 3: Avoid manual copying or bypassing refs
Manual copying or querying raw tables breaks mesh principles and dbt best practices.Final Answer:
Create a dbt model in a shared repository that references domain models via ref() and applies transformations -> Option AQuick Check:
Shared model + ref() = data mesh best practice [OK]
- Copying data manually outside dbt
- Querying raw tables directly
- Not combining domain data at all
Ready to prove it?
Pass the test and this pattern moves unknown
