# Change data capture

> Read the database's change log and publish each change as an event, so search, warehouse, and cache stay in step without the app writing twice.

Change data capture turns the database's own log into a stream of events that other systems follow.

## Use it when

- A second copy of the data must follow the database: a search index, a warehouse, a cache, or another service.
- The app currently writes to two stores, and they drift apart after a crash.
- You cannot change every writer to emit events.

## How it works

Every database writes changes to a log before it applies them. A connector such as Debezium reads that log and publishes each insert, update, and delete to a stream. Consumers read the stream and apply the changes to their copies. The app writes once, to the database, so there is nothing to disagree.

Key the stream by the row's primary key. Order holds only inside a partition, so an unkeyed stream can apply an old write after the newer one.

## What it costs

Copies lag the database by however far behind the consumer is, and a consumer further behind than the stream's retention loses changes. Changes are row-level, so consumers see the schema, and a migration can break them. You run a connector and a stream. A consumer that writes back to the source can start a loop.

## In Quorum



Link the [Database](https://wiki.playquorum.dev/components/database.md) into a [CDC Connector](https://wiki.playquorum.dev/components/cdc.md), the connector into an [Event Stream](https://wiki.playquorum.dev/components/log.md), and the stream into a [Worker](https://wiki.playquorum.dev/components/worker.md). The connector has no options of its own. It copies the writes the Database processes and never slows them. The stream's key and partitions set order and read speed.

The Search Engine in the picture sits beside the Database, and the other extra Nodes only serve the remaining Series B request kinds. Research [Change data capture](https://wiki.playquorum.dev/research/cdc.md), which needs [Event streaming](https://wiki.playquorum.dev/research/event-streaming.md) and [Data warehousing](https://wiki.playquorum.dev/research/data-warehouse.md). The same effect without a stream is the [transactional outbox](https://wiki.playquorum.dev/patterns/transactional-outbox.md). The glossary defines [CDC](https://wiki.playquorum.dev/glossary/cdc-change-data-capture.md).

Source: https://wiki.playquorum.dev/patterns/change-data-capture
