ADE Delta Lake and Medallion

A plain data lake stores files cheaply, yet files alone cannot update a row, undo a mistake, or protect readers from half-finished writes. Delta Lake adds those missing powers. The Medallion pattern then organizes Delta tables into clear quality layers. Together they form the backbone of a modern lakehouse on Azure.

What Delta Lake Adds

A Delta table is a folder of Parquet files plus a transaction log stored in a hidden folder named _delta_log. The log records every change as a numbered entry. Readers consult the log to learn which files belong to the current version of the table.

sales_table/
   part-0001.parquet
   part-0002.parquet
   part-0003.parquet
   _delta_log/
        00000000000000000000.json   (version 0: created table)
        00000000000000000001.json   (version 1: added rows)
        00000000000000000002.json   (version 2: updated rows)

Key Delta Features

  • ACID transactions: A write either finishes completely or leaves no trace. Readers never see half-written data.
  • Time travel: Query any earlier version of the table.
  • Schema enforcement: Delta rejects rows that break the table definition.
  • Updates and deletes: UPDATE, DELETE, and MERGE work directly on lake data.
  • Batch and streaming in one table: The same table accepts both write styles.

Time Travel in Action

An analyst deletes the wrong rows at 10 AM. Time travel rescues the data in seconds.

-- See the history
DESCRIBE HISTORY sales;

-- Read the table as it looked at version 5
SELECT * FROM sales VERSION AS OF 5;

-- Restore the table to that version
RESTORE TABLE sales TO VERSION AS OF 5;

Think of a document with a full edit history. Any earlier draft returns with one click.

Upserts with MERGE

MERGE INTO sales AS target
USING new_sales AS source
  ON target.sale_id = source.sale_id
WHEN MATCHED THEN UPDATE SET *
WHEN NOT MATCHED THEN INSERT *;

Medallion Architecture

Medallion architecture sorts data into three layers named after medals. Data climbs from raw to refined, and each layer promises a higher level of quality.

SOURCES            BRONZE               SILVER               GOLD              USERS
                (raw copy)         (cleaned, joined)    (business-ready)

Apps      --->  +----------+       +-------------+      +--------------+
Files     --->  | Delta    | --->  | Delta       | ---> | Delta        | ---> Power BI
Streams   --->  | as-is    |       | validated   |      | aggregated   |      Data science
                +----------+       +-------------+      +--------------+
LayerContentTypical WorkReaders
BronzeRaw data exactly as receivedIngest and add load timeData engineers
SilverCleaned, deduplicated, typed dataFix types, remove duplicates, join sourcesEngineers and data scientists
GoldBusiness tables and summariesAggregate and shape for reportsAnalysts and executives

Scenario: TuneNest Music App

TuneNest, a fictional music app, logs every song play as a JSON event.

Bronze

Event Hubs Capture and ADF drop raw play events into a bronze Delta table. Corrupt records stay untouched for later review.

Silver

A Spark job removes duplicate events, converts timestamps to a proper type, and joins song details. The silver table holds trustworthy play records.

Gold

Another job counts plays per song per day and per country. Power BI reads this small gold table, and dashboards load in seconds.

silver = (spark.read.format("delta").load("/lake/silver/plays")
          .groupBy("play_date", "country", "song_id")
          .count()
          .withColumnRenamed("count", "play_count"))

silver.write.format("delta").mode("overwrite").save("/lake/gold/daily_plays")

Schema Enforcement and Evolution

Delta protects table shape. A write with an unexpected column or a wrong type fails with a clear message, and the table stays safe. Teams sometimes want a new column on purpose. The mergeSchema option allows that controlled change.

(new_plays.write
          .format("delta")
          .mode("append")
          .option("mergeSchema", "true")
          .save("/lake/silver/plays"))

Enforcement acts like a security guard at the door of the table. Evolution acts like a signed permission slip that lets a new column enter.

Streaming into Delta

A Delta table accepts streaming writes and batch reads at the same time. A stream can feed bronze continuously while analysts query the same table with plain SQL. The transaction log keeps both groups consistent, so nobody reads a half-written file.

Maintenance Commands

  • OPTIMIZE: Merges many small files into fewer large ones for faster reads.
  • VACUUM: Deletes old files that no table version needs, which frees storage. The default retention is seven days, and shorter periods remove the ability to travel back.

Why Layers Help

  • A bug in a silver job never damages bronze, so a rerun repairs everything.
  • Each layer has one clear owner and one clear promise.
  • Reports read gold tables and never touch messy raw data.

Key Points

  • Delta Lake adds transactions, history, and updates to plain Parquet files.
  • Time travel restores earlier versions after mistakes.
  • Medallion architecture moves data through bronze, silver, and gold layers.
  • OPTIMIZE and VACUUM keep Delta tables fast and tidy.