# Change data capture

> Copying every insert, update and delete from a database to other systems as it happens.

- Level: Advanced
- Topics: Data
- URL: https://tidbit.legios.com.ar/change-data-capture/
- In Spanish: [Change data capture](https://tidbit.legios.com.ar/es/change-data-capture/)

**Change data capture**, or **CDC**, is a technique for detecting each change made to a database and sending it elsewhere, almost in real time. Instead of copying a whole table every night, CDC sends only what changed: a new order inserted, a price updated, a customer deleted, each as a small event.

The most common method reads the database's own transaction log. Databases like PostgreSQL and MySQL already write every change to a log before applying it, for crash recovery and replication. A CDC tool such as **Debezium** or AWS Database Migration Service tails that log and turns each entry into an event, usually published to a stream. Older approaches use triggers or poll for rows with a recent `updated_at`, but they add load and can miss deletes.

CDC is how a data warehouse stays minutes behind the production database instead of a day, how a search index or a cache stays in sync with the source of truth, and how a database can be migrated with almost no downtime. The tricky parts are order, since events must be applied in the sequence they happened, schema changes in the source, and the first full copy that has to be taken before streaming changes on top of it.

## An analogy

Like following a shared document's edit history instead of downloading the whole document every hour: you only receive the lines that changed, in order, as soon as they change.

## Keep in mind

- Sends each insert, update and delete as an event, not whole tables.
- Usually reads the database's transaction log, so it adds little load.
- Keeps warehouses, caches and search indexes close to real time.
- Order, schema changes and the initial full copy need care.

## Go deeper

- [What is change data capture? (AWS)](https://aws.amazon.com/what-is/change-data-capture/)
- [Debezium (open-source CDC platform)](https://debezium.io/)
- [Change data capture on Wikipedia](https://en.wikipedia.org/wiki/Change_data_capture)

## Related terms

- [Database](https://tidbit.legios.com.ar/database/): An organized store of data that programs can search and update safely.
- [PostgreSQL](https://tidbit.legios.com.ar/postgresql/): A free, open-source relational database behind a great many apps.
- [MySQL](https://tidbit.legios.com.ar/mysql/): The open-source relational database that powered the early web and still runs much of it.
- [Data warehouse](https://tidbit.legios.com.ar/data-warehouse/): A database built for analysis: years of history, from many sources, in one place.
- [Database index](https://tidbit.legios.com.ar/database-index/): A sorted shortcut that lets a database find rows without reading the whole table.
- [Caching](https://tidbit.legios.com.ar/caching/): Keeping a copy of an answer close by so you do not have to work it out again.
- [Database schema](https://tidbit.legios.com.ar/database-schema/): The blueprint of a database: which tables exist, their columns and how they connect.
