Medallion architecture in Databricks organizes data into layered bronze, silver, and gold tables to enforce data quality, governance, and lineage—each layer serves a distinct role in transforming raw data into trusted insights.

What You'll Need

  • A Databricks workspace with access to Unity Catalog (for schema-level governance)
  • Appropriate permissions: at least 'CREATE TABLE' and 'SELECT' on target schemas
  • Source data ingested into cloud storage (e.g., S3, ADLS, or GCS) or available via Databricks File System (DBFS)
  • Basic familiarity with PySpark or SQL in Databricks notebooks

Step-by-Step

  1. Plan your schema structure: Decide on database (catalog.schema) naming that reflects layering. For example, use `bronze`, `silver`, and `gold` as schema names under your target catalog (e.g., `analytics.bronze`, `analytics.silver`, `analytics.gold`). This makes lineage and access control straightforward.
  2. Ingest raw data into bronze layer: Load unprocessed, source-system data as-is into bronze tables. Use `COPY INTO` for simplicity and fault tolerance, or structured streaming for continuous ingestion. Example: COPY INTO analytics.bronze.sales_raw FROM 's3://my-bucket/sales/' FILEFORMAT = CSV;. Do not clean, dedupe, or transform—bronze preserves the original format and metadata.
  3. Apply basic cleaning and standardization in silver layer: Transform bronze data into consistent, validated silver tables. Remove duplicates, parse timestamps, enforce schema (e.g., cast types), and apply basic business rules (e.g., exclude null primary keys). Use Delta Live Tables (DLT) or notebooks with `MERGE INTO` for upserts. Example: CREATE TABLE analytics.silver.sales_clean AS SELECT DISTINCT ..., CAST(sale_date AS DATE) FROM analytics.bronze.sales_raw WHERE sale_id IS NOT NULL;.
  4. Aggregate and model for business use in gold layer: Build gold tables with pre-joined, high-level metrics and dimensions ready for dashboards or ML. This layer often includes daily aggregations (e.g., total sales per region), role-based views, or features for modeling. Example: CREATE TABLE analytics.gold.daily_sales_summary AS SELECT region, SUM(amount) AS total_revenue, COUNT(*) AS transaction_count FROM analytics.silver.sales_clean GROUP BY region, sale_date;.
  5. Enable time travel and lineage tracking: Use Delta Lake’s time travel (`VERSION AS OF`, `TIMESTAMP AS OF`) for reproducibility. In Unity Catalog, register each table with `COMMENT` and use table properties (e.g., `delta.minReaderVersion = 3`, `delta.minWriterVersion = 5`) to ensure compatibility. This clarifies how data flows from bronze → silver → gold.
  6. Set up access control per layer: Grant permissions based on layer sensitivity. Bronze often allows read-only for data engineers; silver may be restricted to analysts with cleansing responsibilities; gold tables should be readable by BI tools and end users. Example: GRANT SELECT ON TABLE analytics.gold.daily_sales_summary TO `data-analysts`;.
  7. Automate with Delta Live Tables (optional but recommended): Replace notebook steps with DLT pipelines using SQL or Python. DLT enforces expectations (e.g., `EXPECT_ALL_OR_FAIL`) and auto-manages dependencies. Example: CREATE STREAMING LIVE TABLE silver_sales EXPECT (sale_id NOT NULL); INSERT INTO silver_sales SELECT ... FROM STREAM(live.sales_raw);. This reduces manual orchestration.

Common Mistakes

  • Skipping bronze entirely: Jumping straight to silver causes loss of auditability and makes it impossible to re-ingest from source cleanly if the data pipeline fails.
  • Over-processing in bronze: Adding transformations (e.g., deduplication or joins) in bronze blurs layer boundaries and increases reprocessing effort when source formats change.
  • Ignoring schema enforcement: Not using Delta’s `MERGE SCHEMA` or `ENFORCE` options can lead to silent schema drift, especially in streaming silver layers, causing downstream gold table failures.
  • Hardcoding paths: Using literal DBFS or cloud storage paths instead of Unity Catalog external locations limits portability and security. Always reference tables by name (e.g., `analytics.bronze.raw_events`) rather than physical paths.
  • Over-aggregating in gold: Creating overly specific gold tables for one dashboard reduces reuse. Gold tables should support multiple use cases (e.g., both BI and model training).

Tips

  • Use `DESCRIBE HISTORY` on key tables to verify layer transitions and track changes over time.
  • For streaming workloads, set `ignoreChanges = true` in bronze DLT expectations only if you expect late-arriving or corrupted batches—otherwise use `FAIL` policies to catch issues early.
  • Leverage Databricks’ built-in data profiler (in the Data tab) to validate schema and null rates after ingestion into bronze.
  • Partition silver and gold tables by high-cardinality dimensions (e.g., `date`, `region`) to improve query performance—but avoid over-partitioning (e.g., >10k files/partition).
  • Document expectations in comments: e.g., `-- Silver: deduped on order_id, enriched with customer_country from gold.dim_customers`.
  • Start with a single domain (e.g., `sales`) before expanding to other business areas to validate your pattern.

Troubleshooting

If bronze ingestion fails, check: (1) source file permissions and format consistency (e.g., CSV vs JSON), (2) whether COPY INTO was retried successfully (use `SHOW COPY INTO`), and (3) if the target schema exists. If silver transforms fail due to nulls, adjust `WHERE` clauses or use `COALESCE` before casting. If gold queries are slow, run `ANALYZE TABLE analytics.gold.daily_sales_summary COMPUTE STATISTICS FOR ALL COLUMNS` to update optimizer statistics. If Unity Catalog permissions errors occur, verify the user or service principal has `USE CATALOG`, `USE SCHEMA`, and `SELECT` grants explicitly—note that `ALL PRIVILEGES` is not required for read-only gold access.

Frequently Asked Questions

Does Medallion Architecture require Delta Lake?

Yes—Delta Lake’s ACID transactions, time travel, and schema enforcement are essential for lineage, reproducibility, and reliability across layers.

Can I skip the silver layer?

Only for trivial use cases (e.g., one-off exploratory analysis). Skipping silver risks inconsistent data in gold and makes it harder to enforce clean transformations at scale.

How do I handle schema changes in bronze?

Use `MERGE SCHEMA` in `COPY INTO` or DLT `STREAMING TABLE` definitions to auto-evolve the schema. Test with a small sample first to avoid unexpected columns in downstream layers.

Is gold always table-based, or can it be views?

Both. Precomputed tables (e.g., `gold.daily_summary`) suit frequent queries; views (e.g., `gold.customer_360`) work for lightweight joins but may slow under heavy load.

Do I need separate clusters for each layer?

Not necessarily. Use the same cluster but separate notebooks or DLT pipelines. For large workloads, isolate compute by layer (e.g., bronze uses auto-scaling with low-cost instances; gold uses high-memory clusters for aggregations).

How do I test each layer independently?

Run unit tests on bronze (e.g., row count matches source), silver (e.g., no nulls in `customer_id`), and gold (e.g., `SUM(revenue)` matches known totals). Use Databricks’ `assert` functions in notebooks or DLT expectations.