Skip to main content

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.

Sub-50ms latency with Cloudflare Edge

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

DatabaseCDC MethodMin VersionSetup Complexity
PostgreSQLLogical Replication (WAL)10+Low
MySQLBinary Log (binlog)5.7+Low
MongoDBChange Streams4.0+Low
SnowflakeStreams-Medium
DynamoDBDynamoDB Streams-Low
DatabricksDelta Change Data Feed-Medium
CockroachDBChangefeeds21.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
note

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
note

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.