DWH Modelling in Depth
Factless and coverage facts, role-playing, degenerate and junk dimensions, conformed dimensions, late-arriving dimension rows, SCD2 history that lies, one big table versus a star, a marketplace warehouse, and Anchor Modeling.
8 questions
JuniorTheoryCommonTwo marts, two customer tables — why does return rate by segment break?
Two marts, two customer tables — why does return rate by segment break?
Each table has its own keys and segment rules, so one segment means different customers in each mart and the ratio mixes them. Build one conformed customer dimension, whose surrogate key maps both source ids, for both facts.
Common mistakes
- ✗Matching customers across marts on name or email at query time
- ✗Believing two fact tables cannot appear in one report, when conformed dimensions make drill-across work
- ✗Assuming source systems share a natural key, when the support system has its own customer ids
Follow-up questions
- →How does a Kimball bus matrix show which dimensions sales, returns and inventory must share?
- →How do you compute return rate by segment across the two facts without joining them row to row?
JuniorTheoryCommonHow do you model two dates, an order number and ten flags on an order fact?
How do you model two dates, an order number and ten flags on an order fact?
Both dates point to one date dimension through two keys and two views — a role-playing dimension, not two copies. The order number stays on the fact with no table of its own. The ten flags go into one junk dimension of combinations that occur.
Common mistakes
- ✗Copying the date dimension per role, so the copies drift apart
- ✗Creating a one-column order dimension that adds a join and no attributes
- ✗Putting a high-cardinality id into a junk dimension, which then grows a row per order
Follow-up questions
- →When does a frequently changing customer attribute, such as an age band, call for a mini-dimension?
- →Why does each role-playing view need its own column names?
JuniorTheoryOccasionalWhich promoted products sold nothing — why can't a sales fact alone answer it?
Which promoted products sold nothing — why can't a sales fact alone answer it?
A sales fact has rows only for sales, so a product that sold nothing leaves no row to find. Add a factless coverage fact — one row per product, store and day on promotion, with no measures — and subtract the sales rows from it.
Common mistakes
- ✗Expecting a transaction fact to hold zero rows for events that did not happen
- ✗Modelling promotion as a product attribute when it varies by store and day
- ✗Building the factless table from the sales themselves instead of from everything that could have sold
Follow-up questions
- →How would you model student attendance as a factless fact, and what does
COUNT(*)mean there? - →Why must the coverage fact hold a row for every promoted product, store and day?
MiddleDesignOccasionalOrders load into fct_orders every 15 minutes, but the CRM customer extract lands once a night, so about 3% of orders reference a customer_id that dim_customer does not have yet — mostly same-day sign-ups. Today the load maps them to the shared −1 «Unknown» row. Finance sees «Unknown» revenue grow every month while new-customer revenue looks too low, and nobody ever moves those orders to the real customer. dim_customer has a warehouse surrogate key and keeps SCD Type 2 history on segment. Constraints: today's revenue must stay complete; once the CRM row arrives, those orders must show under the right customer without reloading or updating the fact table; the order load must never wait for the CRM. Design how the load handles a fact whose dimension row has not arrived yet, and what happens when it does.
Orders load into fct_orders every 15 minutes, but the CRM customer extract lands once a night, so about 3% of orders reference a customer_id that dim_customer does not have yet — mostly same-day sign-ups. Today the load maps them to the shared −1 «Unknown» row. Finance sees «Unknown» revenue grow every month while new-customer revenue looks too low, and nobody ever moves those orders to the real customer. dim_customer has a warehouse surrogate key and keeps SCD Type 2 history on segment. Constraints: today's revenue must stay complete; once the CRM row arrives, those orders must show under the right customer without reloading or updating the fact table; the order load must never wait for the CRM. Design how the load handles a fact whose dimension row has not arrived yet, and what happens when it does.
Insert an inferred member — a dimension row with the natural key, a new surrogate key, unknown attributes and a flag — and load the facts with its key. When the CRM row arrives, overwrite it in place (Type 1); the facts stay as they are.
Common mistakes
- ✗Sending unmatched facts to one shared Unknown row, which carries no natural key and can only be fixed by updating the fact
- ✗Quarantining facts until the dimension arrives, so today's totals are silently incomplete
- ✗Versioning the placeholder as SCD2 when the real row arrives, leaving the loaded facts on unknown attributes
Follow-up questions
- →The CRM row arrives with a segment that changed twice since sign-up — which version do the early orders get?
- →How do you alert on inferred rows that are still unresolved after a week?
MiddleDesignOccasionalDesign the dimensional core of a marketplace warehouse. One cart holds items from several sellers, and each seller ships its part separately. A buyer can return single items weeks later. The commission rate depends on the seller's tier, which changes a few times a year, and the platform recategorises products now and then. Finance needs GMV, commission and return rate by seller, category and month, with commission at the rate valid on the order date and each sale under the category its product had on that date; it also needs each seller's balance owed at month end. Constraints: return rate must be computable for any seller and category; a past month's commission must not change when a seller's tier changes; one seller and one product must mean the same thing in every report. Name the fact tables and the grain of each, the dimensions they share, and which dimension attributes need history.
Design the dimensional core of a marketplace warehouse. One cart holds items from several sellers, and each seller ships its part separately. A buyer can return single items weeks later. The commission rate depends on the seller's tier, which changes a few times a year, and the platform recategorises products now and then. Finance needs GMV, commission and return rate by seller, category and month, with commission at the rate valid on the order date and each sale under the category its product had on that date; it also needs each seller's balance owed at month end. Constraints: return rate must be computable for any seller and category; a past month's commission must not change when a seller's tier changes; one seller and one product must mean the same thing in every report. Name the fact tables and the grain of each, the dimensions they share, and which dimension attributes need history.
Facts: order line (an item in one seller's part of a cart), return line (a returned item keyed to its line), seller balance snapshot (seller per day). Seller, product, customer and date are shared. Seller tier and category are SCD2.
Common mistakes
- ✗Modelling the cart as the grain, which hides which seller sold which item
- ✗Writing returns back into the order line, which loses the return date and makes return rate unrecoverable
- ✗Summing a daily balance snapshot across days instead of taking the month-end row
Follow-up questions
- →Would you store the commission amount on the order line at load or derive it from the tier version at query time?
- →How does a shipment fact fit in when one seller ships its part in several parcels?
MiddleDesignOccasionalA sales dashboard runs on a columnar cloud warehouse (BigQuery or Snowflake) over a 2-billion-row fact joined to five dimensions, and its slowest tiles take 20 seconds. An analyst proposes replacing the star with one wide pre-joined table, one big table (OBT), for everything. Facts: customer segment is SCD Type 2 and reports must show the segment as it was at the sale; product categories are renamed a few times a year, and a rename must reach every report the same day; three other marts use the same customer and product dimensions; storage cost is not a concern. Constraints: the dashboard must get faster; no report may show a different category name or customer count for the same thing; a rename must not mean hand-editing several tables. Decide what to build, why the flat table is faster, and what it costs.
A sales dashboard runs on a columnar cloud warehouse (BigQuery or Snowflake) over a 2-billion-row fact joined to five dimensions, and its slowest tiles take 20 seconds. An analyst proposes replacing the star with one wide pre-joined table, one big table (OBT), for everything. Facts: customer segment is SCD Type 2 and reports must show the segment as it was at the sale; product categories are renamed a few times a year, and a rename must reach every report the same day; three other marts use the same customer and product dimensions; storage cost is not a concern. Constraints: the dashboard must get faster; no report may show a different category name or customer count for the same thing; a rename must not mean hand-editing several tables. Decide what to build, why the flat table is faster, and what it costs.
Keep the star as the source of truth and build an OBT from it for the slow dashboard. A flat columnar table reads without joins and its repeated values compress, but a rename rewrites every OBT row that carries it, and marts copying dimension values drift.
Common mistakes
- ✗Making the OBT the only model, so every mart copies dimension values and they drift apart after a rename
- ✗Believing a columnar engine reads all columns of a wide table, when it reads only the selected ones
- ✗Rejoining the OBT to current dimension rows, which replaces the segment at the sale with today's segment
Follow-up questions
- →How do you rebuild the OBT cheaply after a category rename — full rewrite, or only the affected partitions?
- →When would a materialized view over the star beat a separate OBT?
SeniorDebuggingOccasionalA slowly-changing-dimension SCD2 load doubles revenue and misdates changes — debug it
A slowly-changing-dimension SCD2 load doubles revenue and misdates changes — debug it
Duplicate staging rows create two current versions, versions start on the load date, not the CRM change date, and BETWEEN matches two versions on the change day. Dedupe per key, date by the source, use half-open ranges, test overlaps.
Common mistakes
- ✗Feeding every delivery in staging to the load, so a redelivered or superseded row becomes a fake version
- ✗Starting versions on the load date, so any delay in the pipeline shifts history and misattributes orders
- ✗Joining facts with an inclusive
BETWEENon a closed-equals-next-start interval, so the change day matches two versions
Follow-up questions
- →The CRM back-dates a change to before the current version started — what do you rewrite, and which facts are restated?
- →How do you repair the 1,214 customers that already have two current rows, and their fact rows?
SeniorTheoryRareHow does the 6NF method Anchor Modeling differ from Data Vault, and what do its joins cost?
How does the 6NF method Anchor Modeling differ from Data Vault, and what do its joins cost?
An anchor holds only a surrogate id; each attribute is its own table, historized if it changes; ties link anchors; knots hold value sets. Changes only add tables, finer than Data Vault satellites. Each attribute costs a join, eased by join elimination in views.
Common mistakes
- ✗Equating an anchor with a Data Vault hub, when the anchor carries no business key and the natural key is just another attribute
- ✗Assuming a query pays for every attribute table, when join elimination drops the unused ones from the view
- ✗Treating a new attribute as an
ALTER TABLE, when it is a new table and old queries stay untouched
Follow-up questions
- →Under which conditions does PostgreSQL remove a
LEFT JOINfrom a plan, and why does an inner join to the same table stay? - →Why can a knot not keep history, and when would you use one instead of an attribute?