The modelling round

Part of the free LogicWiz Data Engineering course, Module 18: Interview rounds. The SQL and Python run in the app, on real Postgres and real Python in the browser.

It is the modelling round. There is a whiteboard and no editor. The interviewer says: "Design the tables for a ride-hailing app. Analysts want revenue per driver per day, cancellations by zone and average trip time." There is no query to run and no single right answer, and that is what makes this round scary. It gets easier the moment you stop drawing boxes and say one sentence first: what does one row of the fact table mean?

You'll learn to

  • Answer a design prompt in a fixed order, starting from the questions
  • Build and load a small star schema with surrogate keys
  • Apply an SCD type 2 change and pick the right fact type

Learn

How the round runs

You get a product (a store, a ride-hailing app, a video streaming service) and 45 minutes to design what analysts will query. The interviewer listens for a method, not a perfect diagram:

  1. Ask which questions the business needs answered.
  2. Pick the business process: an order line, a trip, a play.
  3. Declare the grain in one sentence: "one row per trip".
  4. Add the dimensions: who, what, where, when.
  5. List the measures, and say whether they add up across every dimension.
  6. Decide how history is kept: overwrite (SCD type 1) or a new row per change (type 2).

Then test the design out loud against one of the questions.

Build the ride-hailing answer, one move at a time

The ride-hailing design grows in five steps: the three questions, the grain of fact_trip, its dimensions with the zone dimension used twice, its measures, and a test of the design against the questions.

  1. The questions. Revenue per driver per day, cancellations by zone, average trip time. All three are about one thing that happens: a trip.

  2. The grain. Say it before any column: "one row per trip request, completed or cancelled." Cancelled trips must be rows too, or nobody can count them.

  3. The dimensions. Who, where, when: a rider, a driver, a date and a zone. A trip has two zones, so dim_zone is used twice, as pickup and as drop-off. That is called a role-playing dimension.

  4. The measures. fare and distance_km add up across every dimension. status stays on the row, so cancellations can be counted.

  5. Test it on the questions. Revenue per driver per day is SUM(fare) grouped by driver_key and date_key. Cancellations by zone is a count where status = 'cancelled'. Average trip time needs a duration, and the fact has none. The test found a gap: add a measure for it, and say so.

Read the middle box as the fact table growing, one move per step. The last step is the one candidates skip, and the one interviewers remember.

Three classic prompts, grain first

PromptFact and grainDimensionsThe twist
E-commercefactorderline: one row per product line of an orderdate, customer (type 2), productan order-level shipping fee does not belong on every line
Ride-hailingfacttrip: one row per trip request, completed or cancelleddate, rider, driver, pickup zone, drop-off zoneone zone dimension used twice: a role-playing dimension
Streaming servicefactplayback: one row per play of a title on a devicedate, user, title, device, plansubscriber counts need a periodic snapshot: one row per plan per day

Read the second column first: the grain. Say it before any column. Every later choice (which keys, which measures, what adds up) follows from it.

SwiftKart's fact_order_line in the middle with the date, customer and product dimensions around it; click a table to see its columns and its grain.

This is the e-commerce row of the table, built: SwiftKart's own warehouse. Click each table to see its columns and its grain.

History in the warehouse: customer 18 moved

SELECT f.order_id, d.full_date, c.customer_key, c.city
FROM fact_order_line AS f
JOIN dim_customer AS c ON c.customer_key = f.customer_key
JOIN dim_date AS d ON d.date_key = f.date_key
WHERE c.customer_id = 18
GROUP BY f.order_id, d.full_date, c.customer_key, c.city
ORDER BY d.full_date;

Step 6, history, in real rows. The fact stores the surrogate key of the customer version that was current on the order date. The 7 June order points at key 18 (Berlin) for ever; later orders point at key 19 (Munich). Joining on customer_key gives "where they lived then" with no date logic at all.

An SCD type 2 change: customer 5 moves to Rome on 12 June

customerkeycityvalidfromvalidtoiscurrent
before5Milan2025-01-019999-12-31true
after5Milan2025-01-012025-06-12false
after32 (new)Rome2025-06-129999-12-31true

Compare the "before" row with the two "after" rows. Two statements do it: close the current row, insert a new one with a new key. A "change" to the same city must do nothing, or every daily load would add a row.

Interviewers reward the sentence "the grain is one row per ..." said early, and a design checked against a real question. Name your keys (surrogate keys in dimensions, natural keys kept as attributes), say which dimension needs history and why, and mention one trade-off, such as a star schema being simpler to query than a snowflake at the cost of some repeated text.

The trap: mixed grain. Put an order's $5 shipping fee on each of its four lines, and SUM reports $20. Keep each measure at its own grain (an order-level fact, or share the fee out across the lines on purpose). And never join two facts of different grains directly: aggregate each to a shared grain first.

Remember: "The grain is one row per ..." Say that sentence first, and test the design on a real question last.

Next is the scenario round: something is broken in production, and you talk the interviewer through it.

In one line

Design in a fixed order: the questions, the process, the grain in one sentence, the dimensions, the measures and whether they add up, then history, and keep every measure at its own grain.

Interview corner

How do you start a data modelling question?

I ask which questions the business needs answered, pick the business process behind them, and declare the grain in one sentence, such as "one row per trip request". Then I add the dimensions (who, what, where, when), the measures with their additivity, and decide how each dimension keeps history. I finish by running one of the questions against the design out loud.

Why declare the grain first?

The grain decides everything else: which dimensions can attach, which measures are valid and whether sums are correct. Most modelling bugs are mixed grain, such as an order-level fee repeated on every line, and stating the grain up front makes them visible before any table exists.

How do you model a customer whose address changes?

If analysts need history, SCD type 2: the dimension gets a surrogate key, valid_from, valid_to and is_current, and a change closes the current row and inserts a new one. Facts store the surrogate key current at the time of the event, so joins are automatically point-in-time. If history does not matter, type 1 simply overwrites.

What is the difference between a transaction fact, a periodic snapshot and an accumulating snapshot?

A transaction fact has one row per event (an order line, a trip). A periodic snapshot has one row per thing per period (subscribers per plan per day) and records state even when nothing happened. An accumulating snapshot has one row per process instance (an order) with a column per milestone, updated as it progresses.