VAYULearn
Colour theme
Investigate a failure
VAYU Learn

Kafka & Streaming

Change Data Capture (CDC) — Real-Time Ingestion Patterns That Actually Work

How modern data teams move data in real time without breaking databases or pipelines.

Kafka & StreamingDatabricks & LakehouseSQL & DatabasesData Architecture & Reliability

TL;DR

Change Data Capture (CDC) streams row-level changes from databases (INSERT/UPDATE/DELETE) in real time.
Tools like Debezium, Kafka Connect, and Fivetran make this possible — but only if you design CDC pipelines correctly.
Most CDC failures come from bad modeling, wrong tooling, or ignoring downstream implications.

This blog shows what CDC really is, how it works, where it breaks, and which patterns actually survive production.


📘 Introduction

Every modern data system wants fresh data.

Dashboards want updates in minutes.
Fraud systems want updates in seconds.
ML models want features now, not tomorrow.

The naive approach?
👉 Poll databases every few minutes.

That works… until it doesn’t.

  • Databases slow down
  • Latency increases
  • Costs explode
  • Teams lose trust

CDC exists to solve this — but only when done right.

Let’s break CDC down like real engineers.


🧠 1. What is Change Data Capture (CDC)? (No Marketing BS)

CDC is a technique to capture row-level changes from a source database as they happen.

Instead of re-reading entire tables, CDC captures only:

  • INSERTs
  • UPDATEs
  • DELETEs

Key idea:

👉 Move changes, not snapshots.

🚫 What CDC is NOT

  • Not scheduled batch ETL
  • Not polling with updated_at
  • Not full table reloads
  • Not “near real-time” hacks

CDC is event-driven data movement.


⚙️ 2. How CDC Actually Works (Under the Hood)

Most CDC systems read database logs, not tables.

Examples:

  • MySQL → binlog
  • PostgreSQL → WAL
  • SQL Server → transaction log
  • Oracle → redo logs

Why logs matter

  • Zero impact on query workload
  • Exact order of changes
  • Guaranteed consistency

Log-Based CDC vs Query-Based CDC (Why Only One Scales)

Not all “CDC” is real CDC.

There are two fundamentally different approaches:

Log-based CDC

• Reads database transaction logs (binlog / WAL / redo logs)
• Zero additional query load on OLTP
• Captures INSERT, UPDATE, and DELETE accurately
• Preserves exact change order
• Production-safe at scale

Query-based CDC (Polling)

• Periodically queries tables using updated_at timestamps
• Misses deletes
• Breaks on clock skew
• Adds read load to OLTP
• Fails silently under high write volume

Many tools market query-based polling as CDC.
It isn’t.

If your pipeline relies on SELECT * WHERE updated_at > last_run,
you are doing batch ETL with shorter intervals — not CDC.

Real CDC is log-based or it doesn’t count.


🧩 CDC Internals — How Changes Flow in Real Time

This diagram shows how CDC systems capture row-level changes directly from database logs and stream them downstream without polling or full table scans.

Figure 1 - CDC Internals: database changes are captured from transaction logs (binlog/WAL), converted into change events by CDC engines like Debezium, and streamed to Kafka and downstream systems such as Lakehouses, Warehouses, and real-time applications.

This is the only scalable and production-safe way to achieve real-time ingestion from OLTP databases.

If your CDC design doesn’t look like this, you’re either polling, missing deletes, or corrupting downstream state.

🛠️ 3. CDC Tooling Landscape (What Engineers Actually Use)

Let’s cut through vendor noise.

🐘 Debezium — The Gold Standard (Open Source)

Debezium is the most battle-tested CDC engine.

Why engineers love it

  • Reads DB logs directly
  • Schema-aware
  • Handles deletes correctly
  • Emits before/after states
  • Deep Kafka integration

Typical stack

Database → Debezium → Kafka → Spark/Flink → Lakehouse

When Debezium is the right choice

  • You want control
  • You run Kafka
  • You care about correctness
  • You handle scale

Ruthless truth:
If you’re serious about CDC, Debezium is your baseline.

🔌 Kafka Connect — The CDC Plumbing Layer

Kafka Connect is not CDC itself — it’s the runtime.

Debezium usually runs on Kafka Connect.

Why it matters

  • Scales connectors
  • Handles offsets
  • Manages failures
  • Standardizes configs

Think of it as

“The operating system for CDC connectors.”

💸 Fivetran — Managed CDC for Speed (and Money)

Fivetran abstracts CDC behind a UI.

Pros

  • Zero infrastructure
  • Fast setup
  • Handles schema drift
  • Good for analytics teams

Cons

  • Expensive at scale
  • Limited customization
  • Black-box behavior
  • Latency trade-offs

Important caveat:

Fivetran CDC is optimized for analytics freshness, not event-driven systems.

If you need:
• Sub-minute latency
• Event ordering guarantees
• Real-time consumers
• Streaming joins

Fivetran is the wrong tool.

It shines for BI ingestion.
Debezium shines for systems engineering.

Choosing Fivetran for real-time workloads is how teams pay more for less control.

Use Fivetran if

  • You need speed > control
  • Team is small
  • Budget is flexible

Mentor take:
Fivetran is great early.
Debezium wins long-term.


🏗️ 4. Core CDC Architecture Patterns (That Don’t Break)

Pattern 1 — CDC → Kafka → Lakehouse (Most Common)

OLTP DB
↓
Debezium
↓
Kafka Topics
↓
Spark / Flink
↓
Bronze → Silver → Gold Tables

Why this works

  • Scales cleanly
  • Reprocessing is possible
  • Fits Medallion Architecture
  • Streaming + batch unified

This is the default modern pattern.

Pattern 2 — CDC → Warehouse Direct (Analytics-First)

DB → Fivetran → Snowflake / BigQuery

When this works

  • Simple analytics
  • No real-time apps
  • Low transformation complexity

Where it breaks

  • ML pipelines
  • Streaming joins
  • Multi-source enrichment

Pattern 3 — CDC → Event-Driven Applications

DB → Debezium → Kafka → Microservices

Used for:

  • Cache invalidation
  • Search index updates
  • Fraud triggers

⚠️ Requires idempotent consumers.


⚠️ 5. CDC Data Modeling — Where Most Teams Fail

CDC events are not rows.
They are change events.

A typical CDC event contains:

  • key
  • before
  • after
  • operation (c/u/d)
  • timestamp

🚨 Common mistakes

  • Ignoring deletes
  • Treating CDC like append-only
  • No primary keys
  • Rewriting history accidentally

Correct Silver-layer handling

  • Use upserts (MERGE)
  • Handle tombstones
  • Deduplicate by key + LSN
  • Enforce ordering

Delivery Semantics: Why Exactly-Once Is a Myth

CDC pipelines are at-least-once by nature.

Network retries happen.
Connectors restart.
Offsets replay.

Exactly-once delivery does not exist end-to-end in CDC.

Correctness is achieved at the sink:
• Idempotent upserts
• Deterministic primary keys
• Versioning via LSN / log offset
• MERGE-based reconciliation

If your downstream tables cannot safely reprocess the same event twice,
your CDC pipeline is already broken — you just haven’t noticed yet.


🧨 6. CDC Failure Modes (What Breaks in Production)

CDC pipelines don’t usually fail loudly.
They fail silently — and that’s worse.

Here are the failure modes that kill CDC systems in real life.

❌ Failure 1 — Schema Changes Break Consumers

A column gets added.
Downstream jobs crash.
Pipelines stall.

Why it happens:

  • CDC emits schema changes
  • Consumers assume fixed schemas

How to survive:

  • Enforce schema evolution at Silver layer
  • Never let raw CDC events hit BI directly
  • Use schema registry + compatibility checks

❌ Failure 2 — Missing or Mishandled Deletes

Deletes are ignored.
Downstream tables slowly rot.

Why it happens:

  • Teams treat CDC as append-only
  • Tombstones are dropped

How to survive:

  • Treat DELETE as first-class
  • Use MERGE with delete conditions
  • Validate row counts regularly

❌ Failure 3 — Out-of-Order Events

Updates arrive before inserts.
State becomes inconsistent.

Why it happens:

  • Parallel partitions
  • Network delays

How to survive:

  • Order by LSN / log offset
  • Deduplicate by primary key + version
  • Never trust arrival time

❌ Failure 4 — Backfill Nightmares

Replaying months of CDC crashes Kafka or Spark.

Why it happens:

  • No replay strategy
  • No checkpointing

How to survive:

  • Time-bounded replays
  • Bronze persistence + Time Travel
  • Replay into isolated environments
Mentor truth:If you haven’t planned for these failures,
your CDC pipeline will break — just not today.

Latency Expectations (Reality Check)

Typical latency expectations:
• Log-based CDC → seconds
• Micro-batch ETL → minutes
• Batch ETL → hours

If your “real-time” pipeline updates dashboards every 15 minutes,
you’re running batch with marketing labels.


🧪 7. Real-World CDC Use Cases

💳 Fintech — Fraud Detection

  • CDC streams transactions instantly
  • Real-time risk scoring
  • Low-latency alerts

Polling is too slow. CDC wins.

🛒 E-commerce — Inventory Sync

  • Stock updates from OLTP
  • Real-time availability
  • No overselling

📊 Analytics — Near Real-Time Dashboards

  • Orders, users, revenue
  • Updated in seconds
  • Accurate deletes & corrections

🤖 ML Feature Pipelines

  • User state changes
  • Incremental feature update
  • Training + serving consistency

CDC enables online + offline feature parity.


🧱 8. CDC + Lakehouse + Medallion (Perfect Fit)

CDC works best when combined with Delta Architecture.

CDC Events
↓
Bronze (Raw CDC)
↓
Silver (Upserts / Dedup / Clean)
↓
Gold (Business Metrics / Features)

Why this combo wins:

  • ACID handles updates
  • Time Travel enables replay
  • One source of truth
  • Streaming + batch together

This is the modern standard.


🧠 9. CDC vs Batch ETL — Choosing the Right Tool

CDC is powerful.
It is not always the right answer.

Table - CDC vs Batch ETL: choosing between real-time correctness and operational simplicity

Rule of thumb:

  • If latency matters → CDC
  • If simplicity matters → Batch
  • If both matter → CDC + Lakehouse

Choosing CDC where batch would work is how teams waste money.


🧠 10. When NOT to Use CDC

CDC is powerful — but not free.

Avoid CDC if:

  • Data changes rarely
  • Tables are tiny
  • Batch latency is acceptable
  • Source DB doesn’t support logs

Sometimes, simple batch ETL is the right answer.


🧾 11. CDC Implementation Checklist (Save This)

Before deploying CDC to production, verify:

  • Source DB supports log-based CDC
  • Primary keys exist on all captured tables
  • Deletes are handled explicitly
  • Schema evolution strategy is defined
  • CDC events land in Bronze unchanged
  • Silver uses upserts with ordering guarantees
  • Backfill & replay strategy tested
  • Monitoring on lag, throughput, failures
  • Downstream consumers are idempotent

If you can’t check all of these,
you’re not CDC-ready yet.


🧠 Conclusion

CDC is not a feature.
It’s an architectural decision.

Most teams do not need CDC.
But the teams that do cannot afford to get it wrong.

Done right, CDC delivers:

  • Low latency
  • High correctness
  • Scalable ingestion
  • Real-time intelligence

Done wrong, CDC quietly destroys systems:

  • Corrupt downstream data
  • Missing or ignored deletes
  • Out-of-order state
  • Silent inconsistencies
  • Endless debugging with no clear root cause

CDC is not a performance optimization or a freshness hack.
It is a commitment to correctness, ordering, and operational discipline.

If your data needs to be right now and right forever, CDC is mandatory — 
but only with the right patterns, tools, and modeling rigor to survive production scale.


🔥 Next in Series

Next up: “⚡Real-Time ETL Patterns: Event-Driven, Micro-Batching, Log-Based ETL ”


🔔 Follow for More

Follow TheDataForge for high-signal deep dives on Spark, Kafka, Streaming, Lakehouse, and real-world data engineering — no fluff, only engineering truth.

⚡️Let’s connect — I post daily Big Data & Spark insights at DataForgeX on X.

💬 Comment Below:Are you using CDC today — and what’s the biggest pain you’ve hit so far?


🏷️ Tags

#DataEngineering #CDC #ChangeDataCapture #Debezium #KafkaConnect #Streaming #Lakehouse #RealTimeData #Kafka #Spark