CDC-Based Customer Data Pipeline
Design and implement a low-latency Change Data Capture (CDC) processing pipeline handling INSERT, UPDATE, and DELETE event streams with out-of-order sequencing, duplicate suppression, replayability, and current-state materialization in Delta Lake and Snowflake.
Project Brief
Understand real-time Change Data Capture (CDC), event stream processing, and current-state replication.
Business Scenario
The core customer operations database processes hundreds of thousands of customer profile updates, new registrations, address modifications, and GDPR account deletions every day. Currently, downstream analytics teams rely on heavy, expensive nightly full-table batch extractions that lock operational databases and introduce a 24-hour latency.
The business requires a low-latency Change Data Capture (CDC) pipeline that continuously ingests operational database change logs (INSERT, UPDATE, DELETE) and maintains an up-to-date, trusted customer master table in Delta Lake and Snowflake without performing full historical reloads.
Development Objective
Design and implement a robust, production-grade CDC pipeline in Databricks and PySpark. The pipeline must ingest CDC event streams, handle out-of-order and duplicate events, determine the true latest state of each customer, apply idempotent MERGE operations into a Silver current-state Delta table, maintain an immutable historical audit log, and publish synchronized customer datasets to Snowflake.
Expected Outcome
The primary engineering challenges in CDC are event ordering, handling multiple updates to the same customer within a single micro-batch, processing hard/soft deletes, and ensuring exactly-once business outcomes upon stream replay.
Source System
Inspect CDC event stream format, operation codes, log sequence numbers, and payload structures.
Source Event Stream Overview
The source system is an operational database CDC stream (e.g., Debezium, AWS DMS, or Kafka log stream) emitting row-level change events. For development and testing, CDC streams can be simulated using streaming JSON event files or test event generators.
Example CDC Event Payloads
Each event represents an atomic database operation on a customer record:
// 1. INSERT EVENT
{
"event_id": "EVT-1001",
"customer_id": "C-9021",
"operation": "INSERT",
"event_timestamp": "2026-08-30T10:00:00Z",
"customer_name": "Aarav Sharma",
"email": "aarav.sharma@example.com",
"phone": "+91-9876543210",
"city": "Bengaluru",
"country": "India",
"status": "ACTIVE",
"metadata": {
"source_table": "customers",
"lsn": "00000028:000001bc:0001",
"tx_id": "TX-49201"
}
}
// 2. UPDATE EVENT
{
"event_id": "EVT-1002",
"customer_id": "C-9021",
"operation": "UPDATE",
"event_timestamp": "2026-08-30T11:15:00Z",
"customer_name": "Aarav Sharma",
"email": "aarav.sharma@newdomain.com",
"phone": "+91-9876543210",
"city": "Mumbai",
"country": "India",
"status": "ACTIVE",
"metadata": {
"source_table": "customers",
"lsn": "00000028:000001bc:0002",
"tx_id": "TX-49280"
}
}
// 3. DELETE EVENT
{
"event_id": "EVT-1003",
"customer_id": "C-9021",
"operation": "DELETE",
"event_timestamp": "2026-08-30T14:30:00Z",
"customer_name": null,
"email": null,
"phone": null,
"city": null,
"country": null,
"status": "DELETED",
"metadata": {
"source_table": "customers",
"lsn": "00000028:000001bc:0003",
"tx_id": "TX-49350"
}
}CDC Event Schema Fields
Known CDC Source Constraints
The pipeline must achieve deterministic, exactly-once business state regardless of network re-deliveries, batch sizes, or out-of-order message arrivals.
Expected Architecture
Layered CDC lakehouse architecture: Bronze changelog, Silver current-state materialization, and Gold analytics.
Target Architecture Flow
The CDC architecture separates append-only changelog storage (Bronze) from stateful customer materialization (Silver) and analytical aggregations (Gold).
Layer Responsibilities
Architectural Expectations
Never perform Delta MERGE directly on raw streaming batches containing duplicate customer_ids. Always reduce and deduplicate to the latest change per customer within the batch first!
Development Requirements
Implement the streaming ingestion, windowed deduplication, MERGE logic, and Snowflake sync.
Developer Responsibilities
The implementation must fulfill the following 17 engineering requirements across streaming ingestion, change ordering, state materialization, and validation.
CDC Stream Ingestion & Checkpointing
Establish reliable streaming ingestion with state checkpoints.
Bronze Event Changelog Persistence
Persist an immutable audit log of all raw change events.
Operation Code Validation
Validate and categorize incoming operation types.
Micro-Batch Change Deduplication
Deduplicate multiple changes for the same customer within a single batch.
Out-of-Order Event Protection
Prevent older delayed events from overwriting newer state in Silver.
INSERT Operation Processing
Process new customer creations.
UPDATE Operation Processing
Apply attribute modifications to existing customer records.
DELETE Operation Processing
Handle customer account deletions and GDPR purge requests.
Idempotent Delta MERGE Implementation
Execute atomic upsert operations against the Silver table.
Late-Arriving CDC Event Handling
Handle events arriving significantly after their occurrence window.
Silver Current-State Customer Dataset
Maintain the query-optimized Silver customer master table.
Gold Customer Lifecycle Analytics
Generate analytical metrics and aggregated business views.
Snowflake Synchronization Pipeline
Replicate current customer state and analytical marts to Snowflake.
Audit History & Lineage Tracking
Maintain complete traceability for compliance and audits.
Disaster Recovery & Replay Pipeline
Provide automated mechanism to rebuild Silver state from Bronze.
Data Quality Assertions & Quarantine
Prevent dirty CDC records from corrupting master tables.
Configuration & Environment Management
Externalize all streaming parameters and storage paths.
You have full freedom to choose your exact merge syntax, streaming trigger intervals, and delete strategy (soft vs hard). Document your rationale and prove its correctness through testing.
Testing Requirements
Thoroughly test INSERT, UPDATE, DELETE, out-of-order events, duplicate streams, and disaster replay.
Required Test Scenarios
Validate the CDC pipeline against the following 13 test scenarios:
CDC systems must be rock-solid against out-of-order delivery, crashes, and network re-deliveries. Every edge case must be demonstrated with automated tests.
Acceptance Criteria
Verify that the CDC pipeline fulfills all production Definition of Done criteria.
Definition of Done
The implementation is complete when all 12 criteria are satisfied:
Approval requires execution logs proving that multi-event batches, duplicate replays, and out-of-order events leave the Silver master in a 100% correct state.
Developer Deliverables
Submit all streaming code, MERGE logic, replay scripts, tests, and evidence.
Required Deliverables
Provide the following 11 deliverables in your repository:
Ensure your test harness allows another engineer to simulate a stream of 10,000 mixed events and verify the outcome.
Engineering Constraints
Adhere to operational and technical boundaries for mission-critical CDC pipelines.
Required Boundaries
The implementation must strictly comply with the following 10 constraints:
Failing to handle out-of-order events or executing MERGE on un-deduplicated streaming batches will result in code review rejection.
Suggested Project Structure
Recommended repository layout for production CDC streaming pipelines.
Recommended Project Layout
Structure your repository to separate streaming ingestion, deduplication windowing, Delta MERGE, recovery, and tests:
DEV-005-cdc-customer-pipeline/
โ
โโโ README.md
โ
โโโ config/
โ โโโ dev.yaml
โ โโโ prod.yaml
โ
โโโ src/
โ โโโ ingestion/
โ โ โโโ stream_reader.py # Structured Streaming / micro-batch consumer
โ โ โโโ bronze_logger.py # Immutable append-only Bronze changelog
โ โโโ processing/
โ โ โโโ window_dedup.py # LSN & timestamp windowing deduplication
โ โ โโโ delta_merger.py # Idempotent Delta MERGE for INSERT/UPDATE/DELETE
โ โ โโโ quarantine.py # Bad record & invalid operation handler
โ โโโ analytics/
โ โ โโโ customer_kpis.py # Gold customer metrics & churn aggregation
โ โโโ replication/
โ โ โโโ snowflake_sync.py # Synchronize master state to Snowflake
โ โโโ recovery/
โ โโโ replay_engine.py # Rebuild Silver state from Bronze changelog
โ
โโโ tests/
โ โโโ mock_cdc_stream.py # Event generator (INSERT, UPDATE, DELETE)
โ โโโ test_multi_change_batch.py
โ โโโ test_out_of_order.py
โ โโโ test_duplicate_suppression.py
โ โโโ test_replay_recovery.py
โ
โโโ docs/
โโโ cdc_architecture.md # Architecture diagram and state machine
โโโ recovery_playbook.md # Disaster recovery and replay stepsModule Responsibilities
Decoupling the windowing deduplication module from the Delta MERGE module allows unit-testing the state resolution logic in isolation without needing live database connections.
Submission Checklist
Final engineering quality checklist before submitting DEV-005.
Final Review Checklist
Verify every checklist item before submitting your CDC pipeline:
Submit DEV-005 only after the streaming ingestion, Bronze changelog, windowing deduplication, Delta MERGE, Snowflake sync, disaster replay, and test suites have been verified.