Star Schema for Lakehouse
Earn 25 points (50 with Pro) in two steps
- ① Read through the lesson — each section gets a ✓ as you scroll through it.
- ② When every section has a ✓, tap Complete lesson.
0 of 11 read · keep scrolling
✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro
Lesson: Designing Star Schemas for the Data Lakehouse
Introduction: The Evolution of Data Modeling
In the past, data architecture was strictly divided into two camps: the Data Warehouse, which relied on rigid, highly structured relational databases, and the Data Lake, which acted as a raw repository for massive amounts of unstructured or semi-structured data. The Data Lakehouse is a modern architectural approach that aims to combine the best of both worlds. It provides the low-cost storage and flexibility of a data lake with the performance, ACID transactions, and structured modeling capabilities of a traditional data warehouse.
However, simply dumping data into a lakehouse does not automatically make it useful. To support business intelligence (BI) tools, high-performance reporting, and data discovery, you need a logical structure. The Star Schema—a design pattern originating from the era of data warehousing—remains the gold standard for organizing data to make it understandable and performant. In this lesson, we will explore how to apply Star Schema modeling within the modern Data Lakehouse environment to ensure your data is accessible, efficient, and reliable.
Not read yet
Understanding the Star Schema
At its core, a Star Schema is a multidimensional data model that organizes data into two distinct types of tables: Fact tables and Dimension tables. The schema is named "star" because the central fact table is connected to several surrounding dimension tables, forming a shape that resembles a star.
Fact Tables
Fact tables contain the quantitative data or metrics of a business process. These tables are typically narrow but very deep, meaning they have a high number of rows but a limited number of columns. Common examples of facts include sales amounts, order quantities, temperature readings from sensors, or the duration of a customer support call. A well-designed fact table should contain foreign keys that link to the dimension tables and the measures (the numbers) themselves.
Dimension Tables
Dimension tables contain the descriptive attributes of the data. They provide the "who, what, where, when, and why" behind the numbers in the fact table. For example, a Dim_Customer table might contain names, addresses, email domains, and loyalty status. Unlike fact tables, dimension tables are usually wide, containing many columns that describe the entities, but they typically have fewer rows.
Callout: Fact vs. Dimension Think of the Fact table as the "what happened" and the Dimension table as the "context." If you have a row in a sales table saying "100," that number is meaningless without context. When you join it to a dimension table, you learn that the "100" refers to "100 units sold" of "Product X" in "New York" on "January 1st." The fact provides the magnitude, while the dimensions provide the meaning.
Not read yet
Why Star Schema Matters in a Lakehouse
In a traditional data lake, data is often stored in flat files or folders that are difficult for BI tools to query. Users are forced to perform complex joins on massive, denormalized datasets, which is slow and error-prone. By implementing a Star Schema in a Lakehouse, you achieve three primary goals:
- Query Performance: BI tools are optimized to work with star schemas. By reducing the number of joins and simplifying the structure, you allow the query engine to scan only the necessary data.
- Usability: A Star Schema is intuitive. Business analysts can easily understand the relationships between tables, making it easier for them to build reports without needing a deep understanding of the underlying data engineering.
- Consistency: By centralizing your dimensions (e.g., a single "Source of Truth" for customer attributes), you ensure that every department uses the same definition of a customer, preventing the "multiple versions of the truth" problem.
Not read yet
Designing the Schema: Step-by-Step
Designing a Star Schema for a Lakehouse is not a one-time task; it is an iterative process that requires close collaboration with business stakeholders.
Step 1: Identify the Business Process
Before touching any code or database objects, sit down with the people who will actually use the data. Ask them what business questions they are trying to answer. Are they tracking daily revenue? Are they trying to monitor website traffic patterns? The business process defines the grain of your fact table.
Step 2: Define the Grain
The grain is the most important decision in your model. It defines what a single row in the fact table represents. For example, is a row in your sales table one individual item sold, or is it the total of an entire transaction?
- Transaction Grain: Every single item sold is a row. This is the most flexible.
- Periodic Snapshot Grain: A row represents the total sales for a day per product. This is better for long-term trend analysis but loses detail.
Tip: Choose the lowest possible grain. Always aim for the lowest level of detail (the atomic grain). You can always aggregate detailed data to create higher-level summaries, but you cannot "de-aggregate" summarized data to find individual transaction details later.
Step 3: Identify the Dimensions
Once you have the grain, identify the dimensions that describe that process. Common dimensions include:
- Time/Date: Always essential for tracking trends.
- Geography: Locations of stores, customers, or shipping hubs.
- Product: Details about items sold, categories, and brands.
- Customer: Demographics and account information.
Step 4: Identify the Measures
These are the numeric values you want to calculate. Examples include revenue, quantity_sold, discount_amount, or tax_paid. Ensure these are stored as numeric types (decimals or integers) to allow for mathematical operations.
Not read yet
Implementing in the Lakehouse (Medallion Architecture)
In a modern Lakehouse, we often use the "Medallion Architecture" to manage data quality. This involves three layers: Bronze (raw), Silver (cleaned/standardized), and Gold (refined/modeled). The Star Schema should reside in the Gold layer.
Practical Example: Sales Data
Let's look at how we would structure this using SQL-like syntax typical of modern Lakehouse engines (like Databricks or Trino).
The Fact Table
CREATE TABLE gold.fact_sales (
sales_key BIGINT,
date_key INT,
customer_key INT,
product_key INT,
store_key INT,
transaction_id STRING,
quantity INT,
unit_price DECIMAL(10, 2),
total_amount DECIMAL(10, 2)
)
USING DELTA;
The Dimension Table
CREATE TABLE gold.dim_product (
product_key INT,
product_id STRING,
product_name STRING,
category STRING,
brand STRING,
is_active BOOLEAN
)
USING DELTA;
Note: Using Surrogate Keys Notice the use of
_keycolumns. These are "surrogate keys"—simple integer identifiers that replace the natural keys (like aproduct_idwhich might change over time). Surrogate keys are essential because they allow you to track historical changes in dimensions without breaking the relationships in the fact table.
Not read yet
Handling Slowly Changing Dimensions (SCD)
One of the most common challenges in data modeling is managing changes in dimension attributes. If a customer moves from New York to California, how do you reflect that in your data?
- SCD Type 0: The attribute never changes.
- SCD Type 1: Overwrite the old value. Use this if you only care about the current state.
- SCD Type 2: Keep a full history. Add a new row for every change and use
effective_dateandend_datecolumns to track validity.
In a Lakehouse, SCD Type 2 is preferred for auditability. When a customer moves, you expire the old record and insert a new one with a new surrogate key. Your fact table keeps pointing to the surrogate key that was valid at the time of the transaction.
Best Practices for Lakehouse Modeling
To ensure your Star Schema is efficient, follow these industry-standard practices:
- Keep Dimensions Small: If a dimension table becomes massive (millions of rows), consider if it truly belongs as a dimension or if it should be treated as a fact table.
- Avoid Nulls: Where possible, use default values like "Unknown" or "Not Applicable" for null fields in dimensions. This prevents join issues and makes reporting cleaner.
- Partitioning: In a Lakehouse, partition your fact tables by date (e.g.,
year,month). This allows the query engine to "prune" partitions, meaning it won't scan the entire history of the company when a user only asks for last month's sales. - Data Typing: Be consistent with data types across joins. If
product_keyis an integer in the fact table, it must be an integer in the dimension table. Mismatched types lead to performance degradation during joins. - Documentation: Maintain a data dictionary. Since the Lakehouse is accessible to many, clear documentation on what each column represents is vital for self-service analytics.
Callout: Star vs. Snowflake Schema A Snowflake Schema is a variation where dimension tables are normalized (e.g., breaking
ProductintoProduct,Category, andBrandtables). While it reduces redundancy, it creates more joins. In a Lakehouse, Star Schema is generally superior because modern storage is cheap and the performance cost of extra joins is often higher than the storage cost of denormalization.
Not read yet
Common Pitfalls and How to Avoid Them
1. Over-normalization
Many engineers coming from an application development background try to normalize their dimensions into many small tables. This is a mistake in a data warehouse or lakehouse. Remember: read-heavy workloads (analytics) prefer denormalized data. If you have to join five tables just to describe a product, you have over-normalized.
2. Ignoring Data Quality at the Ingest
If you push garbage data into the Gold layer, your Star Schema will be useless. Implement data quality checks in the Bronze-to-Silver transition. Ensure that customer_key in your fact table actually exists in your dim_customer table (referential integrity). If it doesn't, the join will drop the record, causing your revenue reports to be inaccurate.
3. Mixing Granularities
Never try to store daily snapshots and individual transactions in the same fact table. If you need both, create two separate fact tables. Mixing them creates confusion for BI tools and leads to double-counting when users sum up metrics.
4. Poor Performance
If your queries are slow, check your partitioning strategy. If you are partitioning by a column that is rarely used in filters (like customer_id), your query engine will be forced to perform a full table scan. Always partition by the column most commonly used in the WHERE clause, which is almost always a date or time field.
Not read yet
Comparison Table: Storage vs. Modeling
| Feature | Data Lake (Raw) | Star Schema (Lakehouse) |
|---|---|---|
| Structure | Unstructured/Semi-structured | Highly Structured |
| Join Complexity | High | Low |
| Query Performance | Slow | Fast |
| Primary Use | Data Science / Archival | BI / Reporting / Dashboards |
| Data Integrity | Low (Raw data) | High (Validated) |
Step-by-Step: Validating Your Model
Once you have created your tables, follow this checklist to ensure the model is ready for consumption:
- Row Count Check: Perform a
COUNT(*)on the fact table and compare it to the source data. Ensure no rows were dropped during the transformation process. - Join Test: Run a sample query that joins your fact table to three dimensions. Does it return results in a reasonable time? If not, check your join keys.
- Null Check: Run a query to identify any null values in your
_keycolumns. If you find them, investigate the source and fix the mapping. - Business Logic Verification: Ask a subject matter expert to run a known report against your new schema. Does the result match their legacy report? If not, verify your calculation logic for the measures.
Not read yet
Advanced Concepts: Time-Travel and Versioning
A unique benefit of the Lakehouse (using formats like Delta Lake or Apache Iceberg) is the ability to query data as it existed in the past. This is known as "Time Travel." When building a Star Schema, ensure you are leveraging these features.
If you update a dimension table (SCD Type 1), you can use time travel to see how that dimension looked yesterday. This is invaluable for debugging reporting discrepancies. For instance, if a report showed different numbers yesterday than it does today, you can query the table as of a specific timestamp to see if a dimension update changed the categorization of certain sales.
-- Example of querying historical data in a Lakehouse
SELECT *
FROM gold.dim_product
VERSION AS OF 5; -- Or use TIMESTAMP AS OF '2023-10-01'
Integrating with BI Tools
Once your Gold layer is populated, your BI tool (Power BI, Tableau, Looker) will connect to the Lakehouse. Because you have implemented a Star Schema, the BI tool will automatically detect the relationships.
- Define Relationships: In your BI tool, explicitly define the relationships (e.g.,
fact_sales.product_keytodim_product.product_key). Use a "Many-to-One" relationship where the dimension is the "One" side. - Set Cross-Filter Direction: Set this to "Single" (Fact filters Dimension) to prevent unintended filtering behavior.
- Hide Key Columns: Hide the surrogate keys (
_key) from the end-user report view. They are necessary for the engine but confusing for the business user.
Not read yet
Conclusion and Key Takeaways
The Star Schema remains the most effective way to bridge the gap between complex data storage and intuitive business reporting. In the context of a Lakehouse, it provides the structure necessary to deliver high-performance analytics without sacrificing the flexibility of modern cloud storage.
By focusing on atomic grains, using surrogate keys, managing changes through SCDs, and ensuring consistent data types, you create a robust foundation for your organization's data needs. Remember that modeling is an ongoing conversation with your stakeholders; as business questions change, your schema should evolve to meet them.
Key Takeaways
- Star Schema is Essential: It transforms raw data into a readable, performant structure that BI tools love.
- The Grain Matters: Always define the atomic grain of your fact table to ensure maximum flexibility for future reporting needs.
- Surrogate Keys are Mandatory: Use them to handle historical changes in dimensions (SCDs) without corrupting your fact table relationships.
- Denormalization is a Feature: Do not be afraid to create wide dimension tables. The performance gain of fewer joins outweighs the cost of storage in a modern Lakehouse.
- Partitioning is Key: Optimize query performance by partitioning your fact tables, typically by date, to allow for efficient data skipping.
- Quality First: Use the Medallion architecture to ensure that only validated, high-quality data ever makes it to your Gold-layer Star Schema.
- Iterate and Collaborate: Data modeling is not a solo task. Work with business users to ensure the model actually answers the questions they are asking.
Not read yet
Common Questions (FAQ)
Q: Should I use a Star Schema for real-time streaming data? A: Star Schemas are generally designed for batch or micro-batch processing. For real-time streaming, you might need a "Lambda" or "Kappa" architecture where you append to a fact table continuously, but you must ensure your dimensions are updated in a way that doesn't block incoming data.
Q: How do I handle very large dimensions (e.g., a "Customer" dimension with 100 million rows)? A: If a dimension is this large, it's often called a "Junk Dimension" or a "Degenerate Dimension." You may need to use advanced techniques like indexing or partitioning the dimension table itself, or reconsider if all those attributes are necessary for the specific fact table you are modeling.
Q: Can I have multiple fact tables?
A: Absolutely. A robust Lakehouse environment will have many fact tables (e.g., fact_sales, fact_web_traffic, fact_inventory). The beauty of the Star Schema is that they can all share the same "Conformed Dimensions" (e.g., the same dim_date and dim_product tables), allowing you to join across different business processes easily.
Not read yet
Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.
- Workspace Level Access Controls
- Workspace Level Access Controls Quiz5q
- Item Level Access Controls
- Item Level Access Controls Quiz5q
- Row Level Security
- Row Level Security Quiz5q
- Column Level and Object Level Security
- Column Level and Object Level Security Quiz5q
- File Level Access Control
- File Level Access Control Quiz5q
- Sensitivity Labels
- Sensitivity Labels Quiz5q
- Endorsing Items
- Endorsing Items Quiz5q
- Data Loss Prevention Policies
- Data Loss Prevention Policies Quiz5q
- Version Control for Workspaces
- Version Control for Workspaces Quiz5q
- Power BI Desktop Projects
- Power BI Desktop Projects Quiz5q
- Deployment Pipelines
- Deployment Pipelines Quiz5q
- Impact Analysis
- Impact Analysis Quiz5q
- XMLA Endpoint for Semantic Models
- XMLA Endpoint for Semantic Models Quiz5q
- Reusable Assets and Templates
- Reusable Assets and Templates Quiz5q
- Shared Semantic Models
- Shared Semantic Models Quiz5q
- Git Integration Best Practices
- Git Integration Best Practices Quiz5q
- Creating Data Connections
- Creating Data Connections Quiz5q
- OneLake Catalog and Real-Time Hub
- OneLake Catalog and Real-Time Hub Quiz5q
- Data Ingestion Methods
- Data Ingestion Methods Quiz5q
- Choosing Data Stores
- Choosing Data Stores Quiz5q
- OneLake Integration for Eventhouse
- OneLake Integration for Eventhouse Quiz5q
- Lakehouse Architecture
- Lakehouse Architecture Quiz5q
- Warehouse Architecture
- Warehouse Architecture Quiz5q
- Dataflows Gen2
- Dataflows Gen2 Quiz5q
- Views Functions and Stored Procedures
- Views Functions and Stored Procedures Quiz5q
- Enriching Data with New Columns
- Enriching Data with New Columns Quiz5q
- Star Schema for Lakehouse
- Star Schema for Lakehouse Quiz5q
- Star Schema for Warehouse
- Star Schema for Warehouse Quiz5q
- Denormalizing Data
- Denormalizing Data Quiz5q
- Aggregating Data
- Aggregating Data Quiz5q
- Merging and Joining Data
- Merging and Joining Data Quiz5q
- Handling Duplicate Data
- Handling Duplicate Data Quiz5q
- Handling Missing and Null Values
- Handling Missing and Null Values Quiz5q
- Converting Column Data Types
- Converting Column Data Types Quiz5q
- Filtering Data
- Filtering Data Quiz5q
- Data Pipelines in Fabric
- Data Pipelines in Fabric Quiz5q
- Spark Notebooks
- Spark Notebooks Quiz5q
- Delta Tables in Lakehouse
- Delta Tables in Lakehouse Quiz5q
- Data Wrangling Techniques
- Data Wrangling Techniques Quiz5q
- Visual Query Editor
- Visual Query Editor Quiz5q
- Querying with SQL
- Querying with SQL Quiz5q
- Querying with KQL
- Querying with KQL Quiz5q
- Querying with DAX
- Querying with DAX Quiz5q
- Advanced SQL Queries
- Advanced SQL Queries Quiz5q
- Time Intelligence in DAX
- Time Intelligence in DAX Quiz5q
- KQL Query Patterns
- KQL Query Patterns Quiz5q
- Combining Query Languages
- Combining Query Languages Quiz5q
- Choosing Storage Mode
- Choosing Storage Mode Quiz5q
- Star Schema for Semantic Models
- Star Schema for Semantic Models Quiz5q
- Implementing Relationships
- Implementing Relationships Quiz5q
- Bridge Tables and Many-to-Many
- Bridge Tables and Many-to-Many Quiz5q
- DAX Variables and Functions
- DAX Variables and Functions Quiz5q
- DAX Iterator Functions
- DAX Iterator Functions Quiz5q
- Table Filtering and Windowing
- Table Filtering and Windowing Quiz5q
- Calculation Groups
- Calculation Groups Quiz5q
- Dynamic Format Strings
- Dynamic Format Strings Quiz5q
- Field Parameters
- Field Parameters Quiz5q
- Large Semantic Model Storage
- Large Semantic Model Storage Quiz5q
- Composite Models
- Composite Models Quiz5q
- Information Functions in DAX
- Information Functions in DAX Quiz5q
- Hierarchies in Semantic Models
- Hierarchies in Semantic Models Quiz5q
- Role-Playing Dimensions
- Role-Playing Dimensions Quiz5q
- Query Performance Improvements
- Query Performance Improvements Quiz5q
- Report Visual Performance
- Report Visual Performance Quiz5q
- DAX Performance Optimization
- DAX Performance Optimization Quiz5q
- Direct Lake Configuration
- Direct Lake Configuration Quiz5q
- Direct Lake Fallback and Refresh
- Direct Lake Fallback and Refresh Quiz5q
- OneLake vs SQL Endpoints
- OneLake vs SQL Endpoints Quiz5q
- Incremental Refresh
- Incremental Refresh Quiz5q
- Performance Analyzer
- Performance Analyzer Quiz5q
- Aggregations in Semantic Models
- Aggregations in Semantic Models Quiz5q
- Monitoring Semantic Models
- Monitoring Semantic Models Quiz5q
- Query Folding
- Query Folding Quiz5q
- Partitioning Strategies
- Partitioning Strategies Quiz5q
- Troubleshooting Refresh Failures
- Troubleshooting Refresh Failures Quiz5q
Spend your points to unlock exam-style practice questions
Spend points to unlock DP-600 exam-style practice questions.
Practice for DP-600