Modeling the data warehouse
Professional Data Engineer · Lesson 13 of 23 · 1:32:56
YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗
Learning with these videos? Subscribe for new courses and exam-style questions.
Subscribe on YouTube (opens in a new tab)In this lesson
Prepare for the Google Cloud Professional Data Engineer exam, on the official exam guide. In this lesson: from business questions to a model and its grain, star and snowflake schemas, normalization and denormalization, nested and repeated fields, and history and keys. Includes three original practice questions, with Cymbal Mobility, a fictional ride-hailing and scooter company, as the example.
Study notes
The text of this lesson, to read at your own pace. Information as of November 2026.
Forty tables, a dozen joins
Cymbal Mobility's finance team asks for revenue per city, per month, and per vehicle type, and operations asks for trip details with every stop. The old warehouse spreads this over forty normalized tables, and every report needs a dozen joins. The data engineer must design a model for BigQuery.
From requirements to a model
Start from business questions, not from the source tables. List the measures people need, like revenue or trip count, and the ways they slice them, like city, month, or vehicle type. Agree on the grain of each table: one row per trip, per trip stop, or per day and city. Note who uses the data, how fresh it must be, and how they filter it, because that drives partitioning and clustering. And keep raw, cleaned, and business-ready layers apart, so each model can be rebuilt.
Star and snowflake schemas
A star schema puts the measures in a fact table, like trips, with keys to dimension tables, like rider, city, and vehicle. A snowflake schema normalizes the dimensions further, so a city table points to a country table, which means more joins. Normalization stores each fact once, which suits transactional systems with many small changes. Analytics favors denormalization: BigQuery stores data in columns, reads only the columns a query uses, and runs fastest with fewer joins. BigQuery supports both star and snowflake schemas, but its most natural model uses nested and repeated fields.
Nested and repeated fields
BigQuery's own way to denormalize is nested and repeated fields. A struct, also called a record, groups related fields, and an array, a repeated field, holds a list of values or structs in a single row. So each trip row can hold its stops as an array of structs, instead of a separate stops table to join. Queries flatten the stops with the unnest operator when needed, and data that belongs together stays together. The cost is some repeated data and more storage, which is usually worth the speed of fewer joins.
History and keys
Dimensions change: a scooter moves to another city, or a rider changes plan. When reports must show the past as it was, keep history in the dimension: a new row for each change, with start and end dates, often called a type two slowly changing dimension. When only the current value matters, overwrite the row instead. BigQuery lets you declare primary and foreign keys, but it does not enforce them: they help the optimizer, so your pipelines must keep them valid. And for business users, publish clean tables or views with clear names, so the model matches the questions they ask.
Recap
Let's recap. Start from business questions: measures, the ways to slice them, the grain, freshness, and filters. Star schemas put measures in a fact table with dimensions around it, and snowflake schemas normalize the dimensions further, at the cost of more joins. BigQuery favors denormalization, and its natural model uses nested and repeated fields, like stops inside each trip. Keep history with a new row for each change and its dates, when reports must show the past as it was. And remember that primary and foreign keys in BigQuery are not enforced: they only help the optimizer.
Quick checks for this lesson
The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.
Dashboards join the trips fact table to city, which joins region, which joins country, and every query needs all three. What change reduces the joins?
- Normalize the city table even further
- Hide the three joins inside a view
- Denormalize city, region, and country into one dimension
- Move the dimension tables to Cloud SQL
Show the answer
Denormalize city, region, and country into one dimension
One denormalized city dimension, holding the region and the country, turns three joins into one. “Normalize the city table even further” would add even more joins. “Hide the three joins inside a view” would hide the joins in a view, but every query would still run them. And “Move the dimension tables to Cloud SQL” would move the tables out of BigQuery, and make every join slower.
Each trip has two to ten stops, and analysts always read a trip with its stops. Today, a stops table of eight billion rows is joined to trips in every query. What should the data engineer do?
- Store the stops as a repeated record in each trip
- Cluster the stops table by trip ID
- Copy the stops table into Bigtable
- Split the stops into one table per day
Show the answer
Store the stops as a repeated record in each trip
A repeated record keeps each trip's stops in the same row, so no join is needed. “Cluster the stops table by trip ID” would make the join cheaper, but every query would still run it. “Copy the stops table into Bigtable” would move the stops out of BigQuery, away from the analysts' SQL. And “Split the stops into one table per day” would create thousands of tables, and still need the join.
Finance must report each past trip under the pricing plan that applied at the time, even after a scooter’s plan changes. How should the vehicle dimension handle changes?
- Overwrite the plan in the existing row
- Declare a primary key on the vehicle ID
- Delete the old row, then insert the new one
- Add a new row for each change, with its dates
Show the answer
Add a new row for each change, with its dates
A new row for each change, with its dates, keeps every past version, so each trip joins to the plan of its own time. “Overwrite the plan in the existing row” would rewrite history with the current plan. “Declare a primary key on the vehicle ID” would only describe the key, and BigQuery does not enforce it. And “Delete the old row, then insert the new one” would also lose the old version.