Sub topic 3
Laying out layers in Unity Catalog
This chapter assumes you know basic SQL, have used a Databricks workspace and notebooks, and understand what bronze, silver, and gold mean at a high level. It covers how to map those layers onto Unity Catalog objects. The mapping decides who can see what, where data is stored, and how easy the platform is to run.
The three-level namespace
Unity Catalog names every table with three parts: catalog.schema.table. A catalog is the top-level container. A schema (also called a database) groups tables, views, volumes, and functions inside a catalog. A volume is a governed location for files, such as raw JSON that has not been loaded into a table yet.
The medallion layers are a convention, not a built-in feature. Unity Catalog does not know what "silver" means. You encode the layers in names, and then you attach permissions and storage to those names.
Two common layouts
There are two main options.
| Layout | Example names | Strengths | Weaknesses |
|---|---|---|---|
| Layer per schema | `main.bronze.orders`, `main.silver.orders`, `main.gold.daily_revenue` | Simple, few objects, easy to grant access per layer | Several domains share one catalog, so isolating a domain is harder |
| Layer per catalog | `bronze.sales.orders`, `silver.sales.orders`, `gold.sales.daily_revenue` | Separate storage and ownership per layer, clear boundary for permissions | More catalogs to manage, and the same schema names repeat |
A third option is a catalog per environment, such as dev, test, and prod, with layer schemas inside each. This keeps development work away from production data. The examples in this tutorial use the first layout, with a single catalog named main and one schema per layer.
Creating the objects
The following statements create the layout used in later chapters. They hold the raw files, the checkpoints, and the three layer schemas.
CREATE CATALOG IF NOT EXISTS main;
CREATE SCHEMA IF NOT EXISTS main.sales
COMMENT 'Landing files and checkpoints for the sales domain';
CREATE VOLUME IF NOT EXISTS main.sales.landing;
CREATE VOLUME IF NOT EXISTS main.sales.checkpoints;
CREATE SCHEMA IF NOT EXISTS main.bronze
COMMENT 'Raw, append-only data as ingested';
CREATE SCHEMA IF NOT EXISTS main.silver
COMMENT 'Cleaned, typed, deduplicated data';
CREATE SCHEMA IF NOT EXISTS main.gold
COMMENT 'Business-level aggregates for consumers';Two details matter here. First, the landing files and checkpoints live in volumes, not in the layer schemas. This is why the bronze code reads from /Volumes/main/sales/landing/orders/. Keeping them separate means the layer schemas contain only tables. Second, CREATE CATALOG may require a storage location or specific privileges, depending on how your metastore is set up. If the statement fails, ask your metastore admin rather than working around it.
Managed tables and storage
Create layer tables as managed tables whenever you can. Unity Catalog then controls the file location and lifecycle, and dropping a table also removes its data after a retention period. External tables point at storage you manage yourself. They suit data that other systems must read directly, but you take on cleanup and path management.
You can set a managed storage location on a catalog or schema. That lets you place a layer on its own storage, which helps if gold needs different retention or cost controls than bronze.
Naming guidelines
- Use the same table name across layers when the entity is the same, as in
bronze.ordersandsilver.orders. The schema carries the layer. - Name gold tables after what the consumer wants, such as
daily_revenue, not after the source. - Avoid putting the layer in both places, such as
bronze.bronze_orders.
Common mistakes
- Putting raw files and tables in the same schema, which makes permissions awkward.
- Creating one schema for everything, then trying to hide raw data with row filters later.
- Mixing dev and prod tables in the same catalog without an environment marker.
Exercise
A team wants analysts to read only gold tables, and wants raw files kept apart from tables. Using the layer-per-schema layout in main, which schemas and volumes would you create, and where would the raw JSON files go?
Show answer
Create schemas main.bronze, main.silver, and main.gold, plus a schema main.sales holding volumes such as landing and checkpoints. Raw JSON goes in the main.sales.landing volume, so the layer schemas hold only tables. Analysts are granted access on main.gold only.