Sub topic 3
Laying out layers in Unity Catalog
This chapter assumes you know the bronze, silver, and gold layers from the overview. It also assumes you know what a Delta table is and can run SQL in a Databricks notebook or the SQL editor. The goal is to decide where each layer lives in Unity Catalog, so the rest of the tutorial has stable names to build on.
The three-level namespace
Unity Catalog names every table with three parts: catalog.schema.table.
- A catalog is the top-level container. It is the usual unit for isolating environments, business domains, or teams.
- A schema (also called a database) sits inside a catalog. It groups tables, views, volumes, and functions.
- A table, view, or volume is the object that holds or exposes data.
The medallion layers are a convention, and Unity Catalog does not know about them. Nothing stops you from putting a raw table in a gold schema. The layout is how you make the convention visible and enforceable. If the layer is part of the name, a reader can tell what a table is and a permission can target it.
Three layouts and their trade-offs
There are three common ways to map layers onto the namespace.
| Layout | Example name | Strengths | Costs |
|---|---|---|---|
| One catalog per layer | `bronze.sales.orders` | Strongest isolation. Storage and grants can differ per layer. | Many catalogs. Domain grouping is spread across them. |
| One schema per layer | `main.bronze.orders` | Simple. Few objects to manage. Layer grants at schema level. | Domain is only in the table name. Large domains make crowded schemas. |
| Schema per layer and domain | `main.bronze_sales.orders` | Layer and domain are both visible. | More schemas. Naming discipline needed. |
This tutorial uses one schema per layer inside a single catalog, main. The names are main.bronze.orders, main.silver.orders, and main.gold.daily_revenue. It is the smallest layout that still lets you grant access per layer, and it is easy to migrate from later.
Where files live: volumes
Bronze tables are fed from files, and those files need a governed home too. A volume is a Unity Catalog object that provides a path for non-tabular files. Its path always has the form /Volumes/<catalog>/<schema>/<volume>/<subpath>.
The ingestion code in the next chapters reads from /Volumes/main/sales/landing/orders/ and writes checkpoints under /Volumes/main/sales/checkpoints/. That means two volumes, landing and checkpoints, in a schema named sales.
Keep volumes in their own schema, not in bronze. The reasons:
- Files and tables have different lifecycles. Landing files may be deleted after 30 days, while bronze tables are kept.
- Permissions differ. Source systems or upstream teams may need write access to
landingbut should never write to a bronze table. - A schema that holds only tables is easier to browse and to grant on.
Creating the layout
The following script creates the whole layout. It is safe to run more than once because every statement uses IF NOT EXISTS.
CREATE CATALOG IF NOT EXISTS main
COMMENT 'Lakehouse for the sales domain';
CREATE SCHEMA IF NOT EXISTS main.sales
COMMENT 'Landing files and streaming checkpoints';
CREATE SCHEMA IF NOT EXISTS main.bronze
COMMENT 'Raw, append-only copies of source data';
CREATE SCHEMA IF NOT EXISTS main.silver
COMMENT 'Cleaned, typed, deduplicated data';
CREATE SCHEMA IF NOT EXISTS main.gold
COMMENT 'Business-level aggregates and marts';
CREATE VOLUME IF NOT EXISTS main.sales.landing
COMMENT 'Raw files delivered by source systems';
CREATE VOLUME IF NOT EXISTS main.sales.checkpoints
COMMENT 'Auto Loader schema and stream checkpoint state';
SHOW SCHEMAS IN main;Some notes on running it:
- You need the
CREATE CATALOGprivilege on the metastore to create a catalog, andCREATE SCHEMAon the catalog for schemas. Many workspaces already have amaincatalog or a default workspace catalog, so you may only need the schema and volume statements. - Both volumes are managed volumes. Databricks stores their files in the managed storage location of the schema, which is inherited from the catalog or metastore.
- You do not create
main.bronze.ordershere. The Auto Loader job creates it withtoTable.
You can confirm the layout from Python as well:
for row in spark.sql("SHOW SCHEMAS IN main").collect():
print(row["databaseName"])
for row in spark.sql("SHOW VOLUMES IN main.sales").collect():
print(row["volume_name"])Both loops should print the names created above. The default schema may also appear in the first list.
Managed storage
Each catalog and schema can have its own managed storage location. A managed table is stored there, and Unity Catalog resolves the location from the closest level that defines one: schema, then catalog, then metastore.
This is the main reason to choose one catalog per layer. If bronze must sit in a separate cloud bucket, for example because of retention rules or a different owning account, you can set the location on a catalog or schema:
CREATE SCHEMA IF NOT EXISTS main.bronze
MANAGED LOCATION 's3://example-lakehouse-bronze/main';The bucket path is a placeholder. On Azure or Google Cloud you would use the matching URL scheme. The location must be registered first as an external location, and you need the right privilege on it. If you have no storage requirement, leave the clause out and use the default. A location you do not need is one more thing that can break.
Prefer managed tables for all three layers. Unity Catalog then controls the file layout and cleanup, and features like automatic maintenance apply. Use external tables only if other systems must read the same files directly.
Naming conventions that pay off
Settle these early, because renaming tables later breaks every downstream query, job, and dashboard.
- Use lowercase, snake_case names. Quoted mixed-case names are a constant source of errors.
- Keep the same table name across layers when it is the same entity:
bronze.orders,silver.orders. The schema carries the layer. Rename only where the shape changes, as ingold.daily_revenue. - Put audit columns in bronze with a leading underscore (
_ingested_at,_source_file). This keeps them apart from source columns. - Do not put environment names inside table names. Handle environments at the catalog or workspace level.
Environments: dev, test, prod
Layers are one axis. Environments are another. The common pattern is a catalog per environment, each with an identical set of schemas:
dev.bronze.ordersprod.bronze.orders
Code then refers to a catalog name passed in as a parameter, and only the catalog changes between environments. This is why the tutorial's SQL always uses the full three-part name. Relying on USE CATALOG or a default schema makes a notebook behave differently depending on who runs it.
A combined layout, with an environment catalog and layer schemas inside it, is usually the best balance. If you also need per-layer storage isolation, add the layer to the catalog name (prod_bronze) and accept the extra objects.
Common mistakes
- Mixing volumes and tables in one schema. It works, but grants and cleanup get awkward.
- Using paths instead of table names. Reading
dbfs:/...or cloud URLs directly bypasses Unity Catalog governance. Use table names and/Volumes/...paths. - Relying on the default catalog. The default differs between workspaces, so unqualified names make code non-portable.
- Too many catalogs too early. Each catalog is a unit to grant, audit, and document. Start small and split when a real isolation need appears.
- Layer schemas that grow without a domain. If
silverholds tables for six unrelated domains, move tosilver_<domain>or a catalog per domain.
Exercise
A team needs bronze data in a separate cloud storage account for retention reasons, and it wants analysts to see only gold. Which layout fits: one catalog with layer schemas, or one catalog per layer? Name the setting that controls where the bronze tables are stored.
Show answer
Either can work. A schema-per-layer layout can meet the storage need by setting MANAGED LOCATION on the bronze schema, and grants on the gold schema can limit analysts. A catalog per layer is warranted only if the team also needs catalog-level isolation, such as separate ownership and audit boundaries. The storage setting is the managed location on the catalog or schema, which resolves from schema, then catalog, then metastore.
Exercise
Why does this tutorial put the landing and checkpoint volumes in a sales schema instead of bronze?
Show answer
Files and tables have different lifecycles and permissions. Source systems may need write access to the landing files but never to bronze tables, and landing files can be deleted on a schedule. A schema that holds only tables is also easier to browse and to grant on.