Introduction
When building a data platform, simply loading files into Delta tables is rarely enough. As data pipelines grow, we need a structured approach to ingestion, data quality, change tracking, and historical data management. In this blogpost and other blogposts, we'll build a small but practical data platform using Databricks, Unity Catalog, Delta Lake, Change Data Feed (CDF), and Slowly Changing Dimensions Type 2 (SCD2).
The goal is to create an architecture that can ingest data from different sources, preserve the original input, detect changes, and maintain historical versions of business entities. We'll use customer data as our example, but the same architecture can also support REST APIs and other data sources.
We are building upon what we already have :
- Databricks series : Starting a new python project in Visual Studio Code (Part I)
- Databricks series : setting up a connection to Databricks from local IDE (Part II)
- Databricks series : Setting up a Databricks project in Visual Studio Code (part III)
- Databricks series : Deployment from Visual Studio Code (Part IV)
- Databricks series : Execute the job in Databricks (Part V)
- Databricks series : A configrable framework in Databricks (Part VI)
- Databricks series : Loading strategies in Databricks (Part VII)
- Databricks series : Data contracts in Databricks (Part VIII)
- Databricks series : Debugging Python code in Visual Studio Code with arguments (Part IX)
- Databricks series : ODCS Data contracts in Databricks (Part X)
- Databricks series : reading an API (Part XI)
The architecture
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.
Each layer has a specific responsibility. This separation makes the platform easier to maintain, troubleshoot, and extend.
2. Raw – Preserve the original data
The Raw layer is our landing zone. Its responsibility is straightforward: store source files exactly as they arrive. For this implementation, we'll use a Unity Catalog Volume:
/Volumes/main/raw/files/
Our folder structure could look like this:
/Volumes/main/raw/files/
customers/
customers.csv
customers_update.csv
exchange_rates/
exchange_rates.json
We deliberately avoid business transformations in this layer. The original files remain available for reprocessing, troubleshooting, and auditing. Using a Unity Catalog Volume also provides governed access to files through Databricks.
3. Base – Ingest files into Delta tables
The Base layer converts the files from Raw into Delta tables. For example:
main.base.customers
main.base.exchange_rates
During ingestion, we add technical metadata to each record:
We use append-based ingestion so that incoming records are preserved instead of overwriting previous data. An important feature of this layer is Delta Change Data Feed. We enable CDF on the Base table:
ALTER TABLE main.base.customers
SET TBLPROPERTIES (
delta.enableChangeDataFeed = true
);
CDF allows downstream processes to read row-level changes made to a Delta table. It exposes metadata such as:
_change_type_commit_version_commit_timestamp
This provides an efficient mechanism for incremental processing. One important distinction: when we append records from CSV files, CDF reports those records as inserts. It does not automatically detect that a customer already exists in another batch. That comparison is part of our downstream processing.
Prep – Data quality and historical tracking
The Prep layer is where the actual data preparation takes place.
Here we:
Validate incoming data.
Apply data types.
Remove or handle duplicates.
Apply business rules.
Detect changes in customer records.
Maintain historical versions using SCD Type 2.
We'll use an ODCS Data Contract to describe the expected customer schema and required fields.
For example, a customer contract defines:
schema:
- name: customers
properties:
- name: customer_id
logicalType: string
primaryKey: true
required: true
- name: first_name
logicalType: string
required: true
- name: last_name
logicalType: string
required: true
- name: country
logicalType: string
required: true
The contract describes the expected structure and quality requirements. Our PySpark validation code enforces the selected rules at runtime.
Implementing SCD Type 2
A key requirement in many data platforms is preserving historical changes.
Suppose customer 1002 initially lives in Belgium:
| customer_id | first_name | country |
|---|---|---|
| 1002 | Piet | Belgium |
Later, the customer changes their name and country:
| customer_id | first_name | country |
|---|---|---|
| 1002 | Pieter | Netherlands |
A conventional upsert would overwrite the existing record. With SCD Type 2, we preserve the old version and insert a new one. Our Prep table, main.prep.customers, will contain:
We use the following technical columns:
valid_from: Start of the record's validity.valid_to: End of the record's validity.is_current: Indicates the active version.record_hash: Helps identify changes in tracked business attributes.
The processing logic compares incoming records with the current version in Prep. When tracked attributes change, the existing version is expired and a new version is inserted.
The result is a complete historical view of customer data.
How CDF and SCD Type 2 work together
CDF and SCD Type 2 solve different problems. Change Data Feed identifies which rows have changed in a Delta table. SCD Type 2 determines how business history should be maintained.
In our architecture, the flow is:
New files arrive in Raw.
An ingestion job appends their records to Base.
Delta CDF exposes the new records.
A preparation job reads the changes incrementally.
The incoming records are validated and compared with current customer records.
SCD Type 2 expires old versions and inserts new versions.
We also maintain a durable processing checkpoint so that the CDF consumer knows which Delta version it has already processed. This is important for reliable incremental processing and recovery after job failures. CDF itself is not a permanent archive. Its availability is subject to Delta table retention and vacuum operations. If long-term change-event retention is required, we should persist the events in a separate Delta table.
Gold – Business-ready data
The Gold layer contains data models designed for consumption by reporting tools, dashboards, and analytical workloads. For example:
main.gold.dim_customer
main.gold.fact_exchange_rates
We can create a current customer view:
CREATE OR REPLACE VIEW main.gold.dim_customer AS
SELECT *
FROM main.prep.customers
WHERE is_current = true;
This gives consumers a straightforward view of the current customer state. Other Gold models can use the historical records in Prep to perform time-based analysis, such as customer segmentation or historical reporting.
7. Orchestrating the pipeline with Databricks Jobs and Asset Bundles
We'll use separate Databricks Jobs for each major stage:
Databricks Asset Bundles (DAB) allow us to define and deploy these jobs from a local development environment, such as Visual Studio Code. This keeps the project version-controlled and makes deployment repeatable across development and production environments.
Why this architecture?
This architecture provides several benefits:
- Separation of responsibilities : Each layer has a clear purpose, making the solution easier to understand and maintain.
- Reprocessing : Original files remain available in Raw, allowing us to replay ingestion or correct transformation logic.
- Incremental processing : CDF avoids repeatedly processing the entire Base table when only a small number of records have changed.
- Historical tracking : SCD Type 2 preserves previous versions of customer data instead of simply overwriting them.
- Data governance :Unity Catalog provides centralized governance for tables, schemas, volumes, and access permissions.
- Extensibility : The same ingestion framework can support CSV files, REST APIs, and additional source systems.
Conclusion
By combining Unity Catalog Volumes, Delta Lake, Change Data Feed, and SCD Type 2, we can build a practical and extensible data platform. The Raw layer preserves the original input, Base provides a reliable Delta ingestion layer, Prep manages data quality and historical changes, and Gold exposes business-ready datasets.
The most important design principle is that each technology has a distinct responsibility:
Raw preserves the source.
Base ingests the data.
CDF tracks Delta changes.
Prep validates and historizes the data.
SCD Type 2 maintains business history.
Gold serves analytical workloads.
This gives us a solid foundation for building more advanced Databricks data pipelines without making the ingestion process and business transformations tightly coupled.
Hennie



.png)
.png)


.png)
.png)
.png)




