Storing · Chapter 09
Medallion architecture on Databricks: bronze, silver and gold
Reviewed by TechFabric engineers. How we write this guide →
The medallion architecture is a way of organising a lakehouse into three layers of tables: bronze holds data exactly as it arrived from the source, silver holds it cleaned, typed, deduplicated and conformed to one business definition, and gold holds it shaped for a specific consumer such as a dashboard, a model or an API. On Databricks the layers are usually schemas in a Unity Catalog catalog, and the movement between them is a Lakeflow pipeline whose expectations enforce each layer's contract.
It's the most repeated pattern in the lakehouse world and also the most misapplied, usually because teams adopt the three names without the three contracts that make the names mean anything. This chapter is the contracts as we'd write them, the pipeline code that enforces them (Lakeflow pipelines, current as of October 2026), and the cases where we'd use fewer layers.
The short version
Data arriving from other systems is rarely fit to make decisions on. The medallion architecture handles that in three stages, each with a job. The first keeps an exact copy of what arrived, so that when you later find a mistake you can redo the work rather than asking a source system for history it no longer holds. The second turns that raw material into clean, agreed data, where a customer means one thing rather than four depending on who is asking. The third shapes the clean data for each use it has. The payoff is practical: when a number is wrong there's one place to look, and when a definition changes there's one place to change it.
What do bronze, silver and gold each promise? #
Each layer makes a specific promise to its consumers, and the promise decides what is allowed to happen in it. Reading them as three grades of cleanliness on a gradient is how the pattern goes wrong.
Bronze promises fidelity. It holds what the source system sent, as it sent it, with ingestion metadata attached and nothing else changed. If the source sent a malformed record, bronze holds the malformed record. The value of bronze is that it lets you reprocess history when you discover that a transformation was wrong, and that value evaporates the moment somebody starts cleaning data on the way in.
Silver promises correctness and conformance. Types are real types, keys are resolved, duplicates are handled, records that fail validation are quarantined rather than dropped silently, and entities from different sources are conformed onto a shared model. Silver is where the business's actual definition of a customer or a loan gets applied.
Gold promises fitness for a purpose. A gold table exists to serve a specific consumer, whether a dashboard, a model, or an API, and it is shaped for that consumer rather than for general use. Gold tables are allowed to be denormalised, redundant with each other, and narrow.
House rules #
These are the rules we hold to on any build, and the ones worth arguing for when an existing convention conflicts with them.
Bronze is append-only and never updated in place. Corrections happen by reprocessing into silver, not by mutating history.
Every bronze table carries ingestion metadata as a matter of course, minimally the source file or offset, the ingestion timestamp, and a batch or run identifier. This is what makes a reprocessing question answerable.
Nothing outside the platform team reads bronze. If a consumer needs bronze, that is a signal that silver is missing something, and the fix is to add it to silver rather than to grant access downward.
Validation failures in silver go to a quarantine table with the reason attached, and the quarantine table has an owner and an alert. A pipeline that silently drops a few percent of rows can do so for a year before anybody notices.
Gold tables declare their consumer in the table comment. When the consumer goes away, so does the table.
The contracts as pipeline code #
Lakeflow pipelines (formerly Delta Live Tables, and built on Apache Spark Declarative Pipelines) turn the first two rules into a few lines each, in SQL or Python. In SQL, bronze reads files as they land and stamps every row with where it came from and when, using the _metadata column the file reader exposes:
CREATE OR REFRESH STREAMING TABLE originations_dev.bronze.loan_application
COMMENT 'As received from the dealer portal export. Append only.'
AS SELECT
*,
_metadata.file_path AS _source_file,
current_timestamp() AS _ingested_at
FROM STREAM read_files('/Volumes/originations_dev/landing/loan_applications/', format => 'json');Silver declares its contract as expectations, and the quarantine table is the same rules inverted, so a row is always in exactly one of the two:
CREATE OR REFRESH STREAMING TABLE originations_dev.silver.loan_application (
CONSTRAINT has_id EXPECT (application_id IS NOT NULL) ON VIOLATION DROP ROW,
CONSTRAINT positive_amt EXPECT (requested_amount IS NOT NULL AND requested_amount > 0) ON VIOLATION DROP ROW
)
AS SELECT * FROM STREAM(originations_dev.bronze.loan_application);
CREATE OR REFRESH STREAMING TABLE originations_dev.silver.loan_application_quarantine
AS SELECT *,
CASE WHEN application_id IS NULL THEN 'missing id' ELSE 'missing or non-positive amount' END AS _reason
FROM STREAM(originations_dev.bronze.loan_application)
WHERE NOT (application_id IS NOT NULL AND requested_amount IS NOT NULL AND requested_amount > 0);The Python API does the same with the pipelines module, which Databricks now recommends over the older dlt import. Its advantage for this pattern is that the rules live in one dictionary, so the expectations and the quarantine filter can't drift apart:
from pyspark import pipelines as dp
from pyspark.sql import functions as F
RULES = {
"has_id": "application_id IS NOT NULL",
"positive_amt": "requested_amount IS NOT NULL AND requested_amount > 0",
}
QUARANTINE = "NOT ({})".format(" AND ".join(f"({rule})" for rule in RULES.values()))
@dp.table(name="originations_dev.bronze.loan_application",
comment="As received from the dealer portal export. Append only.")
def bronze_loan_application():
return (spark.readStream.format("cloudFiles")
.option("cloudFiles.format", "json")
.load("/Volumes/originations_dev/landing/loan_applications/")
.select("*",
F.col("_metadata.file_path").alias("_source_file"),
F.current_timestamp().alias("_ingested_at")))
@dp.table(name="originations_dev.silver.loan_application")
@dp.expect_all_or_drop(RULES)
def silver_loan_application():
return spark.readStream.table("originations_dev.bronze.loan_application")
@dp.table(name="originations_dev.silver.loan_application_quarantine")
def silver_loan_application_quarantine():
return spark.readStream.table("originations_dev.bronze.loan_application").where(QUARANTINE)@dp.table over a streaming read creates a streaming table; @dp.materialized_view is the decorator for a batch-defined gold aggregate. One pipeline can mix SQL and Python files.
Two things to watch in either shape. The inverted condition must stay in step with the expectations, which is why we'd keep both in one file or one dictionary. And write every condition so it can never evaluate to NULL, which is why the amount check spells out IS NOT NULL: in SQL, NOT (requested_amount > 0) is NULL when the amount is missing, so a quarantine filter written that way quietly skips exactly the rows it exists to catch. Databricks' expectations page doesn't say how a NULL result is counted, so don't rely on either behaviour.
Expectation metrics land in the pipeline event log, which is where we'd hang the quarantine alert. With the event log published to a table (pipeline settings, Advanced), the pass and fail counts per rule are one query:
SELECT e.dataset, e.name AS expectation,
SUM(e.passed_records) AS passed, SUM(e.failed_records) AS failed
FROM (
SELECT explode(from_json(details:flow_progress:data_quality:expectations,
'array<struct<name: string, dataset: string, passed_records: bigint, failed_records: bigint>>')) AS e
FROM originations_dev.ops.loan_pipeline_event_log
WHERE event_type = 'flow_progress'
AND timestamp >= current_timestamp() - INTERVAL 24 HOURS
)
GROUP BY e.dataset, e.name
ORDER BY failed DESC;Silver from a change feed #
When bronze holds a change log from a database rather than files, silver is current state, and AUTO CDC builds it without a hand-written MERGE. In Python:
from pyspark import pipelines as dp
from pyspark.sql import functions as F
dp.create_streaming_table("originations_dev.silver.dealer")
dp.create_auto_cdc_flow(
target="originations_dev.silver.dealer",
source="originations_dev.bronze.dealer_changes",
keys=["dealer_id"],
sequence_by=F.col("commit_lsn"),
apply_as_deletes=F.expr("operation = 'DELETE'"),
except_column_list=["operation", "commit_lsn"],
stored_as_scd_type=2,
)stored_as_scd_type=2 keeps history with validity ranges, which suits a dimension like dealer; 1 keeps only the latest row. The ordering and late-arrival reasons to prefer this over MERGE are in Real-time and CDC.
What we saw: testing the promotion from bronze to silver #
Ihor Seleznov, an engineer at TechFabric, wrote up how he tests the bronze-to-silver step with PyTest inside Databricks notebooks (Using PyTest for data quality checks). He runs the same family of checks twice. Against bronze they are expected to fail, and their job is to say exactly what is wrong and how many rows it affects: nulls, wrong types, duplicate keys, out-of-range values, bad emails, missing countries. That report is what decides the cleansing logic. Against silver, after the cleansing runs, near-identical checks have to pass, which is the evidence that the promotion did what it claimed. Each check is a function with a business-readable failure message, and fixtures share the setup between them.
What we'd take from it for the layer contracts is the pairing. A bronze check that counts failures is a specification for silver; a silver check that passes is the proof. Kept together in the repository and run in CI, the two make the silver contract something a reviewer can read, alongside the pipeline expectations above that enforce it at run time.
How this maps onto catalogs and schemas #
We'd use schemas within a domain catalog for the layers, so a table's full name reads as originations_prd.silver.loan_application. This keeps the layer visible in every query and every error message, and it lets grants follow the layer naturally, since the reader group for a domain typically gets SELECT on gold and nothing else. The mechanics of that grant model are covered in Unity Catalog.
For domains that have matured into data products with independent teams and release cycles, gold splits into a schema per product. That is a scaling decision rather than an architectural one, made when the shared schema gets confusing rather than on principle.
Building the same three layers on each platform
| Concern | Databricks | AWS | Azure | GCP |
|---|---|---|---|---|
| Layer storage | One table format across all three layers | S3 plus Glue Data Catalog, often with Redshift for gold | ADLS plus Synapse, often with a dedicated SQL pool for gold | Cloud Storage for bronze, BigQuery for silver and gold |
| Moving between layers | One declarative pipeline framework spanning all layers | Glue jobs, EMR, or Step Functions per hop | Data Factory or Synapse pipelines per hop | Dataflow or Dataproc into BigQuery |
| Quality rules | Expectations declared in the pipeline, metrics emitted | Glue Data Quality on Glue tables | Data Factory data flow assertions | Dataplex quality scans, configured separately |
| Governance across layers | One permission model over every layer | Lake Formation for the lake, Redshift grants for the warehouse | Purview plus Synapse plus storage ACLs | BigQuery IAM plus Cloud Storage IAM |
| Lineage across layers | Captured automatically, column level | Glue lineage in DataZone, partial | Purview lineage, partial for custom code | Dataplex lineage, partial |
| Replay from bronze | Time travel on the same table | Rebuild from S3, no table history unless you added Iceberg or Hudi | Rebuild from ADLS, same caveat | Rebuild from Cloud Storage, same caveat |
The other platforms can plainly build a medallion architecture, and many organisations have. The difference is where the seams fall. On the cloud-native stacks the layers usually sit in different services with different permission models and different lineage stories, so the boundaries between layers are also boundaries between products, and keeping governance consistent across them is ongoing work somebody owns. On Databricks the layers are schemas in one catalog with one permission model, and the boundaries are conventions you enforce rather than integrations you maintain.
Beyond the basics #
The capabilities below are what make the pattern cheap to operate rather than merely tidy, and they are the part of it least often switched on.
Replay is a design property, not a hope. Because every layer is a Delta table with a transaction log, you can rebuild a downstream table from an exact upstream version rather than from whatever the upstream happens to look like now. Reading bronze.events VERSION AS OF 41822 in a rebuild makes the result reproducible, which turns "we reran it and got a different number" into a solvable problem. Bronze retention properties, delta.logRetentionDuration and delta.deletedFileRetentionDuration, are what determine how far back that ability extends, so they are worth setting explicitly per layer rather than inheriting.
Change data feed moves only what changed. Enabling delta.enableChangeDataFeed on a silver table lets gold consume inserts, updates, and deletes as a stream rather than recomputing an aggregate over the whole table. On a wide silver table feeding several gold aggregates this is frequently the single largest compute saving available, and it is one line of table properties.
Deletions have to cross the layers. An erasure request under GDPR or a similar regime is where bronze fidelity and legal obligation pull against each other. The practical approach is to keep the identifier that links a subject across layers, delete in silver and gold, and either delete or pseudonymise in bronze depending on your legal position. Deletion vectors make the delete cheap, since rows are marked rather than rewritten. What matters is that the procedure exists and has been tested before somebody asks for it.
Governance at the boundary, not more tables. Teams often fork a gold table into three variants because three audiences see different subsets. Row filters and column masks in Unity Catalog let one table serve all three, applied at query time by group membership, and one filtered table is easier to keep correct than three that drift.
Gold does not have to stay inside the platform. A gold table can be shared to another organisation through OpenSharing without copying it, synced into Lakebase for low-latency application reads, or served to a model endpoint. Where gold is really a set of business metrics, a metric view defines them once over silver so every dashboard and Genie Agent computes revenue the same way. Treating gold as the publication boundary rather than the last stop is what makes the rest of the estate simple, and the consumption side of that is covered in Reporting, Semantics, and Power BI.
The layers want different physical treatment. Bronze is append-heavy and read rarely, so it wants large files and long retention. Silver is merge-heavy and benefits most from liquid clustering on the join and filter keys. Gold is read constantly by dashboards and wants clustering on the columns those dashboards filter on. Predictive optimization handles the maintenance on managed tables, as covered in Tables and storage.
How many layers does a domain need? #
The three-layer default is a starting point. Decide per domain from four questions, written into the domain's README so the next team inherits the reasoning along with the schemas.
| Question about the domain | If yes | If no |
|---|---|---|
| Does more than one source describe the same entity? | Silver is where they conform; keep it | Silver may be a thin typed view over bronze |
| Could a source fail to give you history again? | Bronze must keep the raw record, with long retention | Bronze retention can be short |
| Do several consumers need different shapes? | One gold table per consumer | A single gold table, or read silver directly |
| Is any of it personal data subject to erasure? | Design the delete path across all three layers before the first load | Standard retention is enough |
A worked case shows how the answers move the design. A loan servicing domain fed by a core banking extract and a CRM, both describing the borrower, consumed by a finance dashboard and a risk model, and holding personal data, answers yes to all four: it gets all three layers, two gold tables, and a tested erasure path. A domain holding one vendor's exchange-rate feed, read by one report, answers no to three of them, and we'd give it a bronze table and a single gold view, with the fidelity promise kept in bronze.
When not to use three layers #
A domain with one source, no conformance work, and a single consumer does not need three layers, and forcing them produces two tables that are copies of each other plus a maintenance burden. We'd be comfortable with a two-layer domain as long as the fidelity promise of bronze is preserved somewhere.
Equally, some domains need a fourth concept, usually a reference or dimension schema shared across layers, or a features schema serving model training. Adding one is fine. What is not fine is having the same table exist twice under different names because two teams disagreed about which layer it belonged in.
What's popular