• Data Engineering Home
  • Data Engineering Learning Path

Databricks Data Engineering Concepts

Procedural vs. Declarative Data Processing

Overview

Procedural Data Processing

Diagram showing procedural data processing workflows in Databricks

In a procedural processing model, you explicitly specify each step-by-step operation to transform and load the data. You control the exact operational control flow (read -> filter -> aggregate -> write)

from pyspark.sql import SparkSession
from pyspark.sql.functions import col

spark = SparkSession.builder.appName("ProceduralPipeline").getOrCreate()

# Step 1: Explicitly load raw data
raw_df = spark.read.json("s3://my-bucket/data/orders.json")

# Step 2: Manually filter completed orders
filtered_df = raw_df.filter(col("status") == "COMPLETED")

# Step 3: Explicitly define aggregation logic
aggregated_df = filtered_df.groupBy("customer_id") \
                           .sum("amount") \
                           .withColumnRenamed("sum(amount)", "total_spent")

# Step 4: Manually execute write operation to destination
aggregated_df.write.format("delta").mode("overwrite").saveAsTable("customer_totals")

Declarative Data Processing

In a declarative processing model, you describe what target table or view should exist, and let the system (such as Lakeflow pipelines) automatically figure out optimization, execution order, and resource management.

-- Define the target view/table declaration
CREATE OR REFRESH MATERIALIZED VIEW customer_totals AS
SELECT 
  customer_id,
  SUM(amount) AS total_spent
FROM 
  STREAM(live.raw_orders)
WHERE 
  status = 'COMPLETED'
GROUP BY 
  customer_id;

Key Differences Comparison

AspectProcedural ProcessingDeclarative Processing
ControlFull control over executionExecution handled by system
ComplexityCan be complex and verboseGenerally simpler and more concise
OptimizationRequires manual tuningSystem handles optimization
FlexibilityHigh, but requires expertiseLower, but easier to use
Use CasesCustom pipelines, performance tuningSQL queries, managed pipelines

When to Choose Which Approach

How to Think About It