Skip to the page

Data modelling · Design

Grain first: a star schema for food-delivery orders

The interviewer asks

Design the warehouse tables for a food-delivery app's orders, so analysts can see revenue by city, restaurant, cuisine and hour of the day. Start with the grain of your fact table.

Then

Follow-ups the interviewer asks next

  1. What is the grain, and why did you pick it?
  2. Which dimensions do you need, and what goes in each?
  3. Where do the delivery fee, the order-level discount and GST go?
  4. An order has three items and one coupon for the whole order. How do you split the discount?
  5. How would you model the order's journey: placed, accepted, picked up, delivered?
  6. How would you partition the fact table?

The answer

What a strong answer covers

  • States the grain before anything else: one row per order item (good for item and cuisine analysis), with a separate order-level fact for things that belong to the whole order (delivery fee, distance, delivery time). Mixing two grains in one fact table causes double counting.
  • Measures: quantity, item amount, allocated discount, tax, net amount. Knows additive (amounts), semi-additive (balances) and non-additive (ratios, which are computed, not stored) measures.
  • Dimensions: date and time of day (with an IST calendar, holidays and sale days), customer, restaurant (city, area, cuisine, rating band), menu item, delivery partner, payment method, coupon. The order id stays in the fact as a degenerate dimension.
  • Conformed dimensions (date, city, customer) are shared with other facts, so reports across facts agree.
  • Order-level discount: allocated to lines by their share of value, with the rounding remainder put on the largest line so the paise add up; or kept only in the order-level fact.
  • The order's journey: an accumulating snapshot fact, one row per order with a timestamp per milestone, updated as the order moves; it makes "time to deliver" easy.
  • Physical design: surrogate keys to the dimensions, partition by order date in IST, cluster by city or restaurant.

The red pen

Common traps

Avoid:no grain stated; putting city and restaurant names as free text in the fact; one table that mixes order rows and item rows; averaging averages.

Practise this out loud

Say your answer out loud to an AI interviewer that follows up, and get a score for it.

Practise by voice

Practise questions like this out loud

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview