Capstone Project: Designing, Optimizing & Querying a Full E-Commerce & SaaS Analytics Warehouse
Design schemas, load facts, optimize queries, and answer SaaS/e-commerce metrics end-to-end.
In plain words
Design the tables, copy them into a reporting database, write the important business numbers, and check they're fast and correct.
Think of it like…
Building a small house rather than practising each trade separately: the foundation (schema), the frame (warehouse model), the wiring (metrics) and the inspection (tests) all have to fit, and mistakes in one show up in the others.
Where you’ve seen it
The leadership dashboard needs, every morning: net revenue by month (sales minus refunds), average order value, new vs returning revenue, the top 3 products in each category, Pro MRR with new, expansion, contraction and churn, and 90-day repeat rates by first-order month. All of it must reconcile with the payments provider's totals to the rupee.
Words you’ll hear
- Fact grain
- fct_order_items: one row per order line; fct_subscription_months: one row per subscription per month.
- Conformed dimensions
- dim_customer, dim_product and dim_date shared by every fact.
- Net revenue
- Gross order revenue minus refunds, each aggregated separately before combining.
- Reconciliation
- Checking warehouse totals against a trusted source such as payment provider reports.
Visual diagram
Theory & example queries
Schema and warehouse design
In the application database, every table gets a primary key, foreign keys and checks: order_items (order_id REFERENCES orders, product_id REFERENCES products, quantity int CHECK (quantity > 0), unit_price numeric(12,2) NOT NULL), with the price captured at purchase time. Index the API's access paths, such as orders (customer_id, created_at DESC). Subscriptions record plan, seats and status changes as events, so history isn't overwritten.
In the warehouse, staging models clean each source table, intermediate models match payments and refunds to orders and expand subscriptions into one row per month, and marts expose facts at a declared grain. fct_order_items holds quantity, gross amount and keys to dim_customer (type 2 for segment and country), dim_product and dim_date; fct_subscription_months holds MRR per subscription per month. Partition or cluster the large facts by date so most queries read only recent data, and build them incrementally.
WITH sales AS ( SELECT d.year_month, SUM(f.gross_amount) AS gross FROM fct_order_items f JOIN dim_date d ON d.date_key = f.order_date_key GROUP BY 1 ), refunds AS ( SELECT d.year_month, SUM(r.amount) AS refunded FROM fct_refunds r JOIN dim_date d ON d.date_key = r.refund_date_key GROUP BY 1 )SELECT s.year_month, s.gross, COALESCE(r.refunded, 0) AS refunded, s.gross - COALESCE(r.refunded, 0) AS netFROM sales s LEFT JOIN refunds r USING (year_month)ORDER BY 1;PostgreSQL is the lesson baseline unless noted otherwise.
Read this line together with the surrounding statement as part of the same SQL expression.
Expected output3 sample rows
| year_month | gross | refunded | net |
|---|---|---|---|
| 2026-08 | 184500 | 6200 | 178300 |
| 2026-09 | 203750 | 8100 | 195650 |
| 2026-10 | 226400 | 4750 | 221650 |
Note: Illustrative warehouse facts and currency amounts for three months.
Key takeaway: Constraints in the app; declared grains, conformed dimensions and date partitioning in the warehouse.
Metrics, performance and trust
Each metric reuses a pattern from earlier lessons: AOV is net revenue ÷ distinct orders; new vs returning revenue uses ROW_NUMBER over each customer's orders; top 3 products per category is ROW_NUMBER partitioned by category with rn <= 3; MRR movements compare each subscription's MRR with LAG over months (new, expansion, contraction, churn); retention is a cohort triangle by first-order month. Write each as a CTE pipeline with a grain comment per step.
Make it fast: incremental fact builds, date partitions, a small daily summary table or materialised view for the dashboard, and EXPLAIN on anything slow. Make it trustworthy: unique and not_null tests on every key, relationships tests from facts to dimensions, accepted values for statuses, freshness checks on sources, and a daily reconciliation of net revenue against the payment provider's settlement report. Mask customer PII in the marts analysts use.
WITH ranked AS ( SELECT p.category, p.name, SUM(f.gross_amount) AS revenue, ROW_NUMBER() OVER ( PARTITION BY p.category ORDER BY SUM(f.gross_amount) DESC, p.name ) AS rn FROM fct_order_items f JOIN dim_product p ON p.product_key = f.product_key JOIN dim_date d ON d.date_key = f.order_date_key WHERE d.year_month = '2026-10' GROUP BY p.category, p.name )SELECT category, name, revenueFROM rankedWHERE rn <= 3ORDER BY category, rn;PostgreSQL is the lesson baseline unless noted otherwise.
Read this line together with the surrounding statement as part of the same SQL expression.
Expected output4 sample rows
| category | name | revenue |
|---|---|---|
| Books | SQL Field Guide | 18400 |
| Books | Data Modeling | 12650 |
| Electronics | USB-C Hub | 35200 |
| Electronics | Wireless Mouse | 24100 |
Note: Shows an illustrative excerpt; a full result contains up to three products per category.
Key takeaway: Reuse proven patterns per metric; tests and reconciliation before anyone sees a number.
How it works, step by step
Follow one practical SQL workflow from start to finish. Select any step or play through the flow.
Requirements and grains
List each dashboard metric with its exact definition, and the grain of each fact table that supports it.
net revenue = gross − refunds · fct_order_items: one row per line
When to use it & trade-offs
What it is
This capstone builds analytics end to end for a business that sells products online and a monthly "Pro" membership. You design the application schema (customers, products, orders, order_items, payments, refunds, subscriptions), model a warehouse (staging → intermediate → marts with fct_order_items, fct_subscription_months, dim_customer, dim_product, dim_date), write the metrics (net revenue, AOV, repeat rate, top products per category, MRR movements, cohort retention), and make it fast and trustworthy with partitions, indexes, incremental models and tests.
Why it matters: Interviews for analyst, analytics-engineer and data-engineer roles increasingly use a take-home or a whiteboard case like this, because it shows whether you can connect the pieces: grain, joins, window functions, CTE pipelines, indexing and data quality. Working through one complete project is also the best way to see how the earlier lessons fit together.
When to reach for it
- Take-home assignments for analytics roles
- A portfolio project that shows end-to-end skills
- Planning a real company's first warehouse
When to avoid or be careful
- Joining orders, items and refunds before aggregating
- Metrics without written definitions
- Dashboards built before tests and reconciliation pass
Design choices in the capstone
Strengths: Clear grains; correct joins; reusable dimensions.
Watch out: More models to build and test.
Strengths: Simple for one consumer.
Watch out: Duplicated logic; mixed grains; hard to extend.
Strengths: No pipeline to build.
Watch out: Slows the app; no history; logic scattered across reports.
Interview signals & numbers to know
When this topic comes up
- “Design an analytics warehouse for an e-commerce company”
- “Calculate MRR and churn from subscription data”
- “Take-home: build these six metrics”
- End-to-end data modelling
- Metric definitions
Benchmarks & rules of thumb
- 2
- fact grains: order line, subscription-month
- 3
- conformed dimensions: customer, product, date
- ₹0
- allowed difference from the payments reconciliation
Common mistakes & follow-ups
Common interview mistakes
- Joining refunds to order lines and summing both, counting each refund once per line in the order.
- Computing MRR from the current subscriptions table, losing every past plan change and churn.
- Shipping the dashboard first and discovering a week later that revenue is 6% above the payment provider's total.
Likely interviewer follow-ups
- What tables and grains would you design for this business?
- How would you calculate net revenue and MRR movements correctly?
- How would you prove the dashboard's numbers are right?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Capstone Project: Designing, Optimizing & Querying a Full E-Commerce & SaaS Analytics Warehouse with hands-on SQL practice and interview Q&A.