Database CDC (Change Data Capture)
Capture database changes in real time by reading directly from transaction logs. CDC provides the lowest latency and most reliable method for streaming database events.
Database CDC captures changes directly from transaction logs, enabling real-time streaming with minimal impact on database performance.
What is Change Data Capture?
Change Data Capture (CDC) reads changes directly from a database's internal transaction log before they're committed. This provides:
- Real-time capture: Changes are captured as they happen, not through polling or triggers. Latency is under 50ms.
- Zero performance impact: Reads from transaction logs, not query-based. No additional load on your production database.
- Complete and ordered: Captures every change in exact transaction order. No missed updates or race conditions.
- Schema changes included: Captures DDL (CREATE, ALTER, DROP) alongside DML (INSERT, UPDATE, DELETE).
Supported Databases
| Database | CDC Method | Min Version | Setup Complexity |
|---|---|---|---|
| PostgreSQL | Logical Replication (WAL) | 10+ | Low |
| MySQL | Binary Log (binlog) | 5.7+ | Low |
| MongoDB | Change Streams | 4.0+ | Low |
| Snowflake | Streams | - | Medium |
| DynamoDB | DynamoDB Streams | - | Low |
| Databricks | Delta Change Data Feed | - | Medium |
| CockroachDB | Changefeeds | 21.1+ | Low |
PostgreSQL WAL Replication
PostgreSQL CDC uses logical replication to stream changes from the Write-Ahead Log. This is SchemaBounce's most mature and recommended CDC method.
1. Enable Logical Replication
-- In postgresql.conf or via ALTER SYSTEM
ALTER SYSTEM SET wal_level = 'logical';
ALTER SYSTEM SET max_replication_slots = 10;
ALTER SYSTEM SET max_wal_senders = 10;
-- Restart PostgreSQL for changes to take effect
2. Create Publication
-- Create publication for specific tables
CREATE PUBLICATION schemabounce_pub FOR TABLE users, orders, products;
-- Or for all tables
CREATE PUBLICATION schemabounce_pub FOR ALL TABLES;
3. Configure in SchemaBounce
source:
type: postgres_cdc
connection:
host: your-db.example.com
port: 5432
database: production
user: schemabounce_repl
publication: schemabounce_pub
slot_name: schemabounce_slot
For detailed PostgreSQL setup, see the Bridge documentation and Replication Management guide.
MySQL Binary Log
MySQL CDC reads from the binary log (binlog) to capture all database changes.
1. Enable Binary Logging
# In my.cnf
[mysqld]
server-id = 1
log_bin = mysql-bin
binlog_format = ROW
binlog_row_image = FULL
2. Create Replication User
CREATE USER 'schemabounce'@'%' IDENTIFIED BY 'secure_password';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'schemabounce'@'%';
GRANT SELECT ON *.* TO 'schemabounce'@'%';
FLUSH PRIVILEGES;
See the MySQL provider reference for connection options.
MongoDB Change Streams
MongoDB Change Streams provide real-time notifications for document changes. Requires a replica set or sharded cluster.
// SchemaBounce automatically subscribes to change streams
// Configuration:
{
"source": {
"type": "mongodb_change_stream",
"connection": "mongodb+srv://cluster.example.com",
"database": "production",
"collections": ["users", "orders"]
}
}
See the MongoDB provider reference for cluster requirements.
When to Use Database CDC
Best for:
- Real-time data replication
- Event-driven architectures
- Cache invalidation
- Audit logging
- Search index synchronization
- Analytics pipelines
Consider alternatives when:
- Database doesn't support native CDC
- Network restrictions prevent direct access
- You need exactly-once delivery semantics
- A managed database doesn't expose logs
For databases without native CDC support, consider the Outbox Pattern (linked below) as a reliable alternative. For a broader comparison of approaches, see CDC vs ETL.
Related
- Outbox Pattern: the fallback when native CDC isn't available.
- SaaS Connectors: sync data from 100+ SaaS platforms with OAuth.
- Connector Reference: the full catalog of supported SaaS connectors.
- Inbound Webhooks: receive push events in real time.
- Direct Pull: query-based syncing for managed databases without log access.
- Pipeline overview and how the pipeline works for the bigger picture.
- Quick start to set up your first pipeline.
- Try a hands-on walkthrough in the PostgreSQL CDC tutorial.