Medallion architecture without overengineering

Medallion is three jobs that fit in one database. Bronze keeps the raw data untouched, silver fixes types and repeats and keeps bad rows in a rejects table, gold holds the tables a report reads. Start with three schemas, in one database or one lakehouse. Add workspaces only when different people own a layer or its security differs.

Get the project

Starting out · ·

The problem

You copy a medallion diagram and end up with three lakehouses, three workspaces and a pipeline between each pair. Nobody can say which layer holds the right number. This Pattern is for data engineers who want the smallest medallion that still keeps the raw data, cleans it and serves the report.

Steps

One database with three schemas: bronze for raw text, silver rebuilt from bronze with a rejects table, gold rebuilt from silver.

The three jobs as three schemas. Add workspaces only when owners or security differ.

The code below is the project’s own SQL, run on DuckDB 2.0.1. Spark SQL uses other function names for parsing, so adapt it before using it on Spark.

  1. Write down what may change in each layer. Bronze: nothing, new files are only appended. Silver: rebuilt from bronze on every run. Gold: rebuilt from silver. This is the whole architecture; the schemas just give each job a place.

  2. Bronze: land the file as text and add lineage. Read every column as text, so a bad value cannot fail the load. Add the file name, a batch id (a hash of the file content), a batch number and the load time. A file that is already in bronze is skipped, so a retry cannot duplicate it.

    CREATE TABLE IF NOT EXISTS bronze.orders (
        order_id VARCHAR, order_date VARCHAR, amount VARCHAR, country VARCHAR,
        _source VARCHAR, _batch_id VARCHAR, _batch_seq INTEGER, _loaded_at TIMESTAMP
    );
    
    INSERT INTO bronze.orders
    SELECT order_id, order_date, amount, country, ?, ?, ?, now()
    FROM read_csv(?, header = true, all_varchar = true);
    

    The four ? are the file name, the batch id, the batch number and the path. In the project they are bound from Python in load_bronze.

  3. Silver, part one: parse every row and name the first rule it breaks. Trim text, accept two date formats, turn the comma decimal into a point, cast to real types with TRY_CAST so a bad value becomes NULL instead of an error.

    CREATE OR REPLACE TEMP TABLE parsed AS
    WITH typed AS (
        SELECT *,
            TRY_CAST(trim(order_id) AS INTEGER) AS id_i,
            COALESCE(try_strptime(trim(order_date), '%Y-%m-%d'),
                     try_strptime(trim(order_date), '%d/%m/%Y'))::DATE AS date_d,
            TRY_CAST(replace(trim(amount), ',', '.') AS DECIMAL(10,2)) AS amount_d,
            NULLIF(upper(trim(country)), '') AS country_u
        FROM bronze.orders
    )
    SELECT *,
        CASE
            WHEN id_i IS NULL THEN 'order_id is not an integer'
            WHEN date_d IS NULL THEN 'order_date is not yyyy-mm-dd or dd/mm/yyyy'
            WHEN amount_d IS NULL THEN 'amount is missing or not a number'
            WHEN amount_d <= 0 THEN 'amount is not positive'
            WHEN country_u IS NULL THEN 'country is missing'
        END AS reject_reason
    FROM typed;
    
  4. Silver, part two: keep good rows once, keep bad rows with their reason. The good rows get one row per order_id, newest batch first. The bad rows go to orders_rejected with their raw text, so nothing disappears.

    CREATE OR REPLACE TABLE silver.orders AS
    SELECT id_i AS order_id, date_d AS order_date, amount_d AS amount,
           country_u AS country, _source, _batch_seq
    FROM parsed
    WHERE reject_reason IS NULL
    QUALIFY row_number() OVER (
        PARTITION BY id_i ORDER BY _batch_seq DESC, amount_d DESC, country_u
    ) = 1;
    
    CREATE OR REPLACE TABLE silver.orders_rejected AS
    SELECT order_id, order_date, amount, country, reject_reason, _source, _batch_id
    FROM parsed
    WHERE reject_reason IS NOT NULL;
    
  5. Gold: one table for the question the report asks. Build it from silver only.

    CREATE OR REPLACE TABLE gold.sales_by_country AS
    SELECT country, count(*) AS orders, sum(amount) AS revenue
    FROM silver.orders
    GROUP BY country
    ORDER BY country;
    
  6. Prove it with counts, then run everything twice. Every bronze row must be in exactly one place: kept, rejected, or replaced by a newer version (or an exact repeat) of the same order. After day 1 the project reports 10 = 4 + 5 + 1. After day 2 it reports 13 = 6 + 5 + 2. Running both files again skips them and leaves all four tables identical.

  7. The same silver as a materialized lake view in Fabric. Adapted from the syntax on Microsoft’s reference page; the names are placeholders and the SQL assumes Spark SQL.

    -- Needs a schema-enabled lakehouse. Test it in your own lakehouse.
    CREATE MATERIALIZED LAKE VIEW IF NOT EXISTS silver.orders
    (
        CONSTRAINT positive_amount CHECK (amount > 0) ON MISMATCH DROP
    )
    AS SELECT
        CAST(order_id AS INT) AS order_id,
        CAST(amount AS DECIMAL(10,2)) AS amount,
        upper(trim(country)) AS country
    FROM bronze.orders;
    

    What the documentation says about it: Fabric works out the refresh order from the view definitions, and it chooses between an incremental, a full and a skipped refresh. ON MISMATCH DROP silently removes the row; the other option, FAIL, stops the refresh. The pages describe violation counts in lineage, not a table of dropped rows. If you need the rows, keep a rejects table as in step 4.

    Status on 2026-11-29: SQL-defined materialized lake views are generally available. Microsoft’s Azure blog post on FabCon and SQLCon 2026, dated 18 March 2026, says so, and Learn’s “What’s new” lists them as generally available under September 2026. The two dates were not reconciled. PySpark authoring and REFRESH_HINT are marked preview on the Learn pages. Lakehouse schemas are generally available according to Microsoft’s Fabric Updates blog; the Learn page for them carries no preview label.

  8. Start with two layers, split when a reason appears. The project’s run_two_layers builds bronze and gold only. The typed table and the rejects table live in gold, and the gold table comes out the same as in the three-layer run. Moving them to a silver schema is a change of schema name. Split when one of these is true:

    • different people own the raw data and the reporting tables;
    • raw data has security rules that reports do not share;
    • gold needs a different refresh schedule from silver;
    • two or more gold tables reuse the same cleaned data.

The project

Get the project

medallion-minimal is a small Python and DuckDB project with synthetic data. It holds two order files, the pipeline above in medallion.py, a demo, and 18 tests. It needs no account and no cloud.

python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
python demo.py && python -m pytest -v

What the recorded run showed (full output in RUN_LOG.txt inside the project):

  • Day 1: bronze held 10 rows. Silver kept 4, the rejects table held 5 with one reason each, and 1 row was an exact repeat.
  • Day 2: a corrected amount for order 2 replaced the old one. Bronze held 13 rows: 6 kept, 5 rejected, 2 replaced. Gold: ES 3 orders and 174.50, FR 2 orders and 42.25, PT 1 order and 22.40.
  • Rerun: both files were skipped and all four tables were identical to before.
  • The two-layer version produced the same gold table.

Terminal output of the demo and the test summary.

Real output of python demo.py and the test summary, DuckDB 2.0.1, 2026-11-29. Silver rows and file-load details shortened.

Copy this prompt

Use this to sketch a small medallion for your own data sources. Paste it into your assistant’s chat with the engine, row key and question your report needs to answer. Ask for a three-layer design and draft SQL for cleaning, recording rejects and checking that all source rows are accounted for.

Design the smallest medallion for these sources: <list of sources>.
One database or lakehouse, three schemas: bronze, silver, gold.
For each layer say what is allowed to change.
Write the SQL for silver: cast types, one row per <key column>,
and a rejects table that keeps the raw values and the reason.
Write one gold table that answers <report question>.
Add a test that every bronze row is kept, rejected or replaced,
and a test that runs the load twice and changes nothing.
Say which extra layers, lakehouses or workspaces I do NOT need yet.
Target engine: <DuckDB | Spark SQL | other>.

Check the answer for three things: bronze is never edited, bad rows land in a table with a reason, and gold reads from silver only.

Test result

The DuckDB exercise reconciled input rows with valid, rejected and superseded records. The project log shows the counts by layer.

Limits

  • Microsoft’s page recommends more than this Pattern starts with. It says to keep each layer in its own lakehouse and recommends a separate workspace for each, for control and governance at layer level. One lakehouse with three schemas is a smaller first step, not a replacement. Split when the checklist in step 8 says so.
  • Full rebuild on every run. Silver and gold are rebuilt from scratch. That is fine for thousands of rows. For large tables, load increments instead (see Pattern 06).
  • Two date formats only. 01/02/2026 is read as 1 February, never as 2 January. The format list is a contract with the source.
  • Rounding. Amounts are cast to two decimals, so 10.456 becomes 10.46 without a reject.
  • Newest batch wins. That is a rule of this project, not of medallion. Within one batch, ties are broken by amount and country so the result is repeatable.
  • A rejected row stays rejected. If a later file brings a fixed version of that order, the old row remains in the rejects table. Filter it out when you report open rejects.
  • Materialized lake views have their own limits. Per Microsoft’s reference page: no INSERT, UPDATE or DELETE on a view, no user-defined functions or temporary views in its query, and no Delta time travel. Incremental refresh needs Delta change data feed enabled on the source tables; without it the choice is full refresh or skip.
  • Delta tables need maintenance. History grows. VACUUM cannot remove files from the last seven days by default, and the property delta.deletedFileRetentionDuration changes that period. Many small files slow reads; Microsoft’s guidance targets files between 128 MB and 1 GB. For new bronze tables partitioning is acceptable but discouraged, and for silver and gold Liquid Clustering is preferred over partitioning.
  • Fabric sources. If the raw data already lives in OneLake, ADLS Gen2, Amazon S3 or Google storage, Microsoft says to create a shortcut in bronze instead of copying it.
  • Not covered. A warehouse as the gold layer (the second deployment pattern on Microsoft’s page), streaming, and row-level security.

Sources

Author

Rodrigo Lombana Reina, data engineer. Personal opinions. Checked against the documentation on 2026-11-29.

Questions

What is medallion architecture?

A way to organise data in three steps: bronze stores data exactly as it arrived, silver fixes errors, formats and duplicates, gold shapes tables for reports. Microsoft Fabric's documentation calls it the recommended design approach. The layers describe what may change at each step, so they do not need three separate systems.

How many lakehouses do I need for a medallion architecture in Fabric?

Microsoft's page recommends one lakehouse per layer, each in its own workspace, for control and governance at layer level. It also says all lakehouses can sit in one workspace. A smaller start is one schema-enabled lakehouse with bronze, silver and gold schemas, split later when owners or security differ.

Should I clean data in the bronze layer?

No. Bronze stores data as it arrived, and Fabric's medallion page says no changes are allowed there. Keep the original text and add source, batch and load time. If bronze is edited, you lose the source of truth and cannot rebuild silver. The project's tests check that bronze keeps raw values such as a comma decimal.

What should I do with bad rows in the silver layer?

Write them to a rejects table with their raw values and the first rule they broke. Do not drop them silently. In DuckDB 2.0.1 the project keeps five rejected rows from ten, and a row count check proves every bronze row is kept, rejected or replaced. Steps 3 and 4 show the SQL.

Are materialized lake views generally available in Microsoft Fabric?

Yes for SQL-defined views, as of 2026-11-29. Microsoft's FabCon and SQLCon 2026 post, dated 18 March 2026, calls them generally available, and Learn's What's new lists them as GA. PySpark authoring is still marked preview on the overview page. Views also need a schema-enabled lakehouse.

Do I need all three medallion layers?

Not on day one. Two layers work: bronze for raw data and gold for typed, deduplicated tables and reporting tables. The project runs both variants on the same files and gets the same gold table. Add silver when a second consumer reuses the cleaned data or a different team owns it.

Portrait of Rodrigo Lombana Reina

Rodrigo Lombana Reina, data engineer. Data problems solved, step by step.

About Rodrigo · The opinions and texts on this site are my own.

My LinkedIn profile