donderdag 26 november 2026

Databricks series : Building a mediallion architecture with SCD Type 2 (step 2) (Part XIII)

Introduction

In this series, we're building a small but realistic data platform using Databricks, Python, Delta Lake, and Unity Catalog. The goal is to create a reusable data ingestion architecture that can handle different data sources, such as CSV files and REST APIs, while supporting incremental processing and historical data tracking. We'll use a Medallion-inspired architecture with four logical layers:

  • Raw : Original source files.

  • Base : Ingested data stored as Delta tables.

  • Prep  : Validated and transformed data, including historical tracking.

  • Gold : Business-ready data for reporting and analytics.

In this first part, we'll focus on preparing the Unity Catalog structure and creating the Raw storage location. We won't build the Python pipelines yet. First, let's get the foundation right.


We are building upon what we already have :


2. Creating the Unity Catalog schemas

We'll use an existing Unity Catalog catalog called main.

Instead of creating separate catalogs for every layer, we'll create four schemas inside the existing catalog:


main
│
├── raw
├── base
├── prep
└── gold

Open the Databricks SQL Editor and execute:


CREATE SCHEMA IF NOT EXISTS main.raw;
CREATE SCHEMA IF NOT EXISTS main.base;
CREATE SCHEMA IF NOT EXISTS main.prep;
CREATE SCHEMA IF NOT EXISTS main.gold;

This creates the logical structure for our data platform. Using schemas for the different layers keeps the data organized and makes access management easier.


3. Creating the Raw Volume

The Raw layer will store our original source files. In Unity Catalog, we'll use a Volume for file storage. Execute the following SQL statement:

CREATE VOLUME IF NOT EXISTS main.raw.files;

Our Raw storage location is now:

/Volumes/main/raw/files/

We'll use this location as the landing zone for incoming files. For example, our folder structure will eventually look like this:


/Volumes/main/raw/files/
│
├── customers/
│   ├── customers.csv
│   └── customers_update.csv
│
└── exchange_rates/
    └── exchange_rates.json


The important design principle is that the Raw layer preserves the original input. We don't apply business transformations or overwrite source files during ingestion. This gives us the possibility to reprocess the original data if something goes wrong in a downstream pipeline.


4. Verifying the Unity Catalog structure

After creating the schemas and Volume, we can verify the setup. To list the schemas we can use the following command :


SHOW SCHEMAS IN main;

Resulting in :




To inspect the Volume:


DESCRIBE VOLUME main.raw.files;



We should now have the following structure available:

main
│
├── raw
│   └── files (Volume)
│
├── base
│
├── prep
│
└── gold

At this stage, the schemas are empty except for the Raw Volume. That's exactly what we want. We're preparing the foundation before implementing the ingestion logic.


5. Moving existing source files

In our existing Python project, we already have two customer CSV files:


/Volumes/main/demo/raw/customers.csv
/Volumes/main/demo/raw/customers_update.csv

We'll move or copy these files into the new Raw Volume:


/Volumes/main/raw/files/customers/customers.csv
/Volumes/main/raw/files/customers/customers_update.csv

So this is the result :


We'll keep the original files until we've verified that the new locations work correctly. This gives us a clean separation between the original landing zone and the future Delta tables.


Conclusion

We've now established the foundation of our Databricks Medallion Architecture. By organizing Unity Catalog into Raw, Base, Prep, and Gold schemas, and creating a dedicated Volume for original source files, we've established a clear separation between file storage, data ingestion, preparation, and business consumption. The next step is to connect these layers with Python and Delta Lake. This is where the architecture starts to become a working data platform.

Geen opmerkingen:

Een reactie posten