Star Schema vs Snowflake Schema: Dimensional Modeling Basics for Data Warehouses

Star schema and snowflake schema are two dimensional modeling patterns for data warehouses. An explanation of facts, dimensions, and grain, how the two compare, and when to use each.

A good data warehouse is not just about where data is stored, but also about how it is organized. The right structure makes reports quick to build, easy to understand, and consistent in their numbers. This is where dimensional modeling comes in, with two well-known patterns: star schema and snowflake schema.

This article covers the basics with a simple example, the differences between the two patterns, and when to use each.

Dimensional modeling basics: facts and dimensions

Dimensional modeling was popularized by Ralph Kimball in the book The Data Warehouse Toolkit. The idea is simple: data is split into two kinds.

  • Facts: numeric measurements of a business event, such as the quantity of goods sold, the transaction value, or the service duration. They are stored in a fact table.
  • Dimensions: the context that describes those facts, namely who, what, where, and when. For example customers, products, branches, and dates. They are stored in dimension tables.

Another important concept is the grain, the level of detail of a single row in the fact table. For example, “one row = one item in one transaction”. The grain must be decided before the tables are designed, because it determines which questions the data can answer.

What is a star schema?

In a star schema, one fact table sits in the center surrounded by dimension tables, so the shape resembles a star. Each dimension needs only one table that holds all of its attributes.

An example for sales data: the fakta_penjualan table holds sales quantities and values, and connects to dim_tanggal, dim_produk, dim_pelanggan, and dim_cabang. In the dim_produk table, the product name, category, and brand are stored together in a single table.

What is a snowflake schema?

A snowflake schema is an extension of the star schema. Its dimension tables are split further into several smaller tables following their hierarchy, so the shape branches out like a snowflake.

Using the same example, dim_produk only stores the product name and category code. Category names live in the separate dim_kategori table, and brands in the dim_merek table. The data is no longer repeated, but showing “sales by category” requires more table joins (JOINs).

Star schema

dim_produk: name, category, and brand in one table

  • Fewer tables and JOINs
  • Simpler, faster queries
  • Easy for business users to understand

Snowflake schema

dim_produk → dim_kategori → dim_merek

  • No repeated dimension data
  • Attribute changes happen in one place
  • Queries need more JOINs
The difference lies in how the dimension tables are organized.

Star schema vs snowflake schema compared

Star schemaSnowflake schema
Dimension tablesOne table per dimension (denormalized)Split by hierarchy (normalized)
Number of JOINsFewMore
Ease of understandingHigh, well suited to self-service BIMore complex for business users
Data repetitionSome repetition in dimensionsMinimal repetition
ETL processSimplerMore tables to load

When to use which?

Kimball himself recommends the star schema as the default choice, because its ease of use and query speed are worth more than the space a snowflake saves. Microsoft also recommends a star schema for Power BI data models, since dimension tables are used for filtering and grouping while fact tables are used for summing.

In an era of cheap storage and columnar databases such as ClickHouse, BigQuery, or Snowflake (the cloud platform, not the schema pattern), repeated data in dimensions is hardly a problem anymore. Practical guidelines:

  1. Start with a star schemaThe best choice for almost every reporting and dashboard need.
  2. Snowflake when neededConsider it only for very large dimensions, or for hierarchies that are shared by many dimensions and change often.
  3. Define the grain firstDo this before designing the fact table, to avoid double-counted numbers.
  4. Document the designRecord the list of facts, dimensions, and the definition of every measure, so every team uses the same meaning.

Once the schema is set, the next challenge is keeping the history of changes to dimension data, such as a customer moving to another branch. The technique for handling this is called Slowly Changing Dimension (SCD), for example type 1, which overwrites old data, and type 2, which adds a new row so the history is preserved.

Conclusion

Star schemas and snowflake schemas both use facts and dimensions. The difference is that a star schema keeps each dimension in a single table for simplicity and speed, while a snowflake splits it up to avoid repetition. For most data warehouses and dashboards, the star schema is the best starting point. For the bigger picture, read What Is a Data Warehouse? and What Are Dashboards and Business Intelligence?

Learn to design a data warehouse

Dimensional modeling, star schemas, and SCD are covered in depth with case studies in DNASTUDIO’s Data Warehouse & BI Workshop and our DWH & BI training with Apache Hop and Superset.

Sources

Leave a comment

Your email address will not be published. Required fields are marked *