Inferensys

Glossary

Change Data Capture (CDC) Lag

Change Data Capture (CDC) lag is the delay between a change being committed to a source database and that change being propagated and available in a downstream target system or data pipeline.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
DATA FRESHNESS AND LATENCY MONITORING

What is Change Data Capture (CDC) Lag?

Change Data Capture (CDC) lag is a critical latency metric in data engineering that measures the timeliness of data replication.

Change Data Capture (CDC) lag is the time delay between a data modification being committed to a source database and that change being fully propagated and available for consumption in a downstream target system. This latency metric is fundamental to data freshness and is measured from the source's commit timestamp to the target's apply timestamp. High CDC lag indicates a replication pipeline is falling behind, risking stale data for analytics, machine learning features, or operational reporting.

Monitoring CDC lag involves tracking the difference between the log sequence number (LSN) or timestamp of the last committed source change and the last processed event in the target. Causes of lag include source database load, network throughput limits, target system backpressure, and inefficient serialization/deserialization. Effective management requires setting Service Level Objectives (SLOs) for acceptable lag and implementing observability to trigger alerts when thresholds are breached, ensuring downstream data consumers operate on sufficiently current information.

ANATOMY OF A DELAY

Key Components of CDC Lag

CDC lag is not a monolithic delay but a composite of several distinct, measurable phases. Understanding each component is essential for diagnosing bottlenecks and setting precise Service Level Objectives (SLOs).

01

Source Commit Latency

This is the initial delay, measured from the moment a database transaction is initiated until it is durably committed to the source system's write-ahead log (WAL). Factors include:

  • Database lock contention from concurrent writes.
  • I/O performance of the underlying storage.
  • Transaction size and complexity.
  • Replication lag within the source database cluster (e.g., between a primary and its replicas). This component is internal to the source database and is often the first place to investigate for high baseline lag.
02

Log Read & Decode Delay

The delay incurred by the CDC tool as it reads the committed transaction from the source log (e.g., PostgreSQL WAL, MySQL binlog, MongoDB oplog) and decodes it into a structured change event. Key factors:

  • Polling interval configuration of the CDC connector.
  • Log decoding complexity, especially for heavily nested or encrypted data.
  • Source database load impacting log read I/O.
  • Network latency between the CDC agent and the database server (if reading remotely). Optimizing this stage often involves tuning connector configurations and ensuring the CDC process has low-latency access to the log.
03

Change Event Processing & Transformation

The time spent applying business logic to the raw change event before it is emitted. This can include:

  • Schema transformation (renaming columns, changing data types).
  • Filtering out irrelevant tables or operations.
  • Masking or encrypting sensitive data (PII).
  • Debezium's SMTs (Single Message Transformations) or equivalent logic. Complex transformations add computational overhead. This stage is a common source of data skew, where a few complex events slow down the entire pipeline.
04

Broker/Queue Propagation Time

The network and queuing delay as the change event travels from the CDC producer to the message broker (e.g., Apache Kafka, Amazon Kinesis) and through to the consumer. This encompasses:

  • Network Round-Trip Time (RTT) between hosts.
  • Broker acknowledgment wait time (acks=all for high durability).
  • Internal broker queueing and partition leader election events.
  • Consumer group rebalancing, which can temporarily pause consumption. Monitoring consumer lag on the target topic is the primary method for measuring this component.
05

Target Write & Commit Latency

The final delay, where the change event is applied to the destination system (e.g., data warehouse, search index, cache). This is often the most variable component and depends entirely on the target:

  • Data warehouse load performance (e.g., Snowflake, BigQuery, Redshift).
  • Indexing overhead in systems like Elasticsearch.
  • Constraint checking and trigger execution in a target RDBMS.
  • Rate limiting or throttling imposed by the target API. High latency here can cause backpressure, propagating delays back through the entire pipeline.
06

Monitoring & Observability Points

To measure each component, instrument these key metrics:

  • Source Database: Transaction commit timestamps, WAL lag metrics.
  • CDC Connector: source_lag_metrics (Debezium), binlog_position age.
  • Message Broker: Consumer lag (e.g., Kafka's consumer_lag), end-to-end latency.
  • Target System: Ingestion latency, batch commit times.
  • Business-Level SLOs: Define acceptable lag thresholds (e.g., "95% of changes available within 60 seconds") using tools like Grafana dashboards and Prometheus alerts. Correlate lag spikes with pipeline health events.
OPERATIONAL METRICS

How is CDC Lag Measured and Monitored?

CDC lag is a critical operational metric for data freshness, quantified by comparing timestamps between source and target systems to identify propagation delays.

CDC lag is measured by calculating the difference between two timestamps: the commit time of a change in the source database and the processing or availability time in the target system. This delta, expressed in milliseconds or seconds, is the definitive lag metric. Monitoring systems track this value continuously, often exposing it as a gauge or time-series metric like cdc_replication_lag_seconds. Key related metrics include consumer lag in log-based systems and end-to-end latency, which encompasses the full pipeline.

Effective monitoring involves setting Service Level Objectives (SLOs) for acceptable lag thresholds and implementing alerts for breaches. Observability platforms visualize lag trends and correlate them with system health indicators like backpressure or data skew. For robust pipelines, checkpointing progress and handling late data via watermarks are essential complementary practices to ensure accurate lag measurement and system recovery.

DIAGNOSTIC GUIDE

Common Causes of High CDC Lag and Mitigations

A comparison of root causes for delays in Change Data Capture pipelines and corresponding technical mitigations to reduce latency.

Cause / SymptomPrimary ImpactTypical Lag IncreaseRecommended Mitigation

Source Database Write Load Spikes

Overwhelms CDC connector's read capacity

Seconds to minutes

Increase connector parallelism; use database read replicas for CDC

Network Latency or Instability

Increases time to transfer change logs

100ms - 5+ seconds

Co-locate source and target in same cloud region; use dedicated network links

Downstream Target Throttling/Backpressure

CDC process blocks on writes to destination

Minutes to hours

Implement adaptive batching; scale target system throughput

Inefficient Connector Configuration (Batch Size, Poll Intervals)

Suboptimal resource utilization and idle time

Seconds to minutes

Tune batch size and poll intervals based on monitoring; enable heartbeat messages

Schema Evolution or Large Transactions

Connector stalls parsing complex DDL or large TX logs

Minutes to hours

Pre-validate schema changes; monitor for oversized transactions

Checkpointing Failures or Frequency

Connector reprocesses data from an old position on restart

Variable, can be large

Ensure durable, frequent checkpointing to a reliable store

Data Skew in Partitioned Sources

A single hot partition becomes the processing bottleneck

Minutes, tail latency increases

Re-partition source table or configure parallel snapshotting

Unhandled Poison Pill Messages or Deserialization Errors

Connector thread hangs or crashes, stopping progress

Indefinite until restart

Implement dead letter queues (DLQs) and robust error handling with alerting

CHANGE DATA CAPTURE (CDC) LAG

Frequently Asked Questions

Change Data Capture (CDC) lag is a critical latency metric in data engineering, measuring the delay between a source database transaction and its availability downstream. This FAQ addresses common technical questions about its measurement, impact, and mitigation.

Change Data Capture (CDC) lag is the time delay between when a data change (insert, update, delete) is committed to a source database and when that change is fully propagated and available for consumption in a downstream target system, such as a data warehouse, cache, or search index.

This lag is a composite metric influenced by multiple factors:

  • Capture Latency: The time for the CDC mechanism (e.g., reading database transaction logs) to detect the change.
  • Processing & Transformation Latency: The time spent parsing, filtering, or transforming the change event.
  • Transmission Latency: The network transfer time to the target system.
  • Loading Latency: The time for the target system to apply the change, which may involve conflict resolution or index updates.

Monitoring CDC lag is essential for ensuring data freshness and meeting Service Level Objectives (SLOs) for real-time analytics and operational systems.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.