# CDC in the Wild

Page title: CDC Use Cases & Applications

> Real-world CDC use cases: real-time data warehousing, cache invalidation, auditing, microservices integration, and full-text search indexing.

Canonical page: <https://sandgraal.github.io/letstalkcdc/use-cases/>

> **Known errata for this page (1)**
>
> - **Corrected: a delete event does not always carry the full row** (updated 2026-10-11)
>
>   The pages said a delete event holds the row as it was (the before image), or that the log holds the before image. That is only true under the right source settings. On PostgreSQL, with the default replica identity on a table that has a primary key, the before image carries only the key columns; `REPLICA IDENTITY FULL` adds the rest of the row, and other replica identity settings differ, so check yours. On MySQL, `binlog_row_image` controls how much of the row is written (FULL, MINIMAL, NOBLOB); the full row needs `binlog_row_image=FULL`. The places that described the before image now state both conditions: the delete page, the event envelope quiz, the use cases page and the security page. A sink that needs the old column values of a deleted row must not assume them.
>
> [See all corrections and caveats](https://sandgraal.github.io/letstalkcdc/errata/)

Explore the real-world patterns powered by change streams—from real-time analytics to cache invalidation and microservice choreography.

Analytics & BI Microservices Integration

Beyond the theory, Change Data Capture enables a diverse set of powerful, real-time applications. Understanding these patterns is key to unlocking the strategic value of your data. Each use case demonstrates a shift from slow, periodic batch processing to a continuous, event-driven paradigm.

Use Case 1: Analytics & Business Intelligence

## From Batch ETL to Real-Time ELT

**The Problem:** Business decisions based on stale, 24-hour-old data are a competitive liability. Traditional nightly ETL jobs place a heavy, recurring load on production databases and deliver insights that are already out of date.

**The CDC Solution:** Log-based CDC continuously streams every row-level change from operational (OLTP) databases. These events flow through a streaming platform like Kafka and are loaded into an analytical data warehouse (Snowflake, BigQuery, Redshift) in near real-time. The warehouse uses `MERGE` or `UPSERT` operations to efficiently apply these granular changes, keeping analytical tables perfectly synchronized with the source.

Producer (OLTP/CDC)

Streaming Platform

Warehouse

CDC tails DB changes

Publish to Kafka topic(s)

Connector reads

—

—

`MERGE/UPSERT` into models

**The Business Impact:**

- **Accelerated Decision-Making:** BI dashboards and reports reflect business operations up to the minute, not up to the day.
- **Reduced Database Load:** Eliminates the need for resource-intensive, full-table scans during nightly batch windows, improving source system performance.
- **Fresher Data for ML:** Machine learning models can be trained and served with more current data, improving prediction accuracy.

Use Case 2: System Architecture

## Asynchronous Microservice Integration

**The Problem:** Services in a microservices architecture need to share data, but direct, synchronous API calls create tight coupling. If one service is down, it can cause a cascade of failures in the services that depend on it.

**The CDC Solution:** CDC enables the **Event-Carried State Transfer** pattern via the Transactional [Outbox](https://sandgraal.github.io/letstalkcdc/glossary/#outbox). When a service makes a change (an `orders` service creates an order), it writes the business data and an event record to an "outbox" table in the same atomic transaction. The CDC agent streams only the committed outbox events to a Kafka topic. Downstream services (shipping`, `billing`) simply subscribe to this topic to receive state changes without ever calling the `orders` service directly.

Delivery is at-least-once and ordered only per message key, so the subscribers dedupe and guard on a version: [Transactional Outbox and Relay](https://sandgraal.github.io/letstalkcdc/transactional-outbox/).

Producer (Service A)

Kafka

Consumers (B/C)

Write business row + outbox (same txn)

CDC publishes outbox events

Subscribe to topic

—

—

Idempotent upserts; no sync coupling

**The Business Impact:**

- **Increased Resilience:** Services are decoupled. The `shipping` service can continue processing events even if the `orders` service is temporarily unavailable.
- **Improved Scalability:** Services can be scaled independently. You can add more `billing` consumers without affecting the `orders` service.
- **Enhanced Service Autonomy:** Each team can evolve its service and database schema without breaking downstream consumers, as long as the event contract is maintained.

Use Case 5: Discovery & Search

## Near-Real-Time Full-Text Search Indexing

**The Problem:** Rebuilding a search index from scratch (hourly/daily) is wasteful and makes “search lag” a constant complaint.

**The CDC Solution:** Stream row-level changes into a lightweight transformer that denormalizes documents and ships them to Elasticsearch/OpenSearch/Solr. *Upsert* on create/update; *delete* on the delete event. Use a deterministic `doc_id` to make replays idempotent. To also refuse a stale replay, use the source log position as an external version ([how, and the delete window](https://sandgraal.github.io/letstalkcdc/non-kafka-cdc/#search)).

Source/CDC

Doc Builder / Enricher

Search Index

Row-level change events

Join/denormalize into documents

Upsert by `doc_id`

Delete events

Mark as delete

Delete from index

**The Business Impact:**

- **Fresh search:** New/edited products, profiles, and content appear within seconds.
- **Lower cost:** No more full re-index jobs; only incremental updates.
- **Better relevance:** Can re-score or enrich on the fly during the doc build step.

Use Case 6: Machine Learning

## Real-Time Features & Online/Offline Consistency

**The Problem:** Batch-built features drift from production state; models suffer from “training/serving skew.”

**The CDC Solution:** Feed CDC events into a feature pipeline: write *offline* parquet/Delta/Iceberg tables for training and simultaneously upsert *online* features (Redis/DynamoDB/Spanner). Use the same `event_id` and schema contracts so replays are safe and the two stores stay consistent.

Stream Processor

Offline (Lakehouse)

Online Feature Store

Ingest CDC events

Write Parquet/Delta/Iceberg

Idempotent upserts by `entity_id`

Derive features

Training datasets

Serve features to models

Which row wins in each lakehouse table format is covered in [Which Row Wins in Your Target](https://sandgraal.github.io/letstalkcdc/which-row-wins/).

**The Business Impact:**

- **Fresher predictions:** models see current features, not yesterday’s.
- **Consistency:** identical events power training and serving paths.
- **Faster iteration:** add features with schema-checked rollouts.

Guardrails

## When *Not* to Use CDC (or use with caution)

- **Ultra-high fan-out updates** that require global ordering across entities (CDC provides per-key order only).
- **Compute-heavy transformations** that are cheaper in micro-batches; consider a streaming job with windowing instead of per-row fan-out.
- **SaaS sources with unreliable webhooks** without replay—buffer behind an Inbox/Outbox queue first.
- **Hard deletes needed but source lacks tombstones** (polling CDC) → add soft-delete markers or archival tables.

Use Case 3: Security & Compliance

## Immutable Auditing and Data Lineage

**The Problem:** For regulatory compliance (SOX, GDPR, HIPAA) and security investigations, organizations need a complete, tamper-proof history of all changes made to critical data. Building this logic into every application is complex and error-prone.

**The CDC Solution:** The stream of events produced by log-based CDC *is* a perfect, immutable audit log. Each event captures the "before" and "after" state of the data (how much of the row "before" holds depends on the source: on PostgreSQL, with the default replica identity on a table that has a primary key, a delete or update carries only the key columns in the before image; `REPLICA IDENTITY FULL` adds the rest of the row, and other replica identity settings differ; on MySQL the full row needs `binlog_row_image=FULL`), a precise timestamp, the type of operation (`INSERT`, `UPDATE`, `DELETE`), and metadata about the transaction. This entire stream can be durably archived to low-cost object storage (like Amazon S3), creating a verifiable and replayable history of the data's entire lifecycle.

**The catch:** an immutable history and a request to erase a person pull in opposite directions. Decide how long each archived copy lives before you build it; see [Deletes That Stay Deleted](https://sandgraal.github.io/letstalkcdc/deletes-stay-deleted/).

**The Business Impact:**

- **Simplified Compliance:** Easily prove data lineage and access patterns to auditors, satisfying strict regulatory requirements.
- **Enhanced Security:** Detect and investigate unauthorized or anomalous data changes by analyzing the raw event stream.
- **Faster Debugging:** "Replay" the event stream to understand how data reached a corrupted state, drastically reducing time-to-resolution for production incidents.

Use Case 4: Application Performance

## Reliable Cache Invalidation

**The Problem:** Keeping an external cache (like Redis or Memcached) synchronized with the database is famously difficult. A common failure mode is serving stale data because the application logic failed to invalidate the cache after a database write.

**The CDC Solution:** This pattern is elegant in its simplicity. A lightweight consumer service listens to the CDC stream from the primary database. When it receives an `UPDATE` or `DELETE` event for a specific record, it issues a corresponding `SET` or `DEL` command to the cache for that record's key. The responsibility for cache consistency is moved out of the critical application path into a simple, reliable, asynchronous process.

**The Business Impact:**

- **Improved User Experience:** Guarantees that users are never shown stale data, improving trust and application quality.
- **Simplified Application Code:** Removes complex and error-prone cache management logic from the application layer.
- **Better Performance:** Allows applications to confidently and aggressively cache data, reducing load on the primary database and improving response times.

See It In Action

## Real-World Implementation Case Study

Want to see these use cases come together in a real-world scenario? Check out our [**comprehensive case study**](https://sandgraal.github.io/letstalkcdc/case-study/) following an e-commerce company's journey from batch ETL to real-time CDC. You'll see how they:

- Evaluated Debezium, Fivetran, and AWS DMS
- Built a production Kafka + Snowflake pipeline
- Handled schema changes, replication slot bloat, and other challenges
- Reduced data latency from 24 hours to 3 minutes
- Enabled 18 new real-time use cases in 6 months

[Read the Full Case Study →](https://sandgraal.github.io/letstalkcdc/case-study/)

### CDC Use Cases Knowledge Check

Test your understanding of real-world CDC applications and patterns.

Q1

#### How does CDC enable real-time analytics and business intelligence?

A By replacing all batch processes with manual queries

B By streaming fresh data continuously to data warehouses, enabling near real-time dashboards and reports

C CDC is not suitable for analytics workloads

D By storing data only in memory

Q2

#### What is cache invalidation via CDC?

A Deleting all cached data every minute

B Using CDC events to selectively invalidate or update cache entries when source data changes

C Cache invalidation is not possible with CDC

D Disabling caching entirely

Q3

#### How does CDC support microservice data synchronization?

A By forcing all microservices to share one database

B By streaming change events from one service's database to other services, maintaining eventual consistency

C Microservices should never share data

D CDC only works with monolithic architectures

Q4

#### What role does CDC play in event-driven architectures?

A CDC is not related to event-driven systems

B CDC transforms database changes into events, enabling reactive systems that respond to state changes

C Event-driven architectures only use application-level events

D CDC prevents event-driven patterns

Q5

#### How can CDC help with disaster recovery and audit trails?

A CDC has no role in disaster recovery

B CDC events provide a complete change history, enabling point-in-time recovery and full audit logs

C Disaster recovery requires only backups, not CDC

D Audit trails should never use CDC

**0/5** correct

---

CDC: The Missing Manual by Christopher Ennis (Let's Talk CDC), licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Attribution is required.
