Sub topic 1
What the Medallion Architecture Is and Why It Exists
Prerequisites.
This chapter assumes basic SQL, PySpark DataFrame use, and familiarity with data lakes, JSON, Parquet, Databricks notebooks, and Unity Catalog. A lakehouse combines low-cost data-lake storage with warehouse features such as reliable tables and SQL access.
Medallion architecture
The medallion architecture organizes data into layers with increasing structure and business meaning:
| Layer | Main purpose | Typical contents |
|---|---|---|
| Bronze | Preserve what arrived | Raw records and ingestion metadata |
| Silver | Clean and standardize | Typed, validated, deduplicated records |
| Gold | Serve business needs | Aggregates, marts, and reporting tables |
Data usually flows from bronze to silver to gold. The layers provide clear boundaries. Engineers can replay transformations from preserved source data, while analysts can use gold tables without understanding ingestion details.
The pattern is a design convention, not a requirement. A small dataset may need only one or two tables. Extra layers add storage, processing, and operational work.
Delta Lake tables: the foundation
Each layer commonly uses a Delta Lake table, a table format that stores data files with a transaction log. The log records committed changes and supports features such as ACID transactions, schema enforcement, time travel, and reliable concurrent reads and writes.
Delta tables make the layers dependable. A failed write does not expose a partially committed table, and a later transformation can read a consistent version. Delta does not automatically make messy data clean; it provides the storage and transaction foundation for applying those rules.
Laying out layers in Unity Catalog
Unity Catalog organizes objects as catalog.schema.table. One simple layout uses a catalog named main and a schema for each layer:
main.bronze.ordersmain.silver.ordersmain.gold.daily_revenue
This layout separates permissions and clarifies ownership. Data engineers might write to bronze and silver, while analysts receive read access to gold. Use names that reflect data ownership and business boundaries when one catalog contains several domains.
Bronze: land raw data and keep it replayable
Bronze should preserve the source shape as much as practical. Add operational columns such as ingestion time and source file. Avoid business corrections here. If a source sends a malformed amount or duplicate order, retain the record and handle it downstream.
For file ingestion, Auto Loader discovers new files and Structured Streaming uses a checkpoint to remember progress:
from pyspark.sql import functions as F
raw = (
spark.readStream.format("cloudFiles")
.option("cloudFiles.format", "json")
.option("cloudFiles.schemaLocation", "/Volumes/main/sales/checkpoints/orders_schema")
.load("/Volumes/main/sales/landing/orders/")
.withColumn("_ingested_at", F.current_timestamp())
.withColumn("_source_file", F.col("_metadata.file_path"))
)
(
raw.writeStream
.option("checkpointLocation", "/Volumes/main/sales/checkpoints/orders_bronze")
.trigger(availableNow=True)
.toTable("main.bronze.orders")
)The checkpoint is part of the pipeline state. Keep it separate from the table and protect both from accidental deletion.
Exercise
Why should bronze retain an invalid source record instead of dropping it immediately?
Show answer
Retaining it preserves an auditable copy and allows improved validation or transformation logic to replay the data later.