This repository contains an end-to-end implementation of a data pipeline using Databricks Declarative Pipelines, also known as Delta Live Tables (DLT). The project focuses on building a Medallion Architecture (Bronze, Silver, Gold layers), incorporating Slowly Changing Dimensions (SCD) Type 2, and implementing data quality checks and automatic dependency management. This solution leverages the latest Databricks UI and API changes from June 2025, providing a modern approach to data engineering on Databricks.
- Project Overview
- Key Features
- Architecture
- Prerequisites
- Setup & Installation
- Project Structure
- How to Run the Pipeline
- Validation
- Monitoring & Advanced Features
- Important Notes
- Project Output
This project demonstrates how Databricks Declarative Pipelines revolutionize data engineering by allowing users to declare what they want (e.g., transformations, data quality rules), while DLT automatically handles how it should be done (e.g., orchestration, infrastructure, error handling). The core components of DLT, including streaming tables, materialized views, batch views, and streaming views, are explored and utilized.
The main objective is to build a sales data warehouse following the Medallion Architecture, integrating sales data from multiple regions (East and West), and dimension data for products and customers. A key highlight is the implementation of SCD Type 2 for dimension tables, which historically requires significant effort but is greatly simplified with DLT's auto CDC capabilities.
- Declarative ETL Framework: Define data pipelines using simple SQL or Python code, letting DLT manage dependencies, transformations, and automation.
- Automatic Dependency Management: DLT automatically understands and orchestrates the flow of data based on how tables and views reference each other, eliminating the need for manual DAG configuration.
- Incremental Processing (Change Capture): Efficiently processes only new data, a critical feature for big data environments, supported by streaming tables and views.
- Unified Batch and Streaming: Use the same code for both batch and streaming operations, with DLT automatically detecting the data source type and handling it accordingly.
- Built-in Data Quality Checks (Expectations): Define rules (e.g., "column should not be null") to ensure data quality. DLT provides options to drop records, warn, or fail the entire flow if expectations are not met.
Append FlowAPI: A powerful feature for combining multiple streaming sources into a single target streaming table, highly useful for unionizing data from various regions.Auto CDC(Change Data Capture): Simplifies the creation of upserted tables and Slowly Changing Dimensions (SCD Type 1 and Type 2) without writing complex merge logic. It manages updates and inserts based on key and sequence columns.- Modern Lakeflow Code Editor UI: Utilizes the new Databricks UI for building pipelines, offering a purpose-built IDE with folder-based organization, multiple tabs, and improved developer experience.
- Medallion Architecture Implementation: Structures data into Bronze (raw), Silver (cleaned/transformed), and Gold (curated/business-ready) layers.
- Slowly Changing Dimensions (SCD Type 2): Tracks the history of changes in dimension tables automatically, adding
start_date,end_date, andin_useflags. - Pipeline Monitoring: Offers detailed monitoring dashboards, event logs, and the ability to set up notifications for pipeline failures.
- Free Databricks Edition Compatibility: The entire project can be run on Databricks Free Edition, making it accessible to all learners.
The project implements a Medallion Architecture for a sales data warehouse:
-
Bronze Layer (Ingestion):
- Ingests raw sales data from
sales_eastandsales_westsources into a unifiedsales_STGstreaming table using theappend_flowAPI. - Ingests raw
productsandcustomersdata intoproducts_STGandcustomers_STGstreaming tables. - Data quality expectations are applied at this layer (e.g.,
sales_IDnot null,product_IDnot null,pricegreater than 0).
- Ingests raw sales data from
-
Silver Layer (Transformation/Enrichment):
- Creates upserted streaming tables for
sales_enriched,products_enriched, andcustomers_enrichedfrom their respective Bronze layer sources usingcreate_auto_cdc_flow. These tables capture changes and updates. - Transformation logic (e.g., calculating
total_amount, castingpriceto integer, convertingcustomer_nameto uppercase) is applied via streaming views (sales_STG_transform,products_STG_transform,customers_STG_transform) before feeding the upserted tables.
- Creates upserted streaming tables for
-
Gold Layer (Curated/Business Views):
- Builds dimensional tables (
dim_products,dim_customers) as Slowly Changing Dimension Type 2 (SCD Type 2) usingcreate_auto_cdc_flow, tracking historical changes. These dimensions are sourced from their respective Silver layer views to ensure append-only behavior for streaming transformations. - Creates a fact table (
fact_sales) as an upserted table (SCD Type 1) from thesales_enriched_view. - A materialized business view (
business_sales) is created by joining the fact and dimension tables, performing aggregations (e.g.,total_salesby region and category) to support specific business use cases. This materialized view processes all data, unlike streaming views, ensuring complete aggregated results.
- Builds dimensional tables (
To run this project, you will need:
- Databricks Account: A Databricks Free Edition account is sufficient. No business email, Azure subscription, or credit card is required.
- Basic Databricks Knowledge: Familiarity with Databricks workspace, catalogs, schemas, and basic Python/SQL is helpful.
- Databricks Experimental Features Enabled:
- Go to Settings > Developer.
- Enable "Lakeflow pipeline editor". This is crucial for experiencing the new UI and structured folder-based authoring.
- (Optional) Enable other previews or change editor themes for a personalized experience.
-
Create Databricks Free Edition Account:
- Go to any browser and search for "Databricks Free Edition".
- Click on "Try Databricks" and then "Looking for Databricks Free Edition? Click here".
- Login with your normal Gmail account.
- Once created, use the "Login" button to access your workspace.
-
Create Catalog and Schemas:
- In your Databricks Workspace, navigate to the Catalog tab.
- Click the "+" button and select "Create a Catalog". Name it
DLT_ON(or any preferred name) and configure it forAll Workspaces have accessandAll privileges. - Within your
DLT_ONcatalog, create two schemas:source: To store raw source tables.DLT_schema: To store all objects created by the DLT pipeline (streaming tables, materialized views).
-
Upload Source Data (SQL DDL):
- Clone this GitHub repository to your local machine.
- In Databricks, go to the Workspace tab.
- Create a new folder (e.g.,
declarative_pipelines). - Within this folder, create a new Query. Rename it
data_warehouse_source. - Open the
SQL_DDL.sqlfile from this repository (located indelta_live_tables/SQL_DDL.sql). - Crucially, ensure your SQL editor is set to the
DLT_ONcatalog andsourceschema. - Copy and paste the
CREATE TABLEandINSERT INTOstatements forsales_east,sales_west,products, andcustomersinto your Databricks SQL editor. - Run each
CREATE TABLEand its initialINSERT INTOstatement individually (select the code and click "Run selected" or "Run" if it's the only statement) to populate yoursourceschema with initial data. Do NOT run the incremental load statements yet.
The DLT pipeline source code is organized into a DLT_root folder within your Databricks workspace, following best practices for modularity.
DLT_root/bronze/injection_customers.py: Ingests customer data with quality checks.injection_products.py: Ingests product data with quality checks.injection_sales.py: Ingests sales data from East/West sources usingappend_flowwith quality checks.
silver/transform_customers.py: Transforms customer data (e.g., uppercase customer name) and creates an upserted Silver table and a streaming view for Gold.transform_products.py: Transforms product data (e.g., cast price to int) and creates an upserted Silver table and a streaming view for Gold.transform_sales.py: Transforms sales data (e.g., calculates total amount) and creates an upserted Silver table and a streaming view for Gold.
gold/dim_customers.py: Creates SCD Type 2 dimension for customers.dim_products.py: Creates SCD Type 2 dimension for products.fact_sales.py: Creates an upserted fact table for sales.business_sales.py: Creates a materialized business view for aggregated sales by region and category.
explorations/example_exploratory_notebook.py: A non-source code folder for quick data exploration and debugging during development. Files here are not run as part of the pipeline.
tutorial/(Commented out in this project): Contains initial examples and core component demonstrations.
-
Create DLT Pipeline:
- In Databricks, navigate to the Jobs and Pipelines tab.
- Click "Create" and select "ETL Pipeline".
- Set the Catalog to
DLT_ONand Schema toDLT_schema. - Enable "Lakeflow pipelines editor".
- Select "Start with sample code in Python".
-
Move Root Folder and Import Files:
- Once the new pipeline UI loads, it creates a default root folder (e.g., "new pipeline"). Rename this root folder to
DLT_root(or your preferred name). - Move this
DLT_rootfolder into your desired workspace directory (e.g.,declarative_pipelines) using the "Move root folder" option from the three dots menu next to the root folder name. Do not copy/paste files outside the assets browser as it will break synchronization. - Create the
bronze,silver, andgoldsubfolders withinDLT_rootvia the assets browser. - Create new files within these subfolders (e.g.,
injection_sales.pyinbronze/) and copy the Python code from the respective files in this GitHub repository into them. Ensure to un-comment the code as you copy it.
- Once the new pipeline UI loads, it creates a default root folder (e.g., "new pipeline"). Rename this root folder to
-
Run the Pipeline:
- In the DLT pipeline UI, click "Dry Run" initially to visualize the DAG and check for any immediate syntax errors without processing data.
- Once the dry run is successful, click "Run Pipeline". This will execute the entire DLT pipeline, ingest data, apply transformations, and build the Medallion Architecture.
- The pipeline will show its progress and lineage graph in real-time. All tasks should turn green upon successful completion.
After the initial pipeline run:
-
Check Catalog: Navigate to the Catalog tab in Databricks. In your
DLT_ONcatalog andDLT_schema, you should see all the created streaming tables and materialized views (e.g.,sales_STG,products_STG,customers_STG,sales_enriched,products_enriched,customers_enriched,dim_products,dim_customers,fact_sales,business_sales). -
Query Tables: Use the SQL editor to query your tables and views, especially the Gold layer tables:
SELECT * FROM DLT_ON.DLT_schema.dim_productsSELECT * FROM DLT_ON.DLT_schema.dim_customersSELECT * FROM DLT_ON.DLT_schema.fact_salesSELECT * FROM DLT_ON.DLT_schema.business_sales
-
Validate SCD Type 2:
- Go back to your
data_warehouse_sourceSQL query in Databricks. - Run the
INSERT INTOstatements for incremental data (forsales_east,sales_west, and especiallyproductsupdates) that you previously commented out. This will add new records and update existing ones in your source tables. - Rerun the DLT pipeline.
- After the run, query
dim_productsagain. You should observe new rows for updated products, with theend_datepopulated for the older versions andnullfor the latest versions, demonstrating successful SCD Type 2 implementation.
- Go back to your
- Pipeline Monitoring Dashboard: In the Jobs and Pipelines tab, click on your DLT pipeline. The canvas provides a detailed overview of the latest run, showing processed records, upserted records, and expectation fulfillment.
- Expectations: Click on any task in the pipeline graph and then the "Expectations" tab to see if your data quality rules (defined in Bronze layer) were met (100% met should be shown for healthy data).
- Notifications: In pipeline settings, you can configure email notifications to be alerted if the pipeline fails or encounters errors.
- Parameters: DLT pipelines support parameters (key-value pairs) via the settings, which are always passed as strings and may require parsing in your code.
- Scheduling: Pipelines can be scheduled to run at specific intervals (e.g., daily, hourly) for automated execution.
- Integration with Databricks Jobs: DLT pipelines can be orchestrated as tasks within broader Databricks Jobs, allowing for complex multi-component workflows.
- Databricks Free Edition Limits: When using Databricks Free Edition, avoid opening too many tabs, files, or notebooks simultaneously as resources can be exhausted. If you encounter "resources exhausted" errors, wait 30-60 minutes and refresh your workspace.
- Delete Old Pipelines: If you create a new DLT pipeline, ensure to delete existing ones to conserve free resources.
- Dry Run First: Always use "Dry Run" before a full pipeline run to check for errors and visualize the DAG without consuming significant compute resources.
- YAML Configuration: The underlying configuration of DLT pipelines is often represented in YAML, which is becoming increasingly popular in declarative frameworks. Familiarity with basic YAML syntax is beneficial.
- Products Dimensions
- Business Sales
Feel free to explore the code, experiment with transformations, and adapt it for your own data engineering challenges! Happy learning!


