Star Schema in the Lakehouse: Facts, Dimensions and Grain
Delta tables didn't make dimensional modeling obsolete. Here's how to pick the grain, split facts from dimensions, and build a star schema on Databricks that analysts can trust.
TL;DR
- A star schema is one fact table of measurements surrounded by dimension tables that describe them. It's still the easiest shape for BI tools and humans to query, lakehouse or not.
- Grain comes first. Write one sentence describing what a single fact row means before you write any DDL. Most "wrong numbers" bugs are grain bugs.
- Facts hold numbers you add up plus foreign keys. Dimensions hold the words people filter and group by.
- On Databricks, use informational
PRIMARY KEY/FOREIGN KEYconstraints withRELY, and liquid clustering on the fact table's most-filtered keys. - Medallion and star schema aren't competitors. Bronze and silver are about data arrival; gold is where the star lives.
The problem
NorthBridge Retail Group moved its warehouse to Databricks last year. The migration team did a good job on ingestion: 60 source tables landed cleanly in bronze, got cleaned and typed in silver, and everyone celebrated.
Then the analysts started building dashboards straight off silver.
The weekly revenue report joined nine tables. Two analysts wrote that join slightly differently, and their numbers were 4% apart. A third analyst joined order_header to order_line and summed the header's shipping charge, so every order with five lines got charged shipping five times. Finance stopped trusting any number that came out of the lakehouse.
Nobody had done anything stupid. They just had no agreed model of what a "sale" was. That's the job a star schema does.
Key concepts
| Concept | What it means | Why it matters here |
|---|---|---|
| Fact table | One row per measurement event, holding numeric measures and foreign keys | The table people sum, count and average |
| Dimension table | Descriptive context: product, store, customer, date | What people put in filters, rows and slicers |
| Grain | A plain-language statement of what one fact row represents | Decides which dimensions are allowed and which measures add up safely |
| Degenerate dimension | An identifier kept on the fact with no dimension table, like order_number |
Lets you drill to an order without a pointless one-column dimension |
| Conformed dimension | A dimension shared by several fact tables with the same keys and meaning | Lets you compare sales and inventory by the same product hierarchy |
The fact is narrow and long. Dimensions are wide and short. The grain statement sits on top of everything.
Step-by-step implementation
Kimball's four-step design process still works, and it's quicker than it sounds: pick the business process, declare the grain, choose the dimensions, then identify the facts.
Step 1 — Pick the process and declare the grain
The business process is "customers buy products in stores and online". The grain I'd choose:
One row per product line on a sales receipt, at the moment the receipt is finalised.
That sentence carries a lot of weight. It tells you that order-level values like shipping charge don't belong on this row as-is. It tells you returns are either negative lines or a separate process. It also tells you the lowest level anyone can drill to, which is why you should almost always pick the most atomic grain the source gives you. You can roll up a detailed fact. You can't drill into a summary.
Step 2 — Build the dimensions
-- Databricks Runtime 16.4 LTS, Unity Catalog
CREATE TABLE IF NOT EXISTS northbridge.gold.dim_product (
product_key BIGINT GENERATED BY DEFAULT AS IDENTITY,
product_id STRING NOT NULL, -- natural key from the source
product_name STRING,
brand STRING,
category STRING,
subcategory STRING,
pack_size STRING,
is_private_label BOOLEAN,
CONSTRAINT pk_dim_product PRIMARY KEY (product_key) RELY
);
CREATE TABLE IF NOT EXISTS northbridge.gold.dim_date (
date_key INT NOT NULL, -- 20261113
calendar_date DATE,
day_name STRING,
week_of_year INT,
fiscal_period STRING,
is_weekend BOOLEAN,
is_public_holiday BOOLEAN,
CONSTRAINT pk_dim_date PRIMARY KEY (date_key) RELY
);Notice the dimensions are flat. category and subcategory live on the product row instead of in separate dim_category tables. That's deliberate. Snowflaking saves a few megabytes and costs every analyst an extra join forever. In a columnar store with compression, the repeated category strings cost almost nothing.
The date dimension uses a smart integer key (20261113) rather than an identity. Date is the one dimension where a readable key is fine, because dates never change meaning.
Step 3 — Build the fact table
CREATE TABLE IF NOT EXISTS northbridge.gold.fact_sales (
date_key INT NOT NULL,
store_key BIGINT NOT NULL,
product_key BIGINT NOT NULL,
customer_key BIGINT NOT NULL, -- -1 for anonymous walk-ins
order_number STRING NOT NULL, -- degenerate dimension
line_number INT NOT NULL,
quantity INT,
unit_price DECIMAL(12,2),
discount_amount DECIMAL(12,2),
net_amount DECIMAL(14,2),
cost_amount DECIMAL(14,2),
CONSTRAINT fk_sales_date FOREIGN KEY (date_key) REFERENCES northbridge.gold.dim_date,
CONSTRAINT fk_sales_product FOREIGN KEY (product_key) REFERENCES northbridge.gold.dim_product
)
CLUSTER BY (date_key, store_key);Every column is either a key or a number. No product names, no store regions. If you're tempted to add category to the fact "for convenience", that's a sign you want a gold view or a one-big-table export on top, not a change to the fact.
customer_key is NOT NULL with -1 meaning "unknown customer". Nullable foreign keys make inner joins drop rows silently, which is how revenue disappears from reports without anyone noticing.
The constraints are informational: Databricks doesn't enforce primary or foreign keys. With RELY on the primary key, though, the optimizer is allowed to trust uniqueness and can, for example, eliminate a join to a dimension when the query doesn't select any of its columns. Treat RELY as a promise. If you break it, queries can return wrong results.
Step 4 — Query it the way analysts will
SELECT d.fiscal_period,
p.category,
SUM(f.net_amount) AS revenue,
SUM(f.net_amount - f.cost_amount) AS gross_margin,
COUNT(DISTINCT f.order_number) AS orders
FROM northbridge.gold.fact_sales f
JOIN northbridge.gold.dim_date d ON f.date_key = d.date_key
JOIN northbridge.gold.dim_product p ON f.product_key = p.product_key
WHERE d.calendar_date >= '2026-10-01'
GROUP BY ALL;Every join is fact-to-dimension, one hop. That's the whole point. A business user in a BI tool can build this query by dragging fields, and two people building it will get the same answer.
From production: gotchas and lessons
-
Symptom: Shipping revenue in the star was three times what the finance ledger showed. Cause: Mixed grain. Shipping is charged per order, but it was copied onto every order line. Fix: We allocated shipping across lines by net amount so the line-level grain stayed honest. A separate order-grain fact is the other valid choice. Copying the header value onto lines is never valid.
-
Symptom: A dashboard filter on "Region = South" quietly excluded 12% of online sales. Cause: Online orders had a
NULLstore key, and the BI tool used inner joins. Fix: Added a "Online / Not applicable" row with key-2todim_storeand made fact keysNOT NULL. Every dimension should have explicit "unknown" and "not applicable" members. -
Symptom: The fact table had 14 low-cardinality flag columns (
is_promo,is_click_collect,payment_type…) and kept growing. Cause: Flags with nowhere to live. Fix: A junk dimension holding every combination of flags that actually occurs, with one key on the fact. It went from 14 columns to one, and new flags became a dimension change rather than a fact rewrite. -
Symptom: Engineers kept arguing about whether silver or gold was "the model". Cause: Treating medallion layers as a modeling method. Fix: We wrote it down: silver is cleaned, source-shaped and deduplicated. Gold is business-shaped, and for reporting that means stars. Medallion tells you how mature the data is. It doesn't tell you what shape the data should take.
Performance and cost notes
Cluster the fact table on the keys that appear in most WHERE clauses, usually the date key plus one more. Liquid clustering means you can change those keys later without rewriting your partition layout. Don't partition a fact table by date unless it's well into the terabytes; daily partitions on a 50 GB table give you thousands of tiny files and slower queries.
Most dimensions are small enough to broadcast, so joins are cheap. The thing that gets expensive is a "dimension" with tens of millions of rows, such as customers, joined without a filter. Make sure those queries filter on the fact first.
When not to use this
If one data scientist needs a feature table for one model, build that wide table directly; a star adds nothing for them. Event streams that are only ever queried by time and ID, such as logs and telemetry, are usually better as a single well-clustered table. And if your sources change shape every month and you need a full audit trail of every load, look at Data Vault for the integration layer and keep the star for consumption.
Frequently asked questions
Is a star schema still needed with Databricks and Delta Lake? Compute got cheaper, but people still need one agreed definition of a sale, and BI tools still generate fact-to-dimension SQL best. The star schema solves a meaning problem as much as a performance one.
Star schema or snowflake schema? Default to star. Snowflake only where a hierarchy is shared by several dimensions and changes independently, and even then consider a view.
Where does the star schema sit in medallion architecture? In gold. Bronze and silver feed it.
Checklist
- Grain written as one sentence and agreed with the business owner
- Fact columns are only keys, degenerate IDs and measures
- Every foreign key is
NOT NULL, with unknown and not-applicable members in each dimension - Dimensions are flat unless there's a strong reason to snowflake
-
PRIMARY KEY ... RELYonly where uniqueness is actually guaranteed by the load - Fact table clustered on its most-filtered keys
- A reconciliation query compares gold totals to the source ledger daily
Practice
- Try: Data Modeling Interview Questions: 20 Design Problems
- Build it yourself: take the TPC-H
ordersandlineitemtables from the Databrickssamplescatalog, write a one-sentence grain, and build a four-dimension star. Then deliberately puto_totalpriceon the line-level fact and see how wrongSUMgets.
Further reading
Keep going
Slowly Changing Dimensions: Types 1, 2, 3 and 6 with SQL
One customer moves city. Four SCD types record it four different ways. See the rows each type produces, the SQL that writes them, and how to choose per column.
Fact Table Types: Transaction, Periodic Snapshot and Accumulating
Three fact table types answer three kinds of question: what happened, what's the position, and how far along is it. Build each on Delta Lake, and avoid summing what shouldn't be summed.
Surrogate Keys in a Lakehouse: Identity, Hashes or Sequences
Identity columns, hash keys and ROW_NUMBER sequences all produce surrogate keys on Delta Lake. They differ on concurrency, collisions, reproducibility and join cost. Here's how to choose.
One practical note a week
Get new articles, problems and guides in your inbox.
Thanks! You're on the list. (Local demo — no email provider is wired up yet.)