Skip to main content
Difficulty
Advanced
Reward
500 XP ยท ๐Ÿ”„ Change Data Engineer
Prerequisites
Structured Streaming ยท Delta Lake ยท CDC Concepts
Primary Stack
Databricks ยท PySpark ยท Delta Lake
Target
Snowflake
Development Task
DEV-005

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.

01

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

CDC Stream Ingestion
Capture continuous INSERT, UPDATE, and DELETE event streams with full metadata fidelity.
Event Sequencing & Windowing
Order multiple changes per customer within and across batches using log sequence numbers (LSN) and event timestamps.
Duplicate Event Suppression
Filter redundant or replayed CDC messages to prevent state corruption.
Current-State Materialization
Maintain an active, query-ready Silver Customer Delta table using idempotent MERGE / delete logic.
Immutable Audit History
Preserve the complete historical timeline of customer modifications for compliance and debugging.
Snowflake Synchronization
Synchronize latest customer state and operational metrics to Snowflake with zero latency lag.
Developer Focus

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.

02

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.

Source Type
CDC Event Stream (JSON / Kafka)
Operations Supported
INSERT, UPDATE, DELETE
Processing Mode
Structured Streaming / Micro-batch
Ordering Key
event_timestamp + lsn / sequence_id
Primary Business Key
customer_id
Target State
Current Customer Master

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

event_id*
STRING
Unique identifier for the CDC event message.
customer_id*
STRING
Primary business identifier of the customer record.
operation*
STRING
CDC action: 'INSERT', 'UPDATE', or 'DELETE'.
event_timestamp*
TIMESTAMP
ISO UTC timestamp when the database transaction occurred.
customer_name
STRING
Customer full name (null for DELETE events).
email
STRING
Customer email address.
city / country
STRING
Geographic attributes of the customer.
status*
STRING
Lifecycle status ('ACTIVE', 'INACTIVE', 'SUSPENDED', 'DELETED').
metadata.lsn*
STRING
Log Sequence Number strictly guaranteeing source commit ordering.

Known CDC Source Constraints

Multiple Changes per Micro-Batch
A single ingestion batch may contain an INSERT and two subsequent UPDATEs for the same customer_id.
Out-of-Order Event Arrival
Network latency may cause an older UPDATE to arrive after a newer UPDATE event.
Duplicate CDC Events
At-least-once message delivery yields duplicate event_ids during network reconnects.
Hard vs Soft Deletes
Deletes may require soft-deletion flags (is_deleted=true) or physical record removal.
Late-Arriving Events
Historical change events from hours or days prior may arrive during catch-up periods.
CDC Engineering Contract

The pipeline must achieve deterministic, exactly-once business state regardless of network re-deliveries, batch sizes, or out-of-order message arrivals.

03

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).

01
Operational Database CDC Stream
Kafka / Debezium / Cloud Queue
Emits row-level change events (INSERT, UPDATE, DELETE) with transaction metadata.
โ†“
02
CDC Ingestion Engine
Structured Streaming / PySpark
Consumes streaming event batches, validates JSON schemas, and coordinates checkpoints.
โ†“
03
Bronze โ€” Immutable Event Changelog
Delta Lake (Append-Only)
Stores all raw change events with ingestion metadata, enabling full point-in-time replay.
โ†“
04
Change Ordering & Windowing
PySpark Windowing
Deduplicates events and selects the highest LSN / latest timestamp per customer within each micro-batch.
โ†“
05
Silver โ€” Current Customer State
Delta Lake (MERGE / CDF)
Maintains the current single-version-of-truth customer master using idempotent Delta MERGE logic.
โ†“
06
Gold โ€” Customer Analytics & Marts
Databricks / PySpark
Computes customer lifecycle metrics, churn indicators, and daily registration summaries.
โ†“
07
Snowflake Replication Target
Snowflake
Synchronizes current customer records and analytical KPIs for enterprise BI tools.

Layer Responsibilities

Bronze Changelogยท Immutable Audit Trail
Append-only Delta table preserving every change event in sequence. Never mutated, enabling complete disaster recovery replay.
Silver Current Stateยท Single Version of Truth
Keyed on customer_id. Applies latest INSERT/UPDATE values and marks or deletes terminated customer records.
Gold Analyticsยท Downstream Metrics
Calculates customer demographic distributions, active customer counts by region, and daily status churn rates.

Architectural Expectations

Deterministic State Resolution
Within each micro-batch, windowing must pick the change event with the highest LSN / timestamp before executing MERGE.
Idempotent Delta MERGE
Rerunning a micro-batch must result in the exact same customer state without creating duplicate records.
Graceful Delete Handling
DELETE operations must either execute WHEN MATCHED THEN DELETE or update is_deleted=true / status='DELETED'.
Full Replayability
Truncating Silver and replaying the Bronze event changelog from batch 0 must reconstruct the exact current state.
CDC Architecture Principle

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!

04

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.

01

CDC Stream Ingestion & Checkpointing

Establish reliable streaming ingestion with state checkpoints.

Required Checklist
โœ“Implement PySpark Structured Streaming or micro-batch reader for CDC event files/streams.
โœ“Configure persistent checkpoint directories for fault-tolerant state recovery.
โœ“Enforce schema validation on incoming JSON change records.
Expected Outcome
Resilient streaming ingestion without dropped change messages.
02

Bronze Event Changelog Persistence

Persist an immutable audit log of all raw change events.

Required Checklist
โœ“Append raw CDC events to Bronze Delta table partitioned by ingestion_date.
โœ“Preserve original event_id, operation, metadata.lsn, and event_timestamp.
โœ“Enable Delta Change Data Feed (CDF) on the table if applicable.
Expected Outcome
Complete historical event ledger enabling full replayability.
03

Operation Code Validation

Validate and categorize incoming operation types.

Required Checklist
โœ“Assert operation is strictly one of: 'INSERT', 'UPDATE', 'DELETE'.
โœ“Standardize operation string casing (uppercase trimmed).
โœ“Quarantine events with unknown or null operation codes.
Expected Outcome
Clean operation routing preventing pipeline failures.
04

Micro-Batch Change Deduplication

Deduplicate multiple changes for the same customer within a single batch.

Required Checklist
โœ“Apply PySpark Window: partitionBy('customer_id').orderBy(col('metadata.lsn').desc(), col('event_timestamp').desc()).
โœ“Filter row_number == 1 to retain only the latest state per customer in the batch.
Expected Outcome
Clean, single-row-per-customer DataFrame ready for MERGE.
05

Out-of-Order Event Protection

Prevent older delayed events from overwriting newer state in Silver.

Required Checklist
โœ“Compare incoming event_timestamp / LSN against existing Silver record's last_updated_timestamp.
โœ“Ensure MERGE updates only apply when incoming_event_timestamp >= existing_last_updated_timestamp.
Expected Outcome
State consistency immune to out-of-order message delivery.
06

INSERT Operation Processing

Process new customer creations.

Required Checklist
โœ“Insert new record into Silver table when customer_id does not currently exist.
โœ“Populate created_at and last_updated_at timestamps.
โœ“Set is_deleted = false and is_active = true.
Expected Outcome
Accurate new customer onboarding in Silver master.
07

UPDATE Operation Processing

Apply attribute modifications to existing customer records.

Required Checklist
โœ“Update customer attributes (name, email, city, status) when customer_id matches.
โœ“Update last_updated_at timestamp and latest_lsn in Silver.
โœ“Handle partial updates where unspecified attributes retain current values.
Expected Outcome
Up-to-date customer profile attributes.
08

DELETE Operation Processing

Handle customer account deletions and GDPR purge requests.

Required Checklist
โœ“Implement soft-delete logic: set is_deleted = true, status = 'DELETED', deleted_at = event_timestamp.
โœ“Support physical deletion mode where configured: execute WHEN MATCHED AND operation = 'DELETE' THEN DELETE.
โœ“Ensure deleted records are filtered from downstream active analytics views.
Expected Outcome
Compliant, accurate customer deletion processing.
09

Idempotent Delta MERGE Implementation

Execute atomic upsert operations against the Silver table.

Required Checklist
โœ“Write PySpark DeltaTable.merge() statement with WHEN MATCHED and WHEN NOT MATCHED clauses.
โœ“Ensure merge condition matches strictly on target.customer_id == source.customer_id.
โœ“Wrap batch execution in foreachBatch handler for Structured Streaming.
Expected Outcome
Atomic, idempotent state updates across all micro-batches.
10

Late-Arriving CDC Event Handling

Handle events arriving significantly after their occurrence window.

Required Checklist
โœ“Log late-arriving events in telemetry audit table.
โœ“Apply late event only if customer record has not been updated by a subsequent transaction.
Expected Outcome
Graceful handling of delayed change messages.
11

Silver Current-State Customer Dataset

Maintain the query-optimized Silver customer master table.

Required Checklist
โœ“Optimize Silver Delta table with Z-ORDER BY (city, status).
โœ“Include operational audit columns: last_event_id, last_operation, last_lsn, last_updated_at.
Expected Outcome
High-performance Silver customer master table.
12

Gold Customer Lifecycle Analytics

Generate analytical metrics and aggregated business views.

Required Checklist
โœ“Calculate active customer count by city and country.
โœ“Compute daily new customer registration counts and churn rates.
โœ“Summarize customer status distribution across active, inactive, and deleted accounts.
Expected Outcome
Business-ready Gold tables for executive reporting.
13

Snowflake Synchronization Pipeline

Replicate current customer state and analytical marts to Snowflake.

Required Checklist
โœ“Synchronize Silver customer master to Snowflake DIM_CUSTOMER_CURRENT.
โœ“Synchronize Gold analytics tables to Snowflake AGG_CUSTOMER_METRICS.
โœ“Ensure synchronization is idempotent and maintains referential consistency.
Expected Outcome
Synchronized Snowflake warehouse accessible by BI users.
14

Audit History & Lineage Tracking

Maintain complete traceability for compliance and audits.

Required Checklist
โœ“Log every micro-batch execution with batch_id, records_processed, inserts, updates, deletes, duration.
โœ“Emit structured JSON metrics to operational logging table.
Expected Outcome
Full auditability for data governance and compliance.
15

Disaster Recovery & Replay Pipeline

Provide automated mechanism to rebuild Silver state from Bronze.

Required Checklist
โœ“Build replay script that truncates Silver and re-applies Bronze events in LSN order.
โœ“Demonstrate that replayed state reconciles 100% with original state.
Expected Outcome
Proven disaster recovery and state reconstruction capability.
16

Data Quality Assertions & Quarantine

Prevent dirty CDC records from corrupting master tables.

Required Checklist
โœ“Assert customer_id is non-null and matches valid format.
โœ“Assert event_timestamp is valid ISO date not in the future.
โœ“Route invalid events to CDC quarantine Delta table.
Expected Outcome
Zero master data corruption from malformed messages.
17

Configuration & Environment Management

Externalize all streaming parameters and storage paths.

Required Checklist
โœ“Externalize checkpoint paths, batch trigger intervals, schema names, and storage URIs in YAML/JSON configs.
Expected Outcome
Seamless deployment across dev, test, and production environments.
Implementation Guidance

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.

05

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:

01
New Customer INSERT Scenario
Scenario
Stream an INSERT event for a new customer_id.
Expected Result
Silver table creates a new active customer record with correct attribute values and last_operation = 'INSERT'.
02
Customer Profile UPDATE Scenario
Scenario
Stream an UPDATE event modifying email and city for an existing customer.
Expected Result
Silver table updates the customer record in-place with new email/city, updating last_updated_at.
03
Customer Account DELETE Scenario
Scenario
Stream a DELETE event for an existing customer.
Expected Result
Silver table marks record as is_deleted = true / status = 'DELETED' (or removes row if hard-delete configured).
04
Multiple Changes in a Single Micro-Batch
Scenario
Provide a micro-batch containing 1 INSERT and 2 sequential UPDATEs for the same customer_id.
Expected Result
Pipeline applies the final UPDATE state; Silver contains exactly 1 row with the latest attributes.
05
Duplicate CDC Event Suppression
Scenario
Re-send identical CDC event messages with same event_id and LSN.
Expected Result
Pipeline processes events idempotently without corrupting data or creating duplicate rows.
06
Out-of-Order Event Arrival
Scenario
Deliver an older UPDATE event (timestamp 10:00) after a newer UPDATE event (timestamp 11:00) has already been processed.
Expected Result
Pipeline detects stale timestamp/LSN and ignores the older event, preserving the latest state.
07
Late-Arriving Event Recovery
Scenario
Inject a valid change event with a timestamp from 24 hours prior.
Expected Result
Pipeline logs late-data telemetry and incorporates change only if no newer version exists.
08
Streaming Crash & Checkpoint Recovery
Scenario
Simulate cluster termination mid-stream and restart pipeline from checkpoint directory.
Expected Result
Pipeline resumes from exact checkpoint offset without data loss or duplicate state corruption.
09
Full Historical Replay from Bronze
Scenario
Truncate Silver table and re-run batch replay script across all Bronze events.
Expected Result
Reconstructed Silver table matches 100% with previous master table state.
10
Invalid Operation Code Rejection
Scenario
Deliver an event with operation = 'INVALID_OP'.
Expected Result
Event is rejected and routed to quarantine table; valid events in the batch proceed normally.
11
Missing Primary Identifier (customer_id = null)
Scenario
Deliver an event missing customer_id.
Expected Result
Event is captured in quarantine table with failure_reason = 'NULL_CUSTOMER_ID'.
12
State Reconciliation vs Expected Benchmark
Scenario
Process a benchmark dataset of 10,000 mixed INSERT, UPDATE, and DELETE operations.
Expected Result
Final Silver table row counts, active counts, and attribute values reconcile 100% with benchmark.
13
Snowflake Target Synchronization Test
Scenario
Query Snowflake DIM_CUSTOMER_CURRENT after streaming execution.
Expected Result
Snowflake table matches Silver Delta master table in row counts, active states, and attribute values.
Testing Principle

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.

06

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:

01
INSERTs Create Customer Records
New customer creations are populated correctly in Silver with all attributes.
02
UPDATEs Produce Latest State
Modifications update Silver records in-place with latest attributes and timestamps.
03
DELETEs Handled Correctly
Deletions update soft-delete flags or remove records according to defined delete policy.
04
Multi-Change Batches Resolved
Multiple updates for the same customer within a batch resolve to the single latest state.
05
Duplicate Messages Suppressed
Duplicate CDC events do not corrupt state or inflate master table rows.
06
Out-of-Order Events Controlled
Stale events arriving out-of-order do not overwrite newer master records.
07
Bronze Changelog Preserved
Immutable append-only Bronze table stores all raw events for audit and replay.
08
Disaster Recovery Replay Proven
Replaying Bronze changelog reconstructs 100% accurate Silver master state.
09
Fault-Tolerant Checkpointing
Pipeline recovers seamlessly from unexpected process failures without data loss.
10
Snowflake Target Synchronized
Current customer master is synchronized to Snowflake with matching row counts.
11
Dead-Letter Quarantine Active
Malformed payloads and null keys are segregated with rejection diagnostics.
12
All 13 Test Scenarios Pass
Complete test suite executes successfully with attached validation proof.
Acceptance Rule

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.

07

Developer Deliverables

Submit all streaming code, MERGE logic, replay scripts, tests, and evidence.

Required Deliverables

Provide the following 11 deliverables in your repository:

01
Streaming CDC Ingestion Module
PySpark streaming/micro-batch module consuming CDC events and managing checkpoints.
02
Bronze Changelog Persistence Logic
Append-only writer logging all raw change events with ingestion metadata.
03
Batch Windowing & Deduplication Logic
PySpark logic picking the highest LSN / latest timestamp per customer within each batch.
04
Silver Delta MERGE Module
Idempotent MERGE implementation applying INSERT, UPDATE, and DELETE actions.
05
Dead-Letter Quarantine Handler
Module isolating malformed operations or null keys into quarantine storage.
06
Gold Analytics Aggregation Pipeline
Pipelines computing active customer counts, churn rates, and geographic distributions.
07
Snowflake Synchronization Module
Connector script replicating current customer master to Snowflake target tables.
08
Disaster Recovery & Replay Script
Automated script rebuilding Silver state from scratch by replaying Bronze changelog.
09
CDC Event Generator / Mock Harness
Test harness simulating streaming INSERT, UPDATE, DELETE, and out-of-order events.
10
Automated Test Suite
Complete test suite covering all 13 required verification scenarios.
11
CDC Architecture & Operations Guide
README documentation covering state reconciliation, LSN ordering, and recovery playbooks.
Submission Principle

Ensure your test harness allows another engineer to simulate a stream of 10,000 mixed events and verify the outcome.

08

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:

01
Zero Silent Event Loss
Every received CDC event must be logged to Bronze or routed to quarantine with explicit diagnostics.
02
Mandatory LSN / Timestamp Ordering
State mutations must strictly obey event sequencing; stale events must never overwrite newer state.
03
Deduplication Before MERGE
Raw batches must be reduced to one change per customer before executing Delta MERGE statements.
04
Explicit Delete Handling
DELETE events must not be ignored; they must execute configured soft or hard deletion.
05
Idempotent State Mutations
Re-running any micro-batch must result in deterministic, uncorrupted customer state.
06
Observable Stream Telemetry
Every batch execution must emit records processed, latency lag, and operation counts.
07
Configuration Externalization
Storage URIs, checkpoint paths, trigger intervals, and Snowflake credentials must not be hard-coded.
08
Scalable Distributed Processing
Processing must scale across Spark worker nodes without accumulating unbounded state in driver memory.
09
Immutable Bronze Ledger
Bronze changelog tables must remain append-only and never be updated or deleted in place.
10
Production Code Quality
Code must be modular, fully unit-tested, and formatted according to PEP-8 standards.
Constraint Notice

Failing to handle out-of-order events or executing MERGE on un-deduplicated streaming batches will result in code review rejection.

09

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 steps

Module Responsibilities

src/ingestion/
Manages streaming readers, checkpoint state, and append-only Bronze changelog writing.
src/processing/
Contains windowing deduplication (row_number by LSN) and idempotent Delta MERGE logic.
src/analytics/
Computes Gold customer lifecycle metrics, active account counts, and churn rates.
src/replication/
Synchronizes current customer master and analytical marts to Snowflake.
src/recovery/
Provides automated disaster recovery engine to rebuild Silver state from Bronze.
tests/
Complete test suite and mock event generator for multi-event, out-of-order, and replay tests.
docs/
State transition diagrams, LSN ordering documentation, and disaster recovery playbooks.
Design Rationale

Decoupling the windowing deduplication module from the Delta MERGE module allows unit-testing the state resolution logic in isolation without needing live database connections.

10

Submission Checklist

Final engineering quality checklist before submitting DEV-005.

Final Review Checklist

Verify every checklist item before submitting your CDC pipeline:

โœ“
Streaming Ingestion & Checkpointing Configured
Structured Streaming / micro-batch pipeline runs with fault-tolerant checkpoint directories.
โœ“
Bronze Changelog Ledger Preserved
Append-only Bronze table stores all raw change events with LSN and timestamps.
โœ“
Micro-Batch Windowing Deduplication Enforced
Windowing selects the highest LSN change per customer before executing MERGE.
โœ“
INSERT, UPDATE, DELETE Operations Verified
All three operation types mutate Silver master state accurately according to business rules.
โœ“
Out-of-Order & Duplicate Protection Tested
Stale events and duplicate deliveries do not overwrite newer master records.
โœ“
Idempotent Delta MERGE Validated
Re-running micro-batches yields identical, deterministic customer master state.
โœ“
Disaster Recovery Replay Demonstrated
Replaying Bronze changelog from scratch reconstructs 100% accurate Silver state.
โœ“
Gold Lifecycle Analytics Populated
Active customer counts and churn metrics are computed accurately.
โœ“
Snowflake Synchronization Active
Current customer master is synchronized to Snowflake target tables without row inflation.
โœ“
Quarantine Dead-Letter Active
Malformed payloads and null customer_ids are diverted with rejection telemetry.
โœ“
All 13 Test Scenarios Executed
Automated test suite passes with execution logs and state reconciliation evidence.
โœ“
Configuration Externalized
All storage URIs, trigger intervals, and database credentials are fully externalized.
โœ“
Documentation Complete
README contains architecture diagrams, state machines, and disaster recovery playbooks.
Ready for Review

Submit DEV-005 only after the streaming ingestion, Bronze changelog, windowing deduplication, Delta MERGE, Snowflake sync, disaster replay, and test suites have been verified.