Hello! Welcome back to our module on Modern Cloud Data Warehousing.
In our last lesson, we established a framework for deciding when to use a cloud data warehouse (CDW) versus a data lakehouse. We concluded that CDWs are the optimal choice for powering business intelligence and reporting on structured data, where query performance and ease of use are paramount.
Today, we move from the "why" to the "how." The performance and clarity of a CDW depend on a robust data model. Your learning outcome for this lesson is to implement a star schema in a cloud data warehouse platform. This is the most common and effective data modeling technique for analytical workloads. Given your background with relational databases, you can think of this as a specialized application of relational principles, optimized for analysis (OLAP) rather than transactions (OLTP).
1. What is a Star Schema?
At its core, a star schema organizes data into two types of tables: a central fact table and several surrounding dimension tables.
- Fact Table: Contains quantitative data (the "facts" or "measures") about business events, like
sales_amountorquantity_sold. It also contains foreign keys that link to the dimension tables. The fact table is typically long and narrow. - Dimension Tables: Contain descriptive attributes that provide context to the facts, such as
product_name,customer_address, orstore_region. These tables answer the "who, what, where, when, why" questions about the events in the fact table. Dimension tables are typically wide and shallow.
This structure gets its name because a diagram of the model, with the fact table at the center and dimensions radiating outwards, resembles a star.

To solidify this concept, let's read a quick and clear definition.
Implementing Star Schema on BigQuery
The article 'Implementing Star Schema on BigQuery' provides an excellent, concise introduction to the concept. Let's read the first section.
Please read the introductory text, stopping at the section 'Why implement a Star Schema?'. Focus on the definitions of Fact Table, Dimension Tables, and Foreign Keys.
2. A Practical Implementation Pattern
Now, let's move from theory to a concrete implementation. We will study a detailed walkthrough that builds a star schema in Snowflake, a popular cloud data warehouse. This example uses dbt (data build tool), which is a common tool for orchestrating data transformations.
While we won't be setting up the full environment today, studying this example is invaluable as it demonstrates a modern, best-practice architectural pattern for building data models: the Staging -> Marts approach.
- Staging Layer: Raw source data is first loaded into staging tables. This layer is for light, essential transformations: renaming columns for clarity, casting data types, and standardizing values. Crucially, no joins happen here. Each staging table corresponds 1-to-1 with a source table.
- Marts Layer: This is where the star schema is constructed. Dimension and fact tables are built by joining and aggregating data from the staging tables. These are the final, cleaned, user-facing tables that BI tools will connect to.
Let's begin by understanding the source data and the target schema we aim to build.
Designing a Simple Star Schema in Snowflake with dbt ...
The article 'Designing a Simple Star Schema in Snowflake with dbt' uses sample retail data. Let's look at the project overview.
Read the section 'Step 5— Source or Raw data', focusing on the 'Project Overview' which lists the source tables and the target dimension and fact tables.
Step 1: Building the Staging Layer
With the goal in mind, the first step is to create the staging models. Notice how the SQL for each staging model selects from a single source, performs renaming and light transformations (like case statements for categorization), but does not join to other tables.
Designing a Simple Star Schema in Snowflake with dbt ...
Let's examine the SQL used to create the staging models.
Read through 'Step 7— Create a Staging Models'. Review the SQL for stg_tpch_customers.sql, stg_tpch_orders.sql, stg_tpch_lineitems.sql, and stg_tpch_parts.sql. Pay attention to the types of transformations being done: renaming (c_custkey to customer_key), casting (::number), and deriving new columns (case statements).
Step 2: Building the Marts Layer (The Star Schema)
Once we have clean, consistent staging tables, we can build our star schema.
Dimension Tables
The dimension tables are typically created first. They are often simple SELECT statements from their corresponding staging table, selecting the descriptive columns.
Fact Table
The fact table is the centerpiece. It is constructed by joining multiple staging tables. It selects the foreign keys from the relevant dimensions and calculates the numeric measures, often involving aggregations like SUM or COUNT.
Designing a Simple Star Schema in Snowflake with dbt ...
Now for the final step: constructing the dimension and fact tables from our staging models.
Read 'Step 9— Build Dimension Tables', reviewing the SQL for dim_customer.sql and dim_product.sql. Then, carefully study the SQL for fct_orders.sql. Notice how it joins stg_tpch_orders with an aggregated summary of stg_tpch_lineitems to create the final facts.
You have now walked through the code for a complete star schema implementation. The dim_customer and dim_product tables provide the context, while fct_orders provides the numeric, measurable events. An analyst could now connect a BI tool to these three tables and start building reports.
Test your understanding!
Based on the SQL code you just reviewed in the fct_orders.sql model:
- Identify one measure (a quantitative value).
- Identify two foreign keys that link to dimension tables.
- Looking at the
dim_product.sqlmodel, identify two descriptive attributes that provide context for a product.
Show answer
- Measures in
fct_ordersincludeline_item_count,total_quantity,total_discounted_sales, andtotal_final_sales. - Foreign keys in
fct_ordersincludecustomer_key(links todim_customer) andorder_key(which is the primary key of this fact table). Althoughproduct_keyis not directly in the finalfct_ordersmodel in this specific example (it's abstracted away in thelineitemsaggregation), in a more granular fact table,product_keywould be the foreign key linking todim_product. - Descriptive attributes in
dim_productincludeproduct_name,manufacturer,brand,product_category, andprice_tier.
3. The Pattern is Universal
The Staging -> Marts pattern and the star schema model are not specific to Snowflake or dbt. They are universal data warehousing principles. To illustrate this, let's briefly look at an implementation using only standard SQL in Google BigQuery.
Implementing Star Schema on BigQuery
The BigQuery article we saw earlier also provides SQL snippets for creating fact and dimension tables. Let's see how similar the logic is.
Scan through the SQL code blocks under 'Fact Table' and 'Dimension Tables'. You don't need to analyze it deeply; just observe that the pattern is the same: creating a fact table with measures and dimension tables with attributes.
As you can see, regardless of the platform, the core logic remains consistent: you define tables that hold either descriptive context (dimensions) or quantitative measures (facts).
Conclusion
In this lesson, we moved from the theory of dimensional modeling to the practical steps of implementing a star schema in a modern cloud data warehouse.
Key Takeaways:
- A star schema consists of a central fact table (with numeric measures and foreign keys) and surrounding dimension tables (with descriptive attributes).
- This model is the foundation of analytical data warehousing because it is simple for users to understand and is highly optimized for the types of queries used in BI and reporting.
- A common and robust implementation pattern is the Staging -> Marts architecture. Raw data is cleaned in a staging layer before being joined and aggregated into the final star schema in the marts layer.
- This pattern is a universal principle of data architecture, applicable across different cloud data warehouse platforms like Snowflake, BigQuery, and Redshift.
We have now designed and logically implemented the structure for our data. But how do we ensure it performs well when faced with billions of rows?
In our next lesson, we will address this by learning how to apply partitioning and clustering strategies to optimize query performance in a cloud data warehouse.