Change Data Capture (CDC) is a powerful pattern for tracking and streaming database changes in real-time.
StackGres integrates Debezium Engine to provide CDC capabilities through the SGStream custom resource.
With SGStream, you can capture changes from PostgreSQL databases and stream them to various targets, enabling use cases such as:
SGStream performs two distinct operations to capture and stream database changes:
Snapshotting: Captures the current content of the data source at a specific point in time, streaming it as if the records were changes. This provides a complete view of the database state as a stream of events.
Streaming: Captures changes happening in real-time using PostgreSQL logical replication, continuously streaming INSERT, UPDATE, and DELETE events to the configured target.
The CDC process uses PostgreSQL’s logical decoding with the pgoutput plugin, creating a replication slot and publication to track changes.
SGStream can capture changes from:
Captured changes can be streamed to:
SGStream extends Debezium’s functionality with a custom signaling channel that allows you to send signals via Kubernetes annotations on the SGStream resource:
metadata:
annotations:
debezium-signal.stackgres.io/tombstone: "{}"
Available custom signals include:
SGStream is currently an alpha feature (API version v1alpha1). While fully functional, the API may change in future releases. It is recommended to test thoroughly in non-production environments before deploying to production.
Have a look at the CDC Streaming Guide to learn how to create and configure streams, and the SGStream CRD Reference for the complete specification.