Build a Production-Ready Sales Pipeline
You receive raw retail CSV files plagued with realistic real-world flaws: duplicate transactions, corrupted price records, missing customer keys, and untrimmed strings. Your mission is to build, execute, and validate a production-grade Medallion Lakehouse pipeline from scratch.
Mission & Business Context
Understand the operational problem, financial stakes, and your architectural goals.
The Engineering Scenario
The retail operations team at OmniCart Retail imports hundreds of store sales CSV files daily into cloud storage. Currently, analysts query these files directly, which has led to severe business escalations: duplicate transactions inflated regional revenue figures by 8%, while corrupted records with negative quantities silently skewed inventory audits.
As the incoming Data Engineer, you must replace this chaotic ad-hoc process with an automated, idempotent PySpark Medallion Lakehouse pipeline (Bronze → Silver → Gold). Bad records must be intercepted and quarantined without failing the batch, deduplication must be enforced deterministically, and Gold analytical marts must provide rock-solid reconciled metrics.
Starter Materials & Datasets
Inspect the real input datasets and boilerplate starter script. Copy and use them in your local or Databricks environment.
Hands-On Implementation Steps
Execute each step in your PySpark environment. Do not skip data-quality or schema checks.
Source Inspection & Schema Modeling
Define explicit PySpark StructTypes for customers, products, and sales. Do NOT use inferSchema=True.
Bronze Layer Ingestion & Audit Metadata
Read raw CSVs using the defined schemas and append ingestion metadata columns.
Silver Cleansing & Quarantine Routing
Implement robust cleansing rules and separate good records from corrupt records.
Silver Enrichment & Conformed Lookups
Join silver_sales with silver_customers and silver_products.
Gold Layer Analytics Mart Construction
Compute executive business metrics and write to optimized Gold Delta tables.
Expected Output & Schema Specifications
Verify your resulting Delta tables match the expected schema and row counts.
Expected Table Volumes & Outcomes
Gold Table Schema (gold_daily_store_sales)
| Column Name | Data Type | Description |
|---|---|---|
| txn_date | DATE | Calendar date of transactions (derived from txn_timestamp) |
| store_id | STRING | Unique store identifier |
| total_net_sales | DECIMAL(12,2) | Sum of net_amount after discount deductions |
| total_units_sold | INTEGER | Sum of item quantities |
| txn_count | INTEGER | Count of unique clean transactions |
| avg_order_value | DECIMAL(10,2) | total_net_sales / txn_count |
Validation Checks & Test Queries
Execute these test assertions against your completed pipeline to verify data integrity.
Run these queries in PySpark / Spark SQL. All tests must pass before you submit your evidence:
SELECT txn_id, COUNT(*) AS cnt FROM silver_sales GROUP BY txn_id HAVING COUNT(*) > 1;
SELECT * FROM silver_sales WHERE quantity <= 0 OR unit_price <= 0 OR net_amount < 0;
SELECT
(SELECT ROUND(SUM(net_amount), 2) FROM silver_sales) AS silver_net,
(SELECT ROUND(SUM(total_net_sales), 2) FROM gold_daily_store_sales) AS gold_net,
ROUND((SELECT SUM(net_amount) FROM silver_sales) - (SELECT SUM(total_net_sales) FROM gold_daily_store_sales), 2) AS variance;Evidence To Submit
Checklist of artifacts and outputs you need to document to complete the lab.
To receive grading and claim your badge, compile the following proof artifacts:
Common Mistakes To Avoid
Review these frequent anti-patterns discovered in production data engineering reviews.
Stretch / Bonus Objectives
Want to take this lab to the next level? Tackle these optional advanced engineering challenges.
Complete DEV-011 to Earn 600 XP & Pipeline Builder Badge
Build the pipeline, pass all 3 validation SQL queries, compile your evidence checklist, and submit your work for review.