Zero Labs
Industry News / AI

The Complete Production Guide to Medallion Architecture in Microsoft Fabric

Source · Towards AI By Sandip Palit

From the publisher’s feed, collected in the ZeroLabs newsroom.

When we set out to build modern analytical platforms, we frequently encounter a critical fork in the road regarding architectural design. As we navigate Microsoft Fabric, a unified SaaS platform that consolidates our enterprise analytics capabilities into a single ecosystem, we realize that we are no longer forced to pick disparate systems. Historically, engineering teams had to choose between the raw, unstructured power of a data lake and the rigid, transactional reliability of a traditional data warehouse. Today, Fabric natively brings both the Lakehouse and the Warehouse paradigms under one roof, backed by OneLake.However, having both choices readily available at our fingertips introduces a new challenge: we must deeply understand the underlying engines, performance characteristics, and primary strengths of each artifact to avoid architectural missteps. The real beauty of Microsoft Fabric is that we are not locked into a mutually exclusive binary decision. As our data platforms mature, we invariably discover how both options coexist in a unified medallion architecture.In this comprehensive guide, we will walk through the exact steps we take to implement a production-grade Medallion Architecture, moving data seamlessly from Bronze, to Silver, and finally to Gold. We will explore how to handle raw data ingestion, implement robust data quality gates using PySpark, and serve pristine dimensional models using T-SQL and Direct Lake integration.Bronze Layer: Raw Data Ingestion & Schema Drift HandlingThe foundation of our architectural strategy begins with the Bronze layer. The primary objective here is to capture data in its rawest, most unaltered state. We do not apply business logic, we do not filter out seemingly erroneous records, and we certainly do not enforce rigid schema structures at this stage.Landing the DataIn our enterprise deployments, we ingest messy, semi-structured JSON payloads, API response feeds, and high-frequency streaming data directly into the Files directory of our Lakehouse using Fabric Data Factory or Spark. By treating the Bronze layer as an append-only immutable ledger, we ensure that we never lose our original source of truth. If a downstream transformation fails, or if our business requirements radically change six months from now, we can always replay our pipelines from this untampered historical record.Handling Continuous ReplicationFor operational relational databases, we are witnessing a monumental, industry-defining shift in how we handle enterprise data movement. With the continuous evolution of Microsoft Fabric, we are decisively stepping into the era of Zero-ETL by leveraging Fabric Mirroring. Instead of building brittle, custom extraction pipelines, the Fabric Mirroring engine captures microscopic data mutations via Change Data Capture (CDC) and streams them directly into our Microsoft Fabric environment.The system automatically creates a replica of our selected tables in OneLake, initiating a seamless snapshot of the current data state and immediately beginning to stream incremental changes. Because we are merely reading lightweight transaction logs, the extraction impact on the source operational system is virtually zero, preserving our critical operational compute for live applications.Silver Layer: Data Quality Gates, Cleaning, and Delta MERGEOnce our data is safely landed in the Bronze layer, we move to the critical refinement phase: the Silver layer. Here, we transition from raw files into structured, queryable tables. We clean, parse, validate, and flatten the raw data using Spark Notebooks, writing the processed output into open Delta Parquet tables inside our Lakehouse Tables section.This layer is where we enforce data quality, handle schema evolution, and most importantly, perform deduplication and atomic upserts (MERGE operations).Building the Silver Transformation PipelineLet us explore a highly practical implementation. We will construct a PySpark pipeline that reads raw customer data, deduplicates the records, and performs an atomic upsert into our Silver Delta table.# PySpark code for Silver Layer Delta Upsert (Bronze -> Silver) with CDC & Deduplicationfrom delta.tables import DeltaTablefrom pyspark.sql.window import Windowfrom pyspark.sql.functions import col, row_number# 1. Read Raw Bronze Databronze_df = spark.read.table("Bronze_Lakehouse.raw_customers")# 2. Deduplicate landed Bronze records using Window functionwindow_spec = Window.partitionBy("CustomerID").orderBy(col("IngestionTimestamp").desc())deduped_bronze = ( bronze_df .withColumn("rn", row_number().over(window_spec)) .filter(col("rn") == 1) .drop("rn"))# 3. Load target Silver Delta Tablesilver_table = DeltaTable.forPath(spark, "abfss://Workspace@onelake.dfs.fabric.microsoft.com/Silver.Lakehouse/Tables/DimCustomer")# 4. Perform Atomic MERGE (Upsert)( silver_table.alias("target") .merge( deduped_bronze.alias("source"), "target.CustomerID = source.CustomerID" ) .whenMatchedUpdate(set={ "Name": col("source.Name"), "Email": col("source.Email"), "Address": col("source.Address"), "LastUpdated": col("source.IngestionTimestamp") }) .whenNotMatchedInsert(values={ "CustomerID": col("source.CustomerID"), "Name": col("source.Name"), "Email": col("source.Email"), "Address": col("source.Address"), "LastUpdated": col("source.IngestionTimestamp") }) .execute())Under the Hood: Code Breakdown and OptimizationLet us break down exactly what we are achieving with this PySpark execution:Reading Bronze: We natively read from our Bronze Lakehouse tables. The Fabric metastore abstracts away the underlying storage complexities, allowing us to interact with the data simply by its table name.Deduplication via Windowing: In distributed computing environments, especially those utilizing CDC or streaming data, it is incredibly common to receive multiple updates for a single CustomerID within the same batch. We utilize PySpark windowing functions (pyspark.sql.window) to partition our dataset by the unique identifier and order the events chronologically to find the most recent state. By filtering for row_number == 1, we isolate the absolute latest iteration of every customer record before attempting to update our target table.Atomic MERGE (Upsert): The true power of the Delta Lake format shines in the merge operation. We compare our incoming, deduplicated Bronze data against our existing Silver table. If the CustomerID already exists, we update the necessary fields (Name, Email, Address). If it does not exist, we insert a brand-new row. Because Delta format guarantees ACID compliance, this operation is entirely atomic, it either succeeds entirely or fails entirely, ensuring we never leave our data in a corrupted, half-written state.As we write this data, we also heavily prioritize storage optimization. For instance, enabling Microsoft’s proprietary V-Order configuration dynamically compresses our Parquet files and dramatically accelerates subsequent read speeds for the Power BI VertiPaq engine.Protecting the Silver Layer with Time TravelEven with the most robust code, human error is inevitable in software engineering. Fortunately, Delta Parquet architecture fundamentally changes how we handle disaster recovery. A Delta table consists of two main components: the actual data stored in highly compressed Parquet files, and a transaction log stored in a _delta_log folder. Because Parquet files are inherently immutable, when we execute updates, the engine does not rewrite the existing file; it creates a new one and updates the JSON transaction log.Because the old Parquet files are not immediately deleted from our OneLake storage, our complete history is preserved. Specifically, Microsoft Fabric’s Time Travel capability allows us to query our data exactly as it existed at a specific point in time. By leveraging the Delta storage architecture, we drastically reduce our Mean Time To Recovery (MTTR). If a rogue script corrupts our Silver layer, we can restore the table in seconds rather than spending hours restoring traditional database backups.Gold Layer: Dimensional Modeling (Star Schema) and Direct Lake ServingWith our data beautifully cleansed and standardized in the Silver layer, we must now shape it for our end-users. The Gold layer is where we construct our business-facing dimensional models (Star Schemas consisting of Fact and Dimension tables).Zero-Copy Data Movement via ShortcutsTraditionally, moving from a Spark-based data lake into a relational data warehouse required massive data duplication and expensive pipeline execution. In Fabric, we eliminate this entirely. Rather than copying data out of our Lakehouse into the Warehouse, we create OneLake Shortcuts inside our Fabric Warehouse pointing directly to the Silver Delta tables in our Lakehouse.T-SQL for Business LogicOnce the OneLake shortcut is established, we use the T-SQL heavy nature of the Warehouse to curate our Gold layer. We execute T-SQL stored procedures, merge multiple domain datasets, enforce row- and column-level security, apply complex business logic, and guarantee strict ACID compliance for final financial or executive reports.This hybrid approach allows our data engineers to continue utilizing PySpark for heavy data lifting in the Lakehouse, while our business analysts and SQL engineers construct robust views and stored procedures using their preferred T-SQL dialect within the Warehouse.Direct Lake and Power BIThe culmination of our Medallion Architecture occurs at the presentation layer. Because our data is optimally structured in Delta Parquet format and exposed via the Warehouse, Power BI reports connect directly to these Gold views and tables using Direct Lake mode, delivering high performance without duplicating data storage. Our end-users experience the lightning-fast performance of an imported semantic model, while constantly querying the live, underlying OneLake data.Orchestration: Wiring Notebooks into Fabric Data PipelinesTo bring our architecture to life, we must automate the progression from Bronze to Silver to Gold. We accomplish this by utilizing Microsoft Fabric Data Pipelines.Triggering Ingestion: We schedule our Data Factory pipeline to initiate the raw data ingestion, pulling from APIs, on-premises systems, or validating the continuous stream from Fabric Mirroring.Executing PySpark Notebooks: Upon successful ingestion, the pipeline triggers our Silver processing PySpark notebook. We pass parameterized arguments dynamically, ensuring the notebook knows precisely which batch of data to deduplicate and MERGE.Invoking Stored Procedures: Finally, the pipeline executes the T-SQL stored procedures in our Warehouse, refreshing our Gold layer aggregates and dynamically updating our semantic models.Ensuring Business ContinuityIn mission-critical enterprise environments, orchestration also involves rigorous Disaster Recovery (DR) planning. To guarantee uptime, we programmatically replicate our crucial Delta metadata and table content across OneLake regions. By utilizing a scheduled PySpark notebook running in a secondary region workspace, we define explicit paths to both the primary and backup workspaces using the abfss:// protocol, allowing the Spark engine to pull the data securely and establish a guaranteed 1-hour RPO that is completely under our organizational control.ConclusionBy consciously deploying a structured Medallion Architecture within Microsoft Fabric, we create an environment that is scalable, highly governed, and exceptionally performant. We no longer need to wage war over whether a data lake or a data warehouse is superior. In Microsoft Fabric, both the Lakehouse and the Warehouse serve distinct, complementary roles built on top of a shared storage layer: OneLake.We capture our reality immutably in Bronze, we refine and assert technical truth in Silver using PySpark, and we shape our ultimate business reality in Gold using T-SQL. By mastering both environments, we empower ourselves to build the most efficient, scalable, and cost-effective data solutions possible, delivering unparalleled value to our enterprise. Let us continue to build elegantly, automate relentlessly, and harness the full, unified power of our data.Hey, I am Sandip Palit, from Kolkata, India. I love to explore what’s new in the Data Science space and share it with the community. I am a Fabric Super User, and in this Microsoft Fabric Playlist, I will share my learnings on Microsoft Fabric and the tips and tricks of using it effectively..Thank You for reading this article. Please feel free to share your thoughts in the comments section, and give this article a 🌟.The Complete Production Guide to Medallion Architecture in Microsoft Fabric was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.