Analytical Data Modeling

Facts, dimensions, grain and history. The model decides which business questions are easy, which are expensive, and which are answerable but silently wrong.

Analytical Data Modeling
▶ lab

Choosing the shape of the tables people query, so that the questions the business asks are easy to write, correct by construction and affordable to run.

Q · What shape should the tables a consumer queries have, so that the questions the business actually asks are easy, correct and cheap to answer?
Operational vs Analytical Models
▶ lab

Normalised, transaction-oriented schemas and fact/dimension, query-oriented schemas solve different problems. Neither is a degraded version of the other.

Q · Why is the schema that is correct for an application the wrong one for analytics, and what exactly changes between them?
Fact Tables
▶ lab

Tables of measurements of a business process, at a declared grain, with keys to context — and the measure types that decide whether SUM() means anything.

Q · What belongs in a fact table, at what grain, and which of its columns are safe to add up?
Grain: What Does One Row Represent?
▶ lab

The single most important question in analytical modelling. Answer it in one sentence per table, or every aggregate downstream is a guess.

Q · What does exactly one row of this table represent, and what happens to every metric if two people answer that differently?
Dimension Tables
▶ lab

The descriptive context you filter and group by — customer, product, date, region — and the reason a calendar deserves a table of its own.

Q · Where should the attributes people filter and group by live, and why not simply on the fact table?
Surrogate Keys
▶ lab

A warehouse-generated key with no business meaning, because with history the natural key stops being unique and because source ids change underneath you.

Q · Why should a fact join to a warehouse-generated key rather than to the identifier the source system already provides?
Star Schema
▶ lab

One fact table in the middle, dimensions one join away on every side. The shape that makes queries short, joins predictable and grain visible.

Q · Why is a central fact table surrounded by single-join dimensions the dominant analytical shape, and when is it the wrong one?
Snowflake Schema
▶ lab

Dimensions normalised into their own hierarchies. Fewer repeated values, one place to correct a taxonomy, more joins in every query — and an honest comparison of when that trade pays.

Q · When is it worth normalising a dimension into a hierarchy instead of flattening it into the dimension table?
Slowly Changing Dimensions
▶ lab

A customer moves from Poland to Germany. Do last quarter's Polish revenue figures change? That question, answered per attribute, is the whole topic.

Q · When a descriptive attribute changes, should history be restated to the new value or preserved as it was?
SCD Type 2 in Practice
▶ lab

valid_from, valid_to, is_current — the columns that preserve history, the join predicate every fact must use, and the interval bugs that produce numbers reconciling against nothing.

Q · How do you store every version of a dimension attribute, and how does a fact pick the one version that was true when it happened?
Snapshot Tables
▶ lab

Capture the state of every entity at the end of every period. `account_balance_daily` answers "what was it on the 14th" with a lookup instead of a fold over all history.

Q · How do you answer "what was the state of everything on a given date" without replaying every change that ever happened?
Event vs Snapshot Modeling
▶ lab

Events record what changed; snapshots record what was true at time T. Different storage curves, different query complexity, and different questions made easy.

Q · Should this be modelled as a stream of changes or as periodic captures of state, and which questions does each choice make hard?