Sub topic 1
What the Medallion Architecture Is and Why It Exists
Prerequisites
This chapter assumes you know basic SQL (SELECT, JOIN, GROUP BY) and have used PySpark DataFrames. You should also know what a data lake is and how file formats such as JSON and Parquet differ. You should have seen a Databricks workspace and a notebook. You do not need to have built a pipeline yet.
The problem it solves
Raw data arrives messy. Files have missing keys, text where numbers belong, duplicate records, and columns that change without notice. If every report reads those files directly, each team cleans the data in its own way. Two dashboards then show two different revenue numbers, and nobody can say which one is right.
The medallion architecture is a way to organize data in a lakehouse into layers. Each layer has one job, and data moves through the layers in a fixed direction. The layers are called bronze, silver, and gold. Quality and business meaning increase as data moves from bronze to gold.
The three layers
| Layer | Holds | Typical operations | Main consumers |
|---|---|---|---|
| Bronze | Raw data as received, plus load metadata | Append only, no business logic | Data engineers |
| Silver | Cleaned, typed, deduplicated data | Casting, filtering, MERGE | Engineers, data scientists, analysts |
| Gold | Aggregates and marts shaped for a use case | Joins, GROUP BY, metrics | Dashboards, reports, applications |
Bronze
Bronze is the landing zone. You store data as close to the source as possible and add a few columns that record where and when it was loaded. You do not fix anything here. Because the raw record is kept, you can rebuild the later layers if a bug is found in your cleaning logic.
Silver
Silver is where data becomes trustworthy. You cast columns to proper types, drop rows that have no key, remove duplicates, and conform names and formats across sources. The result is one reliable version of each entity, such as orders or customers.
Gold
Gold is built for a specific business need. A table such as daily_revenue holds exactly the columns and grain that a dashboard needs. Gold tables are usually small, fast to query, and named in business terms.
How data flows
Data flows in one direction. A step reads from the layer before it and writes to the next. Nothing writes back upstream.
In Databricks, each layer is stored as Delta Lake tables. A Delta table is a table stored as Parquet files plus a transaction log, which gives you reliable writes and the ability to read earlier versions. The following chapters show how to build each step.
Why separate the layers
The layering gives you several practical benefits:
- Replay. If silver logic is wrong, fix it and rebuild from bronze. You do not need to ask the source system to resend data.
- Isolation of concerns. Ingestion, cleaning, and business logic each live in one place. A change to a business metric touches gold only.
- Incremental processing. Each layer can process only the rows that are new since the last run.
- Access control. You can give analysts access to gold while keeping raw data restricted.
- Debugging. When a number looks wrong, you can trace it back one layer at a time, down to the original source file.
What it is not
The names are a convention, not a product feature. Databricks does not enforce bronze, silver, or gold. You create the structure through your table design, schemas, and pipelines. Some teams add a layer between silver and gold, and some teams skip one for simple sources. The final chapter covers when that makes sense.
The layers are also not a promise of correctness by themselves. A silver table is only as clean as the rules you write for it. Data quality checks, covered later, are what turn the label into a guarantee.
Common mistakes
- Putting business logic in bronze. This makes the raw record unreliable and removes the ability to replay.
- Letting dashboards read silver directly for every metric. Each team then re-implements its own aggregation, which brings back the original problem.
- Treating the layers as a rigid rule. The pattern serves the goal of trustworthy, reusable data. It is not the goal itself.
Exercise
A source system sends an order with the amount "12.50" as text, and the same order is sent twice. In which layer do you keep both raw copies as received, and in which layer do you cast the amount to a decimal and remove the duplicate?
Show answer
Both raw copies stay in bronze, which is append-only and stores data as received. The cast to a decimal type and the deduplication happen in silver.
Exercise
A bug is found in your silver cleaning logic after three weeks of loads. Why does the medallion design make the fix easier than a single-step pipeline?
Show answer
Bronze still holds the raw records unchanged. You can correct the silver logic and rebuild silver and gold from bronze, without asking the source system to resend the data.