dbt Best Practices
Project Structure
Layer Organization (CRITICAL)
- Staging: 1:1 with source tables (
stg_{source}__{entity}) - Intermediate: Business logic composition (
int_{entity}_{verb}) - Marts: Final consumption models (
fct_{entity},dim_{entity})
Materialization Strategy
- Staging:
view(lightweight, always fresh) - Intermediate:
ephemeralorview - Marts:
tableorincremental
Modeling Patterns
Naming Conventions
- Staging:
stg_source__table - Intermediate:
int_entity_verb - Facts:
fct_entity - Dimensions:
dim_entity
Incremental Models
- Use
is_incremental()macro - Define
unique_keyfor merge strategy - Choose strategy: append, merge, delete+insert
Testing
Schema Tests
unique,not_nullfor primary keysrelationshipsfor foreign keysaccepted_valuesfor enums- Custom data tests
Source Freshness
- Configure
loaded_at_field - Set freshness thresholds
Documentation
- Add descriptions to models
- Document column definitions
- Use
docblocks for reusable text - Generate and host dbt docs
References
Converted and distributed by TomeVault — claim your Tome and manage your conversions.