Personal project · 2026
Azure lakehouse, Bronze to Gold
The pattern I used at Molina, rebuilt on Synthea synthetic patient data: metadata-driven ingestion, a quarantine for bad rows, SCD Type 2 history and Gold tables, governed by Unity Catalog.
- Role
- On my own
- When
- 2026
- Type
- Personal project
- Stack
- Azure Databricks, Delta Lake, Unity Catalog, Terraform
Synthea synthetic patient CSVs land in a container; the bronze job keeps them as landed with lineage columns, the silver job types, de-duplicates and runs checks, sending failing rows to a quarantine table with the checks they failed and failing the run above 5% bad rows. The gold job builds an SCD Type 2 patient dimension, a liquid-clustered claim-lines fact and a monthly rollup. Everything sits in Unity Catalog, reached through a managed identity, and is deployed with two Terraform stages and a Databricks Asset Bundle.
How it works
- Sources are config, not code: columns, types, keys and data-quality rules for each source live in one YAML file.
- Bronze lands each file as it arrived, with lineage columns, and skips batches it has already loaded.
- Silver types and de-duplicates (latest row per key) and runs the checks. Rejected rows go to a quarantine table with the checks they failed.
- Gold builds an SCD Type 2 patient dimension, a liquid-clustered claim-lines fact and a monthly rollup.
Keeping it safe
- Names and SSNs never enter the lake: Bronze keeps only the columns declared in config.
- Storage keys are disabled. Unity Catalog reaches ADLS Gen2 through the access connector's managed identity.
- Two Terraform stages (Azure, then Unity Catalog) plus a Databricks Asset Bundle deploy it, with a monthly budget alert.
A decision worth explaining
Liquid clustering on the fact table instead of a date partition plus Z-ORDER: no small-file problem, and the clustering keys can change later without rewriting the table.
Status
9 tests run on local Spark in CI, including an end-to-end bronze to gold run and SCD2 with two changes on the same day. It isn't deployed to Azure yet.
From the code
Silver in three steps: standardize types, keep the latest row per business key so replays are safe, then split passed rows from quarantined ones.
def latest_per_key(df: DataFrame, key) -> DataFrame:
"""Keep the most recently ingested row per business key, so replays are safe."""
w = Window.partitionBy(*key).orderBy(F.col("_ingested_at").desc(), F.col("_batch_id").desc())
return df.withColumn("_rn", F.row_number().over(w)).where("_rn = 1").drop("_rn")
def apply_expectations(df: DataFrame, source: Source) -> Tuple[DataFrame, DataFrame]:
"""Split rows into (passed, quarantined). Quarantined rows list the checks they failed."""
checks = [F.when(~F.coalesce(F.expr(e["rule"]), F.lit(False)), F.lit(e["name"])) for e in source.expectations]
failed_list = F.filter(F.array(*checks), lambda x: x.isNotNull()) if checks else F.array().cast("array<string>")
flagged = df.withColumn("_failed_checks", failed_list)
passed = flagged.where(F.size("_failed_checks") == 0).drop("_failed_checks")
failed = flagged.where(F.size("_failed_checks") > 0)
return passed, failed
def to_silver(bronze: DataFrame, source: Source) -> Tuple[DataFrame, DataFrame]:
std = standardize(bronze, source)
dedup = latest_per_key(std, source.silver_key)
return apply_expectations(dedup, source)# Metadata that drives every layer. Adding a source = adding an entry here.
# Columns follow the Synthea CSV export (synthetic patients — no real PHI).
sources:
claims:
file: claims.csv
key: [Id]
columns: [Id, PATIENTID, PROVIDERID, PRIMARYPATIENTINSURANCEID, SERVICEDATE, STATUS1, OUTSTANDING1, DIAGNOSIS1]
types: {SERVICEDATE: timestamp, OUTSTANDING1: "decimal(12,2)"}
rename: {Id: claim_id, PATIENTID: patient_id, PROVIDERID: provider_id, PRIMARYPATIENTINSURANCEID: payer_id, SERVICEDATE: service_ts, STATUS1: status, OUTSTANDING1: outstanding, DIAGNOSIS1: primary_diagnosis}
expectations:
- {name: claim_id_present, rule: "claim_id IS NOT NULL"}
- {name: patient_linked, rule: "patient_id IS NOT NULL"}
- {name: service_date_present, rule: "service_ts IS NOT NULL"}
- {name: outstanding_not_negative, rule: "outstanding IS NULL OR outstanding >= 0"}