Sub topic 15
When to bend the pattern: trade-offs and pitfalls
This chapter assumes you have read the earlier chapters. You should know what bronze, silver, and gold hold, how Auto Loader and MERGE move data between them, and how Unity Catalog organizes tables. Here you decide when the three-layer pattern fits and when it does not.
The pattern is a default, not a rule
Medallion architecture gives you a replayable raw copy (bronze), a trustworthy cleaned copy (silver), and tables shaped for consumers (gold). Each extra layer costs storage, compute, scheduling, and people's attention. Add or remove a layer only when you can name the benefit.
When fewer layers are justified
- Small, stable, already clean sources. A reference table exported once a day may not need a separate silver step. Land it in bronze and expose a view.
- One-off analysis. A throwaway exploration does not need three governed schemas.
- Silver is the product. Data science teams often consume silver directly. Skipping gold for them is fine.
When more layers are justified
- Sensitive data. Add a step that masks or tokenizes personal data before silver, so most users never see the raw values.
- Multiple sources for one entity. A conformed layer can merge customers from several systems before silver tables are built on top.
- Several gold consumers. Separate marts per team keep one team's logic from breaking another's.
Common pitfalls
| Pitfall | What goes wrong | Fix |
|---|---|---|
| Cleaning in bronze | You lose the original values and cannot replay after a bug in your logic. | Keep bronze append-only. Add only load metadata such as `_ingested_at` and `_source_file`. |
| Business logic in silver | Silver becomes tied to one team's definitions. | Keep silver about types, keys, and duplicates. Put metrics in gold. |
| Gold built from bronze | Dashboards inherit dirty data and duplicates. | Read gold from silver. |
| Full rebuilds everywhere | Cost grows with history, not with new data. | Use streaming or incremental updates for bronze and silver. Rebuild only small gold tables. |
| Silent bad data | Failed checks go unnoticed. | Choose warn, drop, or fail on purpose for each rule. |
| Too many tiny tables | Many small files slow queries. | Schedule table maintenance such as `OPTIMIZE`. |
Trade-offs to weigh
Latency versus structure. Each hop adds delay. If a dashboard needs data within seconds, a three-stage batch flow may be too slow. Streaming between layers shortens the delay but raises cost.
Storage versus safety. Keeping raw history costs storage. In exchange, you can fix a silver bug and rebuild from bronze. Set a retention policy instead of dropping bronze.
Dropping versus failing bad rows. Dropping rows keeps the pipeline running but can hide losses. Failing the update protects correctness but stops delivery. A common compromise is to drop rows with a missing key, since they cannot be merged anyway, and only record violations for softer rules such as amount >= 0.
Ownership. More layers mean more handoffs. If one team owns the whole flow, fewer schemas may be easier to manage. If teams differ, layer boundaries double as contracts.
-- A quick check that silver has no duplicate keys before gold reads it
SELECT order_id, COUNT(*) AS copies
FROM main.silver.orders
GROUP BY order_id
HAVING COUNT(*) > 1> Run checks like this one as a job task after the silver step, and fail the job if rows come back.
Exercise
A team lands daily CSV exports of a 200-row product list that never contains errors. A colleague proposes bronze, silver, and gold schemas for it. What would you recommend, and what would change your mind?
Show answer
Land the file in a single bronze table, or one governed table, and expose a view if consumers need a friendlier shape. Three layers add pipelines and permissions for no gain on a small, clean, stable source. Change the recommendation if the source starts producing errors or duplicates, if the data contains sensitive fields that need masking, or if several teams need different business shapes of it.