Local-First Pipeline ETL Verified (100%) Production Star Schema

Retail & Supply Chain Intelligence Studio

Automated Olist Brazilian E-Commerce ETL, Relational Star Schema & Advanced SQL Business Audit

Runtime Target
SQLite / DuckDB / MySQL
Gross Merchandise Value
$1.41M
Total processed payments across 4,000 orders
Top Logistics Bottleneck
+12.6 d
Amapá (AP) average delivery delay beyond SLA promise
Credit Card Volume
74.4%
$1.05M settled volume; AOV $352.19
Top VIP Customer Spend
$16.9K
42 orders (+$15,551 above benchmark baseline)
📈 Monthly Revenue & Order Volume Seasonality
🚚 Logistics Delivery Gap vs. Promised Date
🎯 Executive Audit Findings & Operational Decisions
Critical Logistics Friction: The Northern corridor (Amapá AP +12.6d, Roraima RR +7.1d, Amazonas AM +6.1d) experiences severe SLA non-compliance due to Amazon basin riverway reliance. Action item: Extend published delivery promises by 10 business days for northern zip prefixes to curb refund chargebacks.
Payment Settlement Optimization: Boleto accounts for 18.4% of volume ($261K) but introduces a 48–72 hour settlement latency before order confirmation. Action item: Implement automated Pix instant payment gateway to capture Boleto volume while unlocking immediate fulfillment.
🏛️ Production Relational Star Schema (Kimball Methodology)

Modeled to isolate dimensional master records (Customers, Sellers, Products) from transactional fulfillment, payments, and review events.

DIM_CUSTOMERS Dimension
PK customer_id VARCHAR(50)
customer_unique_id VARCHAR(50)
customer_zip_code_prefix VARCHAR(10)
customer_city VARCHAR(100)
customer_state VARCHAR(5)
FACT_ORDERS Fact (Grain: 1 Order)
PK order_id VARCHAR(50)
FK customer_id VARCHAR(50)
order_status VARCHAR(20)
order_purchase_timestamp DATETIME
order_delivered_customer_date DATETIME
order_estimated_delivery_date DATETIME
FACT_ORDER_ITEMS Fact (Line Item)
FK order_id VARCHAR(50)
PK order_item_id INTEGER
FK product_id VARCHAR(50)
FK seller_id VARCHAR(50)
price DECIMAL(10,2)
freight_value DECIMAL(10,2)
DIM_PRODUCTS Dimension
PK product_id VARCHAR(50)
product_category_name VARCHAR(100)
product_name_lenght INTEGER
product_weight_g FLOAT
DIM_SELLERS Dimension
PK seller_id VARCHAR(50)
seller_zip_code_prefix VARCHAR(10)
seller_city VARCHAR(100)
seller_state VARCHAR(5)
FACT_PAYMENTS Fact (Payment)
FK order_id VARCHAR(50)
PK payment_sequential INTEGER
payment_type VARCHAR(30)
payment_installments INTEGER
payment_value DECIMAL(10,2)
💻 SQL Challenge 1: Shipping Delay Audit (Top 3 Slowest States)

Calculates average delay (Actual Delivery - Estimated Delivery) in days for delivered orders.

SQL (ANSI / SQLite / MySQL DATEDIFF)
SELECT 
    c.customer_state,
    COUNT(o.order_id) AS delivered_orders,
    ROUND(AVG(JULIANDAY(o.order_delivered_customer_date) - JULIANDAY(o.order_estimated_delivery_date)), 2) AS avg_delay_days,
    ROUND(MAX(JULIANDAY(o.order_delivered_customer_date) - JULIANDAY(o.order_estimated_delivery_date)), 2) AS max_delay_days
FROM fact_orders o
INNER JOIN dim_customers c ON o.customer_id = c.customer_id
WHERE o.order_status = 'delivered'
  AND o.order_delivered_customer_date IS NOT NULL
GROUP BY c.customer_state
ORDER BY avg_delay_days DESC
LIMIT 3;
Customer StateDelivered OrdersAvg Delay (Days)Max Delay (Days)Status
AP (Amapá)11+12.6437Severe Bottleneck
RR (Roraima)22+7.0535Severe Bottleneck
AM (Amazonas)58+6.0534Riverway Delay
💻 SQL Challenge 2: Top Earners per Category (Correlated Subquery)

Finds the top 5 sellers by revenue in each category without window functions.

SQL (Classical Correlated Subquery Method)
WITH seller_category_revenue AS (
    SELECT 
        p.product_category_name,
        oi.seller_id,
        ROUND(SUM(oi.price), 2) AS total_revenue,
        COUNT(oi.order_item_id) AS total_units_sold
    FROM fact_order_items oi
    INNER JOIN dim_products p ON oi.product_id = p.product_id
    GROUP BY p.product_category_name, oi.seller_id
)
SELECT t1.product_category_name, t1.seller_id, t1.total_revenue, t1.total_units_sold
FROM seller_category_revenue t1
WHERE (
    SELECT COUNT(*) 
    FROM seller_category_revenue t2
    WHERE t2.product_category_name = t1.product_category_name
      AND t2.total_revenue > t1.total_revenue
) < 5
ORDER BY t1.product_category_name ASC, t1.total_revenue DESC;
💻 SQL Challenge 3: Payment Preferences & Financial Breakdown
Clean Payment MethodTransactionsTotal Volume ($)Avg Order Value ($)Transaction Share %Revenue Share %
Credit Card2,975$1,047,760$352.1974.38%74.10%
Boleto736$261,179$354.8618.40%18.47%
Other (Voucher / Debit)289$105,022$363.407.22%7.43%
💻 SQL Challenge 4: Customer Lifetime Value (CLV Power Users)

Isolates customers with ≥ 3 orders whose spend exceeds the benchmark average ($1,415.23).

Customer Unique IDStateOrdersTotal Spend ($)Avg Spend / Order ($)Benchmark Average ($)Spend Above Benchmark ($)
uniq_cust_1621SP42$16,966.20$403.96$1,415.23+$15,551.00
uniq_cust_0327SP38$15,756.90$414.65$1,415.23+$14,341.60
uniq_cust_0796BA45$15,638.30$347.52$1,415.23+$14,223.00
uniq_cust_1595SP39$14,754.90$378.33$1,415.23+$13,339.70
uniq_cust_1634RJ42$14,315.80$340.85$1,415.23+$12,900.60
🔬 Data Surgery: Real-World Ingestion Anomalies & Guardrails
Field / TableAnomaly ObservedTechnical FixStatus
customer_zip_code_prefix Leading zeros dropped by numeric parser (e.g. 01001 -> 1001) String conversion + regex zfill(5) Fixed (100%)
order_delivered_customer_date Null values on 219 rows Differentiated canceled (80) vs active in-transit (139) Partitioned
order_items.price Risk of $0 promotional items skewing margin calculations Hard filter price > 0 with data quality logging Passed
Timestamps (5 columns) Inconsistent string formats Coerced to unified ISO-8601 DATETIME objects Normalized
📦 Category Volume & Satisfaction Distribution
🎙️ Senior Data Engineering Interview Talking Points

1. Correlated Subquery vs. Window Functions (Complexity Trade-off)

"In Challenge 2, the specification mandated extracting the top 5 sellers per category without window functions. I implemented this using a correlated subquery counting how many sellers within the same partition had higher revenue. From an algorithmic standpoint, this incurs an O(N²) execution penalty because the inner query executes for every row. In production dbt pipelines, I replace this with DENSE_RANK() OVER (PARTITION BY category ORDER BY revenue DESC) which computes in O(N log N), allowing millions of rows to be ranked in seconds."

2. Storage Engine Strategy: OLTP (MySQL) vs. OLAP (DuckDB / Snowflake)

"Our pipeline supports both MySQL and DuckDB/SQLite. MySQL is optimal for transactional mutations—such as order status updates and payments requiring ACID guarantees. However, for analytical scans across millions of order items, a columnar engine like DuckDB avoids scanning unnecessary columns like product dimensions or seller addresses, reducing memory bandwidth by over 80%."

3. Automated Two-Way Data Integrity Verification

"Rather than relying on silent to_sql() execution, Phase 3 incorporates an automated verification harness that queries the live database using SELECT COUNT(DISTINCT pk) and asserts equality against len(df['pk'].unique()). This immediately catches schema truncation, silent primary key collisions, or silent network dropouts."