Skip to main content
Back to Academy⏳ 2. Dimensional Modeling & Relational Integrity
5 min read
Try Hands-on Lab
VISUAL LESSON2. Dimensional Modeling & Relational Integrity

SCD Type 2, Junk and Bridge Dimensions in Practice

Solve two tricky modeling puzzles cleanly: grouping scattered boolean flags into Junk Dimensions, and modeling many-to-many relationships (e.g., user hobbies or multiple promo tags) with Bridge Tables + allocation weights.

Bridge Table Many to Many DimensionJunk Dimension Low Cardinality FlagsSCD Type 2 vs Bridge TableWeighting Factor Bridge TableFlag Explosion Star SchemaMulti-Valued Dimension Modeling

Explain Like I'm New: Light-Switch Panels & Multi-Tag Movies

In real data tables, beginners frequently hit two awkward puzzles that normal dimensions don't solve:

1. Puzzle 1 — 15 Tiny Checkbox Columns (`is_vip`, `likes_rock`, `likes_jazz`, `paperless_bill`, `email_opt_in`): If you keep all 15 boolean flags straight on a 500M-row fact_sales table, your huge Fact gets bloated—yet creating 15 separate tiny 2-row Dimension tables forces 15 ugly joins! Solution — Junk Dimension: Combine low-cardinality flags into 1 compact table holding all valid combinations (flag_sk = 1..N). Like wiring 15 loose wall switches into one tidy breaker panel!

2. Puzzle 2 — Many-to-Many Tags (1 User Has 3 Favorite Genres; 1 Song Has 2 Artists): What if Alice likes *both* Rock AND Jazz, and spends $100 on concert tickets? If you join fact_sales straight to a user_interests table with 2 rows for Alice, `$100` becomes `$200` (Fan-Out Bug!). Solution — Bridge Table: Put an explicit Bridge Table (bridge_user_interest) between User Group and Interest, paired with an optional Weighting Factor (`0.50` / `0.50`) so allocated totals still sum cleanly to $100.00!

Key Beginner Takeaway: Use a Junk Dimension to tidy up loose boolean/status flags on Fact rows, and use a Bridge Table (with Weighting Factors) whenever one entity belongs to *multiple* categories simultaneously without doubling revenue!

Side-by-Side Comparison: Junk Dimension vs. Bridge Table vs. SCD Type 2

PatternProblem SolvedCardinalityKey Columns
SCD Type 2Tracking how 1 attribute changes over time (e.g. moved cities).1-to-Many across timesurrogate_sk, effective_from, effective_to, is_current
Junk DimensionGrouping stray boolean/enum flags off the Fact table.Small finite combinations (2 x 2 x 3 = 12 rows)junk_sk, is_mobile, payment_method, is_gift
Bridge TableConnecting a Fact/Dimension to 0, 1, or N values simultaneously (skills, genres, diagnosis codes).Many-to-Manygroup_sk, category_sk, weighting_factor

Step-by-Step Worked Example 1: Building a Junk Dimension

Suppose fact_orders originally carried 3 small flags: is_gift (Y/N), channel (WEB/APP), priority (STD/EXP). Only 2 x 2 x 2 = 8 total combinations can ever exist!

Instead of 3 columns per billion rows, create `dim_order_flags`:

flags_skis_giftchannelpriority
1falseWEBSTD
2falseAPPSTD
3trueAPPEXP
............

In SQL, generate your Junk Dimension deterministically using DISTINCT or CROSS JOIN + hash surrogate key:

CREATE OR REPLACE TABLE gold.dim_order_flags AS
SELECT
  MD5(CONCAT_WS('|', is_gift, channel, priority)) AS flags_sk,
  is_gift,
  channel,
  priority
FROM silver.raw_orders
GROUP BY is_gift, channel, priority;

Now fact_orders stores just 1 tidy Foreign Key (`flags_sk`) instead of repeating wide strings 500 million times!


Step-by-Step Worked Example 2: Bridge Table With Allocation Weights

Suppose Alice bought `$100` in tickets (user_id = 101), and she follows Rock and Jazz (2 interests -> weighting_factor = 0.50 each):

`bridge_user_interest`

user_group_skinterest_nameweighting_factor
GRP-101Rock0.50
GRP-101Jazz0.50
GRP-202Sports1.00

Watch how weighting factors let BI analysts slice by genre AND guarantee totals reconcile to `$100.00`:

SELECT
  b.interest_name,
  SUM(f.price_paid)                         AS unallocated_impact_usd,
  SUM(f.price_paid * b.weighting_factor)    AS allocated_revenue_usd
FROM gold.fact_sales f
JOIN gold.bridge_user_interest b
  ON f.buyer_interest_group_sk = b.user_group_sk
GROUP BY b.interest_name;

Output: - Rock: unallocated_impact = $100, allocated_revenue = $50 - Jazz: unallocated_impact = $100, allocated_revenue = $50 - Grand Total of `allocated_revenue` = `$50 + $50 = $100.00` (Zero Inflation!)

Both metrics are super valuable—just label clearly whether a KPI measures "Total Reach / Impact" (unweighted) vs. "Reconciled Revenue Share" (weighted)!


Common Beginner Mistakes (And How to Fix Them)

  1. Forgetting to ensure `SUM(weighting_factor) = 1.0` per group: If weights sum to 0.90 or 1.20, financial totals drift! Add a pipeline quality test: GROUP BY user_group_sk HAVING ABS(SUM(weighting_factor) - 1.0) > 0.001.
  2. Putting high-cardinality IDs inside a Junk Dimension: Never mix customer_zip_code (40,000 values) into a Junk Dimension with 5 booleans (40,000 x 32 = 1.28M rows)! Only group truly low-cardinality flags (< 20–100 combinations).
  3. Joining Bridge tables blindly with `INNER JOIN`: Users with 0 listed interests drop completely unless you map them to an "Unspecified / None" group with weight = 1.0 or use LEFT JOIN.

Quick Cheat Sheet

  1. Junk Dimension packs loose low-cardinality boolean/status flags into 1 compact lookup table.
  2. Bridge Table models Many-to-Many traits (interests, tags, co-authors) cleanly.
  3. Always include `weighting_factor` in Bridges when financial totals must still reconcile without double-counting!

Comprehension & Architecture Check (3 Questions)

Test your understanding of the concepts covered in this lesson.

1. How should a sales transaction be attributed to a customer who moved between states?
2. Why should beginners check a table's grain before writing a JOIN?
3. Which Medallion layer is meant to store clean, deduplicated, standardized records?
Practice What You Learned

TICKIT-03: SCD Type 2 Seller Dimension: Historical Sales Attribution

When a ticket seller moves to a new city, their commission rate and state change. If we overwrite their record, historical sales reports will misattribute past sales to the new location. We must apply an SCD Type 2 MERGE in Delta Lake to close out the old record and insert a new active record.

Solve Challenge