Mesh and Data Collaboration
Mesh Architecture
Data Contract Architecture
Governance Flow
Detailed Explanation
Data mesh is an architectural pattern that decentralized data ownership to domain-specific teams. dbt provides tools to implement data mesh with multi-project architectures, data contracts, and governance features.
What is Domain-Based Organization?
In a data mesh architecture:
- Domain Teams: Own their data products
- Self-Serve Platform: dbt Cloud as the platform
- Data as a Product: Published interfaces
- Federated Governance: Shared standards
What are Cross-Project References?
dbt enables cross-project references for data mesh:
| Reference Type | Syntax | Purpose |
|---|---|---|
| Project references | {{ ref('project', 'model') }} | Reference models in other projects |
| Package references | Shared semantic models | Reuse semantic definitions |
| Metric stores | Centralized metric definitions | Consistent metrics across projects |
What are Data Contracts?
Data contracts define the interface between producers and consumers:
- Schema contracts: Column names, types, constraints
- Freshness contracts: SLA for data availability
- Quality contracts: Acceptable data quality levels
- Cost contracts: Resource usage limits
What are the Governance Features?
- Access Control: RBAC and schema-level permissions
- Data Classification: PII, sensitive, public
- Lineage Tracking: End-to-end data lineage
- Audit Logging: Track all data access and changes
Key Takeaway: Data mesh in dbt enables decentralized data ownership through domain-based organization, cross-project references, data contracts, and governance features.
Code Examples
Cross-Project Reference
-- models/marts/fct_company_metrics.sql
{{
config(
materialized='incremental',
unique_key='company_id'
)
}}
with revenue as (
select * from {{ ref('finance', 'fct_revenue') }}
),
marketing as (
select * from {{ ref('marketing', 'fct_campaigns') }}
),
final as (
select
revenue.company_id,
revenue.company_name,
sum(revenue.amount) as total_revenue,
sum(marketing.spend) as total_marketing_spend,
sum(revenue.amount) - sum(marketing.spend) as profit,
current_timestamp() as updated_at
from revenue
left join marketing on revenue.company_id = marketing.company_id
group by 1, 2
)
select * from final
Data Contract Definition
# contracts/fct_orders_contract.yml
version: 2
contracts:
- name: fct_orders_contract
description: "Data contract for orders fact table"
model: ref('fct_orders')
schema:
columns:
- name: order_id
type: integer
description: "Unique order identifier"
constraints:
- not_null
- unique
- name: customer_id
type: integer
description: "Foreign key to customers"
constraints:
- not_null
- relationships:
to: ref('dim_customers')
field: customer_id
- name: amount
type: decimal(18,2)
description: "Order amount in USD"
constraints:
- not_null
- positive
- name: order_date
type: date
description: "Date order was placed"
constraints:
- not_null
- recent:
period: 30 days
freshness:
max_delay: 4 hours
check_frequency: hourly
alert_on_delay: true
quality:
- type: uniqueness
column: order_id
- type: completeness
columns: [order_id, customer_id, amount, order_date]
- type: consistency
check: "amount > 0"
threshold: 99.9
access:
- team: analytics
permissions: [read]
- team: finance
permissions: [read, write]
- team: data-science
permissions: [read]
Governance Configuration
# governance/access_control.yml
version: 2
access_control:
roles:
- name: data_reader
description: "Read-only access to data"
permissions:
- model:read
- source:read
- metric:read
grant_to:
- team: analytics
- team: business
- name: data_writer
description: "Read and write access to data"
permissions:
- model:read
- model:write
- source:read
- source:write
grant_to:
- team: data-engineering
- name: data_admin
description: "Full access to data platform"
permissions:
- "*"
grant_to:
- team: platform-team
schema_access:
- schema: raw
permissions:
- role: data_writer
access: full
- role: data_reader
access: none
- schema: staging
permissions:
- role: data_writer
access: full
- role: data_reader
access: read
- schema: analytics
permissions:
- role: data_writer
access: full
- role: data_reader
access: read
data_classification:
- level: public
description: "Non-sensitive data"
mask: false
- level: internal
description: "Internal business data"
mask: false
access: [data_reader, data_writer]
- level: confidential
description: "Sensitive business data"
mask: true
access: [data_writer]
masking_policy: "hash"
- level: restricted
description: "PII and regulated data"
mask: true
access: [data_admin]
masking_policy: "full_mask"
Semantic Layer Configuration
# semantic/company_metrics.yml
version: 2
semantic_models:
- name: company_metrics
description: "Unified company metrics"
model: ref('fct_company_metrics')
entities:
- name: company_id
type: primary
expr: company_id
dimensions:
- name: metric_date
type: time
type_params:
time_granularity: day
- name: company_name
type: categorical
expr: company_name
measures:
- name: total_revenue
agg: sum
expr: total_revenue
- name: total_marketing_spend
agg: sum
expr: total_marketing_spend
- name: profit
agg: sum
expr: profit
metrics:
- name: revenue
type: simple
type_params:
measure: total_revenue
- name: marketing_spend
type: simple
type_params:
measure: total_marketing_spend
- name: profit_margin
type: derived
type_params:
expr: "profit / revenue"
exposures:
- name: company_dashboard
type: dashboard
description: "Executive company dashboard"
depends_on:
- ref('fct_company_metrics')
owner:
name: Executive Team
email: exec@company.com
Performance Metrics
| Metric | Description | Target |
|---|---|---|
| Cross-project ref time | Time to resolve cross-project refs | <5s |
| Contract validation | Time to validate contracts | <30s |
| Governance audit | Time to run governance checks | <1min |
| Discovery search | Time to search data catalog | <2s |
| Lineage generation | Time to generate lineage graph | <10s |
Best Practices
- Define clear domain boundaries - Each team owns their data
- Use cross-project refs - Enable data mesh architecture
- Implement data contracts - Define clear interfaces
- Govern access - Use RBAC and schema permissions
- Classify data - Mark PII and sensitive data
- Track lineage - End-to-end data lineage
- Document everything - Clear descriptions and examples
- Monitor usage - Track data access and consumption
See Also
- dbt Cloud â Cloud platform features and job scheduling
- Advanced Jinja â Cross-project reference patterns
- Data Quality Tests â Data contract quality checks
- dbt Best Practices â Governance and documentation patterns
Extended Learning: Beyond the Basics
Key Concepts Summary
This lesson covers fundamental concepts that serve as building blocks for more advanced topics. Master these basics before moving to intermediate and advanced material.
Prerequisite Knowledge
Before studying this topic in depth, ensure you understand:
- Basic definitions and terminology
- Core formulas and their derivations
- Common applications in real-world scenarios
- Typical pitfalls and misconceptions
Step-by-Step Walkthrough
Let us work through a complete example to solidify understanding:
Step 1: Identify the problem type. Determine which category this problem falls into and which approach is most appropriate.
Step 2: Apply the relevant formula. Substitute known values into the appropriate equation, paying attention to units and constraints.
Step 3: Simplify and solve. Work through the algebra step by step, checking each intermediate result.
Step 4: Verify the answer. Check that the solution satisfies the original conditions and makes logical sense.
Common Mistakes to Avoid
- Misidentifying the problem type â Always start by categorizing the problem
- Incorrect formula application â Verify the formula applies to your specific case
- Unit errors â Always check units are consistent throughout
- Sign errors â Pay careful attention to positive and negative values
- Rounding too early â Keep full precision until the final answer
- Forgetting constraints â Check that solutions satisfy all given conditions
Real-World Applications
Understanding this concept is essential for:
- Advanced problem solving in examinations
- Building intuition for more complex topics
- Developing analytical thinking skills
- Applying mathematical reasoning to practical situations
Practice Exercises
- Basic: Solve 5 problems of increasing difficulty using the core concept.
- Intermediate: Apply the concept to word problems with multiple steps.
- Advanced: Combine this concept with 2-3 other topics in a comprehensive problem.
- Challenge: Create your own problem that requires this concept plus additional knowledge.
Interview and Exam Tips
- Common question patterns: Identify which exam or interview formats test this topic
- Time management: Practice completing problems within time constraints
- Common traps: Know the typical mistakes examiners set as distractors
- Verification strategy: Develop a quick method to check your answer
Related Topics
- Previous Topic â Build on the foundation laid here
- Next Topic â See how this concept extends to more advanced material
- Practice Problems â Additional exercises with solutions
- Video Explanation â Visual walkthrough of key concepts
Quick Reference Card
| Concept | Formula/Rule | Key Insight | Common Use |
|---|---|---|---|
| Core Definition | See main text | Understand the intuition | Foundation for all applications |
| Key Formula | See main text | Memorize the derivation | Direct problem solving |
| Special Case | See main text | Recognize when it applies | Simplifies complex problems |
| Edge Case | See main text | Know the limitations | Avoids errors |
Further Reading
For students who want to go deeper:
- Standard textbooks on the subject
- Research papers applying this concept
- Online courses with video explanations
- Practice problem collections with detailed solutions