Harbor & Pine Lakehouse

Case study · Data engineering & Power BI

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.

Tools
Python, Polars, Delta Lake, Power BI, DAX, PBIP / TMDL, Claude Code (agentic AI)
Data
Fictional 12-store coffee chain, Jan 2025 to Nov 2026
Deliverable
Lakehouse, daily pipeline, 3-page report
Built for
Operations leads and the data team
Sales page of the Harbor and Pine Power BI report
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.
3.3MSales lines processed
2,126Raw files ingested
4.4 sAverage daily run
1,965Bad rows quarantined

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.

LayerWhat lives thereKey techniques
LandingRaw CSV and JSON files exactly as the source systems send themFiles arrive daily; nothing is edited in place
BronzeOne Delta table per source, every value kept as textLoad-once file log, schema merge for new columns
SilverOne clean sales table, products, stores and weatherTwo layouts conformed, de-duplication by MERGE, quality rules, quarantine, type 2 product history
GoldStar schema: date, store and product dimensions, sales and store-day factsIncremental refresh of only the dates a run touched, file compaction and Z-ordering
OpsPipeline run log and quality check resultsEvery run, step time, row count and warning recorded, including failures

How I built it

  1. 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.
  2. 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.
  3. 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 sourceHow 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 rowsA 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 lateFlagged as late data, then the gold layer refreshes exactly the affected dates
An empty file and a missing store-dayA completeness check compares stores open each day with stores that reported sales
Product prices and names that change over timeMonthly 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 cityReadings 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

  1. 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.
  2. Promote mobile ordering on rainy daysCustomers already switch to the app when it rains; a rainy-day offer could recover some lost cafe visits.
  3. 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.
  4. 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 of the Harbor and Pine Power BI report

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 page: iced drink share by temperature and rainy-day sales

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 page: run history, quarantined rows and quality checks

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.

×
Power BI model view of the gold star schema and pipeline tables

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.

×