Sub topic 15
Choosing the right storage location
This chapter assumes you can create volumes, build /Volumes paths, and have seen DBFS paths in older code. It gives you a way to pick a location for a file-loading task, and it lists the mistakes that come up most often.
The decision in one pass
Databricks gives you several places to put a file. Ask three questions in order.
- Is the file tabular data you will query repeatedly? Load it into a Delta table. A volume is only the landing spot before that step.
- Is it a non-tabular or raw file, such as CSV drops, images, PDFs, model artifacts or logs? Use a Unity Catalog volume.
- Is it notebook code, a small config file or a helper module that belongs to a project? Use workspace files.
DBFS root and mounts do not appear in these questions. Treat them as legacy locations you recognize and migrate away from, not as places for new work.
Comparing the options
| Location | Best for | Governed by Unity Catalog | New work |
|---|---|---|---|
| Managed volume | Raw files, ingestion landing zones, artifacts | Yes | Recommended |
| External volume | Files that other tools write to existing cloud storage | Yes | Recommended when needed |
| Workspace files | Notebooks, scripts, small config | No, uses workspace permissions | Fine for code |
| DBFS root, `/FileStore` | Old notebooks, quick public downloads | No | Avoid |
| DBFS mounts | Existing legacy pipelines | No | Avoid |
Managed or external
Choose a managed volume by default. Databricks places the files in the storage location of the schema or catalog, and dropping the volume deletes the files. Choose an external volume when files must stay at a path you already own, for example a bucket that an upstream system writes into. Dropping an external volume removes only the metadata, and the files remain in cloud storage.
An external volume carries one extra requirement. Its path must be covered by an external location that you can use.
Applying it
Suppose a partner sends a daily sales.csv. The raw file goes to a managed volume, and a job reads it into a table.
CREATE VOLUME IF NOT EXISTS main.default.landing;
CREATE TABLE IF NOT EXISTS main.default.sales_raw AS
SELECT * FROM read_files(
'/Volumes/main/default/landing/sales.csv',
format => 'csv',
header => true
);The volume keeps the original file for replay and audit. The table serves queries. If the partner already writes into your own bucket, make the landing volume external and point it at that path instead of copying files.
Common mistakes
- Writing new data to
dbfs:/FileStore/because an old tutorial did. The files sit outside Unity Catalog governance and are easy to expose by accident. - Using a volume as a database. Many small updates to a file are slow compared with a Delta table.
- Choosing an external volume without a reason. It adds an external location and a separate cleanup step.
- Forgetting privileges. Users need
READ VOLUMEto read andWRITE VOLUMEto add files, plus access to the parent catalog and schema.
Exercise
A team receives nightly JPEG images from a vendor who writes them to an S3 bucket the team already owns. Other systems also read that bucket. The team wants Unity Catalog governance over the images in Databricks. Which location should they use, and why not DBFS?
Show answer
An external volume pointing at the bucket path. The images are non-tabular files, so a volume fits, and the files must stay in the existing bucket that other systems use, which rules out a managed volume. DBFS is legacy and is not governed by Unity Catalog.