Sub topic 15
When to Bend the Pattern: Trade-offs and Pitfalls
This chapter assumes you have built the three layers in the earlier chapters. You should know how Auto Loader fills bronze, how MERGE builds silver, and how gold tables serve business consumers. You should also be comfortable reading Unity Catalog names such as main.silver.orders.
The medallion architecture is a default, not a law. Bronze, silver, and gold give you replayability, a clean conformed layer, and consumer-shaped tables. Each layer also costs storage, compute, and maintenance. This chapter helps you decide when the default pays off and when to change it.
What each layer costs
Every extra hop between layers adds a table to govern, a job to monitor, and latency before data is usable. Before you add a layer, name the problem it solves.
| Layer | What you gain | What you pay |
|---|---|---|
| Bronze | Replay without re-reading the source, an audit trail, protection from upstream changes | Storage for a second copy of the data, and a table nobody should query directly |
| Silver | One typed, deduplicated version of each entity, shared by many consumers | Transformation logic that must stay correct, and MERGE compute |
| Gold | Fast, simple tables shaped for dashboards and models | Duplicated aggregates that can drift from silver if the logic changes |
Seen this way, the layers are a bundle of separate jobs: keep raw data, clean it, and serve it. A layer is worth having when its job matters in your situation.
Deciding how many layers you need
Start from the work to be done, not from the names. Ask three questions:
- Do you need to replay or audit raw data? If the source cannot resend history, bronze is cheap insurance.
- Do several consumers need the same cleaned entity? If so, silver prevents each team from writing its own cleanup.
- Do consumers need shapes that differ from the entity model? If so, gold tables are justified.
Fewer layers: when to collapse
Some flows do not need all three tables.
- Small, stable sources. A lookup table of 5,000 country codes does not need a bronze copy, a silver copy, and a gold copy. One Delta table with a documented load job is fine.
- Sources you can re-read. If you can fetch the full history from a database at any time, bronze adds less. Keep it if the source overwrites rows in place and you need history.
- Single-consumer pipelines. If one dashboard reads the data and nothing else will, you may fold gold logic into a view over silver.
A view is the lightest way to merge gold into silver. It adds no storage and cannot go stale, because it reads silver each time it runs.
CREATE OR REPLACE VIEW main.gold.completed_orders AS
SELECT order_id, customer_id, order_ts, amount
FROM main.silver.orders
WHERE status = 'completed';The cost is that every query repeats the filter work. For small tables that cost is negligible. For large aggregations, a stored gold table or a materialized view is better, because dashboards then read precomputed results.
More layers: when to extend
Teams sometimes add layers beyond the three. Do this only for a concrete reason.
- A staging or "landing" step for data that needs decryption, unzipping, or format repair before Auto Loader can read it.
- A conformed-entity layer between silver and gold when several silver sources must be joined into shared entities, such as a single customer record built from CRM, billing, and web data.
- A restricted layer for sensitive columns. You might keep a silver table with raw personal data under tight grants, and a second table with masked values for wider use.
- Feature or serving tables for machine learning that need point-in-time correctness.
Every added layer needs an owner, a freshness target, and a rule for what belongs in it. Without those, the extra layer becomes a place where logic is copied and nobody knows which table is correct.
Common pitfalls
Bronze that is not really raw
Bronze is meant to keep data replayable. Pitfalls appear when engineers "tidy" it:
- Dropping rows or fixing values in bronze removes the ability to reprocess from the original input.
- Overwriting bronze instead of appending destroys history.
- Inferring a rigid schema can silently lose columns when the source adds fields. Auto Loader's schema evolution and a rescued data column help here, so unexpected fields land somewhere you can inspect.
Add load metadata such as _ingested_at and _source_file, as in the Auto Loader example, so you can trace any row to its file.
Silver that does too much
Silver should clean, type, and conform. It becomes a problem when it also holds business rules that only one team needs, such as a "VIP customer" flag defined by marketing. Those rules change often and differ between consumers. Put them in gold, where each consumer can own its own definition.
The opposite error is silver that does too little. If every consumer must cast timestamps and deduplicate on their own, you have a bronze table with a nicer name.
Gold that drifts
Gold tables built with CREATE OR REPLACE TABLE ... AS SELECT recompute from scratch each run. That is simple and correct, but expensive at scale. Moving to incremental gold logic saves compute and adds risk: late or corrected silver rows must update the right aggregate rows. Choose incremental gold only when full recomputation is too slow or costly, and test how corrections flow through.
Two gold tables that compute "revenue" with different filters will give different answers on two dashboards. Define each metric once and reuse it, either in one gold table or in a governed metric definition.
Treating expectations as a safety net for everything
The choice between warn, drop, and fail in expectations is a trade-off, not a style preference.
| Behavior | Good for | Risk |
|---|---|---|
| Warn (record the violation, keep the row) | Soft rules such as `amount >= 0` where you want to measure first | Bad data reaches gold |
| Drop (remove the row) | Rows that are unusable, such as a missing key | Rows disappear silently unless you track the drop counts |
| Fail (stop the update) | Rules where wrong data is worse than late data | A single bad file blocks the whole pipeline |
Dropping rows without keeping them anywhere makes later debugging hard. Consider routing failed rows to a quarantine table so someone can inspect and replay them.
Ignoring late and out-of-order data
MERGE keyed on order_id with "latest _ingested_at wins" assumes arrival order matches business order. If a delayed file contains an older version of an order, it can overwrite a newer one. When the source provides a version number or an update timestamp, order by that field instead of ingestion time. Keep a tie-breaker, such as the source file name, so results are deterministic.
Small files and unmaintained tables
Streaming into bronze every minute creates many small files, which slows reads. Layout and maintenance settings matter more as tables grow. Schedule table optimization, or enable automatic maintenance features available for your tables, rather than discovering the slowdown through a failed dashboard.
Mixing governance across layers
If analysts have broad access to a catalog, they will find bronze tables and query them. Results then differ from gold, and raw sensitive fields leak. Grant access per layer, as in the earlier governance chapter, and make gold the only layer most people can read.
Latency and freshness
The medallion flow trades freshness for structure. Each hop adds delay, and a batch schedule adds more. Typical choices:
- Hourly or daily batches with
availableNowtriggers suit reports that tolerate delay. They keep compute costs low because clusters shut down between runs. - Continuous streaming between layers reduces latency but keeps compute running and makes failure handling more demanding.
- A fast path outside the layers is sometimes right. If one alert must fire within seconds, it may read from the stream directly while the same data also lands in bronze for the full flow.
Decide freshness targets per gold table, not per pipeline. A daily revenue table and a fraud alert have different needs.
A short review checklist
Before you approve a new medallion pipeline, check these points:
- Each layer has a stated purpose and an owner.
- Bronze is append-only and keeps load metadata.
- Silver deduplicates on a business key using a version field that reflects source order.
- Expectations have an explicit warn, drop, or fail decision, and dropped rows are counted or quarantined.
- Gold metrics are defined in one place.
- Permissions differ by layer.
- Maintenance and freshness targets are written down.
Exercise
A team ingests a 3,000-row currency-code lookup file that changes twice a year and feeds one finance dashboard. A colleague proposes bronze, silver, and gold tables for it. Argue for a lighter design, and name one condition that would make you add a bronze layer back.
Show answer
Load the file into a single Delta table with a short transformation step (casting types and removing duplicates), and expose it through a view if the dashboard needs a specific shape. The data is small, changes rarely, and has one consumer, so three tables add storage, jobs, and governance work with no benefit. Add a bronze layer back if the source overwrites the file without keeping history and you need an audit trail or the ability to replay earlier versions, or if the file's format becomes unstable so you need raw copies to reprocess after fixing the parsing.