Kahan Data Solutions

YouTube

Data Modeling Crash Course: The 3 Layered Model

2026-11-04 16:45 UTC
Length: 22:35

The video explains a three-layer data modeling approach that starts with a staging layer of one-to-one views, moves to a warehouse layer where star schemas are built, and ends with marts for analytics. It shows how naming conventions, SQL views, and dbt can enforce DRY transformations and make maintenance easier for data teams. The core problem solved is reducing duplicated logic and making future data requests faster by reusing clean, well-organized data structures.

Insights

1. Staging layer as one-to-one views
1.1 Define a staging schema that contains views mirroring each source table exactly, without joins or aggregations.
1.2 Use SQL to create lightweight views that rename columns, cast types, and apply simple formatting.
1.3 Benefits: single source of truth for column logic, easier updates, and no extra storage.
1.4 Tradeoff: All downstream queries must reference the staging view, so changes propagate to every consumer.

2. Naming conventions with STG prefix, source system, and table name
2.1 Prefix view names with STG to signal they are staging objects.
2.2 Include the source system (e.g., CRM, HR) to group related views in the database catalog.
2.3 Append a concise table name to keep identifiers readable and avoid duplication.
2.4 Common mistake: omitting the source prefix leads to confusion when many tables share names.

3. DRY principle in staging
3.1 Centralize all column renames, casts, and simple transformations in the staging layer.
3.2 When the same logic is needed in multiple downstream queries, reference the staging view instead of repeating code.
3.3 Example: change a decimal rounding rule in one place and have it reflected everywhere.
3.4 Pitfall: Overloading staging with heavy logic can slow query performance and make debugging harder.

4. Warehouse layer and star schema design
4.1 Create fact tables that capture business actions (e.g., sales, invoices) with measurable metrics and foreign keys to dimensions.
4.2 Build dimension tables that describe context (e.g., customer, product, location) and use surrogate keys for stable joins.
4.3 Use dbt models in the warehouse directory to materialize these tables as tables or incremental tables.
4.4 Tradeoff: Star schemas simplify reporting but may require more joins and careful key management.

5. Slowly Changing Dimensions (SCD)
5.1 Track attributes that change over time (e.g., employee location) using SCD Type 2 with effective dates.
5.2 Use a surrogate key to maintain historical records and preserve the original natural key.
5.3 When to use: when business reporting needs historical context or audit trails.
5.4 Common mistake: overwriting values instead of versioning, which loses historical insight.

6. Junk dimensions and dimension design
6.1 Combine infrequently used or one-off attributes into a single junk dimension to reduce table count.
6.2 Example: store flags like "is_active" or "has_discount" in a junk dimension linked to a fact table.
6.3 Benefit: keeps fact tables lean and simplifies joins for rare attributes.
6.4 Pitfall: overusing junk dimensions can hide the need for proper dimension modeling and lead to confusion.

Watch on YouTube