Harbor & Pine Lakehouse
A medallion lakehouse for a 12-store coffee chain: messy daily files from two till systems flow through bronze, silver and gold Delta tables on an incremental pipeline, with quality checks, a quarantine and a Power BI report that shows both the business and the health of the pipeline.

The ask
Harbor & Pine Coffee Co., a fictional chain of 12 coffee shops across Seattle, Bellevue, Tacoma, Portland and Spokane, runs two different till systems. Every night each one drops a file, along with a weather feed and a monthly product list, and the files are messy: different layouts, changing columns, re-sent and late files, and bad rows.
The goal was a lakehouse that loads those files automatically every day, fixes the known problems, holds back bad data instead of letting it reach a report, and gives leadership one trusted view of sales, the weather’s effect on demand and the health of the pipeline itself.
The architecture
The layout mirrors a Microsoft Fabric lakehouse: raw files land as-is, then three layers of Delta tables refine them, and the pipeline logs everything it does.
| Layer | What lives there | Key techniques |
|---|---|---|
| Landing | Raw CSV and JSON files exactly as the source systems send them | Files arrive daily; nothing is edited in place |
| Bronze | One Delta table per source, every value kept as text | Load-once file log, schema merge for new columns |
| Silver | One clean sales table, products, stores and weather | Two layouts conformed, de-duplication by MERGE, quality rules, quarantine, type 2 product history |
| Gold | Star schema: date, store and product dimensions, sales and store-day facts | Incremental refresh of only the dates a run touched, file compaction and Z-ordering |
| Ops | Pipeline run log and quality check results | Every run, step time, row count and warning recorded, including failures |
How I built it
- Step 1Generated realistic messy dataWrote a Python generator for 3.3 million sales lines across 2,126 files, with problems planted on purpose: two till layouts, a system migration, renamed and added columns, re-sent files, a late file, an empty file and invalid rows.
- Step 2Built the pipelinePython and Polars steps write Delta Lake tables layer by layer. An orchestrator runs land, bronze, silver, gold, maintenance and serve in order, times every step and logs the outcome. One full load, then 31 daily incremental runs.
- Step 3Built the Power BI reportA star-schema model over the gold layer with 32 DAX measures and three pages: sales, weather and pipeline health. Generated as a PBIP project with the model in TMDL, and checked against Microsoft's schemas.
Problems the pipeline handles
Every one of these was planted in the source data, and each one shows up in the pipeline's logs or on the Pipeline page of the report.
| Problem in the source | How the pipeline handles it |
|---|---|
| Two till systems with different layouts (dollars vs cents, ISO vs day-first dates, different store and item codes) | Each layout is mapped to one silver schema; one store switches systems mid-history and its sales continue unbroken |
| New and renamed columns (mobile ordering added a channel column; qty became quantity) | Bronze merges new columns into the table schema and logs the change; silver coalesces old and new names |
| Re-sent files and repeated rows | A Delta MERGE on the line key: 18,452 duplicate lines removed without double-counting a sale |
| Invalid rows (unknown product, zero quantity, negative price, missing store, bad timestamp) | Five quality rules; 1,965 failing rows go to a quarantine table with the reason, 0.06% of the total |
| A file that arrives six days late | Flagged as late data, then the gold layer refreshes exactly the affected dates |
| An empty file and a missing store-day | A completeness check compares stores open each day with stores that reported sales |
| Product prices and names that change over time | Monthly snapshots become a type 2 dimension, so each sale keeps the price and name in effect that day |
| A weather feed that sometimes reports Fahrenheit or drops a city | Readings are converted to Celsius and a coverage check flags the gap |
Built with an AI agent
I built this project with Claude Code working as an agent alongside me. I set the architecture and the requirements, and reviewed every layer and every page of the report.
- Pipeline as code: the generator, the four layers and the orchestrator are plain Python files, so the whole lakehouse can be rebuilt from nothing by running two scripts.
- Verified at every layer: silver and gold row counts match exactly (3,303,946 lines), net sales agree across both fact tables, and every report figure was checked against numbers calculated directly from the data.
- Report as code: the Power BI model and pages are generated as TMDL and PBIR files and validated against Microsoft's published schemas before Power BI opens them.
Ready for Microsoft Fabric
The design follows Fabric's lakehouse pattern on purpose. The tables are Delta Lake, the same open format OneLake stores, and every path comes from one config file, so moving the pipeline into a Fabric lakehouse means pointing that config at OneLake and running the steps as notebooks, with a Data Factory pipeline in place of the local orchestrator. In Fabric the serve step would disappear: Power BI would read the gold tables directly through Direct Lake.
What the report shows
- Same-store sales grew 7.3% in 2026 against the same dates in 2025, for the nine stores open the whole time.
- Heat drives the menu: iced drinks are about 16% of drinks below 10°C and about 65% above 25°C.
- Rain costs 9% of a store's daily sales, but drive-thrus sell slightly more on rainy days while cafes and kiosks sell less.
- Rain pushes customers to the app: mobile orders are 13.9% of transactions on rainy days against 10.7% on dry days.
- The data is trustworthy: only 0.06% of rows failed a quality rule, every run succeeded, and a daily run takes about 4 seconds.
Recommendations
- Plan staffing and stock around the forecastShift prep toward iced drinks when highs pass 20°C, and expect cafes to run quieter on rainy days.
- Promote mobile ordering on rainy daysCustomers already switch to the app when it rains; a rainy-day offer could recover some lost cafe visits.
- Fix the bad rows at the source84% of quarantined rows come from the Squarely tills; sharing the quarantine report with that vendor would cut them further.
- Move the pipeline into FabricThe design is Fabric-ready, so the next step is OneLake storage, scheduled notebooks and Direct Lake for the report.
Inside the report



Key pipeline code
Quality rules and the quarantine split, the MERGE that makes re-sent files harmless, the incremental gold refresh and the type 2 product lookup.
Show the Python
# silver.py: every rule is an expression that is True when a row FAILS it
RULES = [
("store_known", pl.col("store_id").is_null()),
("timestamp_valid", pl.col("sale_ts").is_null()),
("sku_known", ~pl.col("sku_ok")),
("quantity_nonzero", pl.col("quantity").is_null() | (pl.col("quantity") == 0)),
("price_positive", pl.col("unit_price").is_null() | (pl.col("unit_price") <= 0)),
]
# tag each row with the rules it breaks, then split good rows from bad ones
fails = pl.concat_list([pl.when(expr).then(pl.lit(name)) for name, expr in RULES]).list.drop_nulls()
df = df.with_columns(fails.alias("_failed"))
bad = df.filter(pl.col("_failed").list.len() > 0) # -> silver/sales_quarantine, with the reason
good = df.filter(pl.col("_failed").list.len() == 0)
# delta_io.py: a Delta MERGE on the line key, so a re-sent file updates rows instead of duplicating them
def upsert(df, path, keys):
pred = " AND ".join(f"s.{k} = t.{k}" for k in keys)
return (df.write_delta(path, mode="merge",
delta_merge_options={"predicate": pred, "source_alias": "s", "target_alias": "t"})
.when_matched_update_all().when_not_matched_insert_all().execute())
# gold.py: rewrite only the dates this run touched (Delta replaceWhere), not two years of history
df.write_delta(path, mode="overwrite",
delta_write_options={"predicate": f"sale_date >= '{lo}' AND sale_date <= '{hi}'"})
# gold.py: attach the product version that was current on the sale date (type 2 dimension)
fact = lines.join_asof(versions, left_on="sale_date", right_on="valid_from", by="sku", strategy="backward")
Sales page: net sales, transactions, ticket size, mobile share and same-store growth, with monthly sales against last year, sales by hour, product group and store.
×
Weather: iced drinks climb from about 16% of drinks below 10°C to about 65% above 25°C. Rain cuts sales at cafes and kiosks but lifts drive-thrus, and pushes more customers to mobile ordering.
×
Pipeline: 32 runs with a 100% success rate. Amber runs finished with a quality warning (a re-sent file, a missing store-day and a late file), and the quarantine shows which rules caught bad rows.
×
Model view: date, store and product dimensions filter the sales and store-day facts, and the pipeline run log links to its quality checks and quarantined rows.
×