Skip to main content
← PROBLEMS / ARCHITECTURE
An end-to-end domain learning journey

Building Reliable Change Data
Capture (CDC) Pipelines.

Losing or misaligning Debezium Kafka Connect offsets alongside PostgreSQL replication slot drops or LSN resets creates silent, unrecoverable data sync gaps in downstream search and analytics.
Start the journey5 stages
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When a single bottleneck threatens end-to-end availability, pair compacted, RF=3 `connect-offsets` topics and Debezium heartbeat tables with PostgreSQL `max_slot_wal_keep_size` monitoring and DBLog-style incremental snapshots to heal gaps without downtime.

TL;DR30-second simplified summary
▾

Core Mechanics: A Debezium pgoutput connector streaming 8,500 writes/sec from a 1.8 TB (420M-row) PostgreSQL orders table to Kafka, Elasticsearch, and Snowflake relies on two aligned pointers: PostgreSQL's confirmed_flush_lsn and Kafka Connect's connect-offsets topic.

Visual & Structural Flow: Depicts Slot Drop + Uncompacted Offsets Create Silent Sync Gaps (Postgres WAL -> Debezium -> connect-offsets -> ES / Snowflake); pgoutput WAL + Heartbeat + DBLog Incremental Snapshot (Postgres Primary (1.8 TB) -> Debezium Connect Worker -> connect-offsets (RF=3) -> Kafka -> ES & Snowflake).

Trade-Offs & Production: Leaving connect-offsets at replication.factor=1 or cleanup.policy=delete loses LSN checkpoints on a single broker failure. Debezium CDC is the backbone for decoupling operational OLTP databases from derived systems: Search Index Synchronization: Streams OLTP mutations into Elasticsearch/OpenSearch without dual-write drift.

Failure Modes & Application: Debezium CDC is the backbone for decoupling operational OLTP databases from derived systems: Search Index Synchronization: Streams OLTP mutations into Elasticsearch/OpenSearch without dual-write drift.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Change Data Capture (CDC)
Change Data Capture (CDC) streams row-level inserts, updates, and deletes directly from a database's transaction log (WAL/binlog/oplog) into event buses like Kafka—eliminating dual-write race conditions and heavy polling queries.
Full walkthrough · 5 stages
01
STAGE 01 · WHY IT MATTERSL4 · FUNDAMENTALS

Why CDC replication slot drops cause silent search & warehouse drift.

Why this matters: The mechanism: understand how Why CDC replication slot drops cause silent search & warehouse drift works from first principles.

Think of Why CDC replication slot drops cause silent search & warehouse drift as the intuition layer for Building Reliable Change Data Capture (CDC) Pipelines: The mechanism: understand how Why CDC replication slot drops cause silent search & warehouse drift works from first principles.

A Debezium pgoutput connector streaming 8,500 writes/sec from a 1.8 TB (420M-row) PostgreSQL orders table to Kafka, Elasticsearch, and Snowflake relies on two aligned pointers: PostgreSQL's confirmed_flush_lsn and Kafka Connect's connect-offsets topic. If either is lost, downstream sinks silently diverge from the source of truth.

02
STAGE 02 · IMPACTL5 · APPLIED DESIGN

WAL disk exhaustion and unrecoverable LSN gaps.

Why this matters: The problem: see what breaks without WAL disk exhaustion and unrecoverable LSN gaps under real concurrency or scale.

Two operational failures regularly break production CDC:

  1. Idle-Table WAL Bloat: When monitored tables are idle, confirmed_flush_lsn stalls while unrelated tables write WAL—filling the 100 GB NVMe cap.
  2. Accidental DROP_REPLICATION_SLOT + Lost Offsets: Dropping the slot to free disk and restarting with missing connect-offsets skips hours of committed orders, while a blocking INITIAL snapshot on 1.8 TB takes 14 hours.
CDC LSN & Offset Drift

Slot Drop + Uncompacted Offsets Create Silent Sync Gaps

Postgres WALDebeziumconnect-offsetsES / Snowflake1. Idle table stalls flush_lsn ->100GB WAL2. Operator runs DROP_REPLICATION_SLOT3. Broker loss drops RF=1 offsets4. Restarts at latest LSN ->silent gap!5. Fix: heartbeat + RF=3 + DBLogsignal

Heartbeat queries advance LSNs continuously, RF=3 compacted offsets survive broker loss, and DBLog signals heal gaps without locking.

Engineering Decision Framework
Problem
How to implement Building Reliable Change Data Capture (CDC) Pipelines without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
When a single bottleneck threatens end-to-end availability, pair compacted, RF=3 connect-offsets topics and Debezium heartbeat tables with PostgreSQL max_slot_wal_keep_size monitoring and DBLog-style incremental snapshots to heal gaps without downtime.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Building Reliable Change Data Capture (CDC) Pipelines experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

03
STAGE 03 · NAIVE SOLUTIONL5 · APPLIED DESIGN

Why RF=1 offsets and blocking INITIAL snapshots fail at 1.8 TB.

Why this matters: The problem: see what breaks without Why RF=1 offsets and blocking INITIAL snapshots fail at 1.8 TB under real concurrency or scale.

Think of Why RF=1 offsets and blocking INITIAL snapshots fail at 1.8 TB as the intuition layer for Building Reliable Change Data Capture (CDC) Pipelines: The problem: see what breaks without Why RF=1 offsets and blocking INITIAL snapshots fail at 1.8 TB under real concurrency or scale.

Leaving connect-offsets at replication.factor=1 or cleanup.policy=delete loses LSN checkpoints on a single broker failure. Meanwhile, running snapshot.mode=initial on a 420M-row table holds long-lived transactions, bloats vacuum, and takes 14 hours.

Lifecycle & Failure Recovery

Why RF=1 offsets and blocking INITIAL snapshots fail at 1.8 TB

poll batchsink successpoison / timeoutAppended to LogLeased to ConsumerOffset CommittedMoved to DLQ
04
STAGE 04 · ENTERPRISE SOLUTIONL6 · SCALE & TRADE-OFFS

Enterprise solution: Heartbeats, Compacted RF=3 Offsets, and DBLog Signals.

Why this matters: Operational control: configure bounds, failure handling, and safe production defaults.

Build a self-healing, zero-downtime Debezium pipeline:

  • Durable Offset Storage: Set connect-offsets to cleanup.policy=compact, replication.factor=3, and min.insync.replicas=2.
  • Heartbeat Table (heartbeat.interval.ms=10000): Upsert public.debezium_heartbeat every 10s so confirmed_flush_lsn advances even when orders is idle, keeping WAL usage well below max_slot_wal_keep_size = 100 GB.
  • DBLog Incremental Snapshots: Configure signal.data.collection=public.debezium_signal to re-stream specific PK ranges in chunked, non-blocking windows interleaved with live WAL streaming.
  • 5-Minute Drift Reconciliation: Compare row-count / MAX(updated_at) watermarks between Postgres and ES/Snowflake every 5 minutes.
Resilient CDC Pipeline

pgoutput WAL + Heartbeat + DBLog Incremental Snapshot

Postgres Primary (1.8 TB)pgoutput + max_slot_wal_keep_sizeDebezium Connect Worker10s heartbeat + DBLog signalsconnect-offsets (RF=3)Compacted, min.isr=2Kafka -> ES &…Idempotent upsert + 5m…

1.Heartbeat LSN Advance: Upserts heartbeat row every 10s so replication slot LSN never stalls on idle tables.

2.DBLog Signal Backfill: Surgically re-streams missed PK ranges in chunks without locking or 14h downtime.

3.5-Min Drift Probe: Compares source vs. sink watermarks continuously to catch gaps within 5 minutes.

Heartbeats prevent WAL exhaustion, compacted RF=3 offsets protect LSN state, and incremental snapshots heal gaps online.

{
  "name": "pg-orders-cdc-v2",
  "config": {
    "connector.class": "io.debezium.connector.postgresql.PostgresConnector",
    "plugin.name": "pgoutput",
    "slot.name": "debezium_orders_v2",
    "snapshot.mode": "when_needed",
    "heartbeat.interval.ms": "10000",
    "heartbeat.action.query": "INSERT INTO public.debezium_heartbeat (id, ts) VALUES (1, NOW()) ON CONFLICT (id) DO UPDATE SET ts = EXCLUDED.ts",
    "signal.data.collection": "public.debezium_signal"
  }
}
05
STAGE 05 · SYSTEM DESIGN APPLICATIONSL7 · STAFF / PRINCIPAL

Where reliable CDC pipelines power distributed architectures.

Why this matters: Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.

Debezium CDC is the backbone for decoupling operational OLTP databases from derived systems:

  • Search Index Synchronization: Streams OLTP mutations into Elasticsearch/OpenSearch without dual-write drift.
  • Transactional Outbox Pattern: Tails an outbox table from the WAL for guaranteed event publishing.
  • Real-Time Lakehouse Ingestion: Feeds Apache Iceberg/Snowflake medallion tables.
Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

Why does configuring `heartbeat.action.query` in Debezium prevent PostgreSQL WAL disk exhaustion on a quiet table?

Recommended Learning Flow