A production-style ETL pipeline transforming raw Brazilian e-commerce data into a PostgreSQL star schema warehouse, with clean staging, idempotent loads, structured observability, and a single-command orchestrator.
The raw Olist dataset is 9 separate CSV files with inconsistent naming, mixed data types, duplicate records, and no clear separation between source data and analytics-ready tables. This is a realistic representation of what raw data looks like in production environments.
The pipeline follows a classic multi-layer warehouse architecture: raw data stays immutable, a staging layer normalises and validates it, and the analytics layer builds the star schema from clean inputs.
wipe_all.pyextract.pyexplore.pyclean.pytransform.pyrun_all.py# Run the full pipeline in one command python -m etl.run_all # What run_all.py executes: 1. wipe_all → drop & recreate staging + analytics schemas 2. extract → download Kaggle ZIPs, validate CSVs, log row counts 3. clean → cast types, handle nulls, load staging schema 4. transform → build dim_* + fact_* tables in analytics schema # All steps: timed, logged, fail-fast
The analytics layer is a fully normalised star schema optimised for BI workloads. Surrogate keys, FK constraints, and date key mapping throughout. All tables are defined explicitly in SQL DDL, not inferred from Python.
dim_customer
│
dim_date ──────── fact_orders ──────── dim_product
│
dim_seller
fact_orders + 4 conformed dimensions → 1 star, 1 query path per metric| layer | tables |
|---|---|
| staging (cleaned 1:1 from raw, validated) | staging_customers, staging_orders, staging_order_items, staging_payments |
| fact (transactional grain, surrogate keys, FK integrity) | fact_orders, fact_order_items |
| dimension (conformed, reusable, date-key mapped) | dim_customer, dim_product, dim_seller, dim_date |
| ETL modules & orchestration | extract.py, explore.py, clean.py, transform.py, run_all.py, wipe_all.py, logger.py, db_config.py |
-- Example: fact_orders (simplified DDL) CREATE TABLE analytics.fact_orders ( order_key SERIAL PRIMARY KEY, order_id TEXT NOT NULL, customer_key INT REFERENCES dim_customer(customer_key), date_key INT REFERENCES dim_date(date_key), order_status TEXT, item_count INT, total_value NUMERIC(12,2) );
Each stage is an isolated Python module (extract, clean, transform), independently testable and replaceable. No monolithic scripts.
wipe_all.py drops and recreates all schemas before each run, guaranteeing clean, deterministic output with no duplicate rows.
All warehouse tables defined in explicit SQL DDL files, not inferred from pandas DataFrames. Schema is the source of truth, not Python.
Cross-platform ColorFormatter with UTF-8 detection, rotating file logs (no ANSI codes), emoji-safe console output, section banners, and timing decorators on every stage.
All DB credentials and input paths managed via .env and db_config.py. No hardcoded values anywhere in the codebase.
Validation at extract, clean, and transform stages. Row counts, schema checks, null counts, and dataset profiling via explore.py before any data reaches the warehouse.
| decision | reasoning |
|---|---|
| SQL-first modeling | Tables defined in .sql DDL files, not generated from Python types. Makes the schema auditable, reviewable, and portable. A recruiter or data analyst can read the schema without touching Python. |
| Idempotent wipe | Rather than upsert logic, the pipeline resets entirely on each run. Simpler to reason about, eliminates partial-load bugs, and makes the pipeline safe for scheduled execution. |
| Surrogate keys | All dimension and fact tables use surrogate integer keys (SERIAL) rather than natural keys from the source data. Decouples the warehouse from upstream source system changes. |
| Staging layer | Raw data is never written to directly by the analytics layer. The staging schema acts as a clean intermediate layer, validating and standardising before promotion to the warehouse. |
| Semantic naming | All warehouse tables and columns use business-readable names (dim_customer, order_status) rather than source system codes. Analytics teams can query without a data dictionary. |
python -m etl.run_allFor higher volumes the natural evolutions would be: PySpark to distribute the transform across executors when row counts pass ~10M; dbt on top of the warehouse for analyst-authored transformations and tested SQL models; Airflow or Prefect orchestration for scheduled runs with retry and alerting; SCD Type 2 dimensions with valid_from / valid_to columns to track customer attribute changes over time; incremental fact loads partitioned by order date to avoid full reloads; and migration tooling (Alembic, Flyway) for evolving the DDL safely instead of DROP + CREATE.
I'm currently looking for Data Engineer / Analytics Engineer roles. UK-based, open to remote or hybrid.
A 1M-row PySpark pipeline for synthetic banking transactions, with a validated star schema warehouse, deterministic SHA-256 surrogate keys, and idempotent re-runs on PostgreSQL.
read-case-studyThree-schema PostgreSQL warehouse on chocolate sales data, with raw, operational, and analytics layers and a full dimensional model.
read-case-study