Skip to content

Star Schemas for Analytics and ML

A star schema is an analytical data model with a central fact table for measured events and surrounding dimension tables for descriptive context. It gives BI queries and ML feature pipelines a shared structure: facts provide behavioural signals, dimensions provide labels and attributes, and joins remain explicit and predictable.

Analytical systems usually fail when raw application tables are queried directly. They reflect operational workflows, not business questions: orders are split across normalised tables, customer attributes change, product metadata lives elsewhere, and timestamps have different meanings. BI teams need totals, rates, cohorts, and segments. ML teams need historical signals computed as they would have been known at prediction time. A star schema exists to make those repeated joins and aggregations understandable, reusable, and less fragile.

The concrete design starts with the grain of the fact table: what a row means. It might be an order line, a session, an account-day, or a sensor reading. The fact table stores measures such as revenue or quantity, event timestamps, and foreign keys. Dimension tables store descriptive fields such as customer segment, product category, store region, or campaign. Queries join facts to dimensions, then filter, group, aggregate, or label the result.

The main trade-off is that the model is deliberately shaped for analysis, not for perfect normalisation. Dimension tables may duplicate descriptive values, and historical changes need explicit handling. Slowly changing fields such as plan, address, or risk tier are a common source of wrong answers. For ML, the cost is stricter discipline: joins and aggregations must respect time, otherwise features quietly include information from the future.

Engineers meet star schemas in warehouses, marts, semantic layers, dashboard models, and feature generation jobs. They show up as fact_orders joined to dim_customer, dim_product, dim_date, and similar tables. A common misunderstanding is that a star schema is only for reporting. In practice, the same structure is often the cleanest input to batch feature pipelines because it separates events, context, timestamps, and aggregation logic.

Common questions

How is a star schema different from a snowflake schema?
In a star schema, dimensions are usually kept wide and directly joined to the fact table. In a snowflake schema, dimensions are further normalised into related sub-dimensions, such as product joined to category joined to department. Snowflaking can reduce duplication, but star schemas are often simpler for analysts, query builders, and feature jobs.
What is the most important design decision?
The grain of the fact table is the decision that controls everything else. If a fact row represents an order, the measures and joins differ from a row representing an order line or an account-day. An unclear grain leads to double counting, awkward joins, and features whose meaning changes depending on the query.
Why does this matter for machine learning?
ML features are usually aggregates over past behaviour plus contextual attributes. A star schema gives those inputs a stable layout: timestamped facts for counts, sums, recency, and frequency, and dimensions for relatively stable context. It also makes leakage easier to spot, because feature code must join to the version of data valid before the prediction time.
Should dimensions contain the latest value or historical values?
It depends on the question. For current-state reporting, the latest customer or product attributes may be acceptable. For historical reporting and ML training, you often need the value that was true when the event happened or when the prediction was made. Otherwise old events can be reinterpreted using information that was not available then.