Fan-out from Postgres with Change Data Capture using Debezium and Upstash Redis
Streaming committed Postgres changes from the write-ahead log via a logical replication slot avoids the dual-write problem, where an application writes to the database and a message broker separately and can leave them inconsistent. LISTEN/NOTIFY doesn't fix this because it is only at-most-once. The guide configures Debezium Server to read Neon's WAL using pgoutput, with an initial snapshot and file-based offset tracking, and to sink change events into an Upstash Redis stream. A Node.js consumer then uses XREADGROUP consumer groups and XACK to get at-least-once fan-out that can resume after restarts.
Related posts
- Event-driven architectures using Neon and Sequin
Neon mediumAdept
Sequin offers a lighter alternative to Debezium plus Kafka for change data capture on Neon Postgres, using a logical replication slot to build a strictly ordered "Sequence" of table rows that consumers can read, rewind and replay without copying data into a separate system. Setup covers enabling logical replication in Neon, creating a pgoutput replication slot and a publication, defining a Sequence with a sort column, and creating a pull consumer group with optional SQL filters and a chosen start position. Consumers fetch batches over an HTTP receive endpoint and acknowledge them with ack tokens, and Sequin redelivers rows until they are acknowledged.
- Change Data Capture with Serverless Postgres
Neon mediumAdept
Neon has released Postgres logical replication in beta, letting Neon databases act as publishers that stream an initial snapshot plus row-level changes to external stores for change data capture and real-time analytics. Under the hood, the walsender decodes the WAL through an output plugin: pgoutput for Postgres-to-Postgres replication, and newly supported wal2json for systems such as Kafka or Materialize. Enabling it is irreversible and restarts the compute. Neon can't act as a subscriber yet, active subscribers can prevent scale-to-zero, DDL changes are not replicated, and replication lag should be monitored.
- Contributing to Debezium: Fixing Logical Replication at Scale
Zalando Engineering hardMasterZalando contributed two configuration options to Debezium's PostgreSQL connector, released in 3.4.0.Final. They restore the pgjdbc keepalive flush that prevents runaway WAL growth on low-activity databases and resolve the offset/slot LSN mismatch that made it unsafe with durable offset stores. The first option, `lsn.flush.mode` (manual, connector, connector_and_driver), lets the JDBC driver advance the replication slot past unmonitored WAL activity. The second, `offset.mismatch.strategy` (no_validation, trust_offset, trust_slot, trust_greater_lsn), controls whether Debezium trusts the stored offset or the slot on startup, both with backward-compatible mapping from the deprecated booleans. The recommended setup is connector_and_driver with trust_greater_lsn for persistent offset stores, which avoids dummy heartbeat writes and full re-syncs.
- Change Data Capture (CDC) with PostgreSQL and ClickHouse - Part 1
ClickHouse mediumAdept
Postgres-to-ClickHouse CDC can be built by streaming row changes from Postgres logical decoding (pgoutput plugin, replication slots, LSN ordering) through Debezium and Kafka, then applying them in ClickHouse with the ReplacingMergeTree engine. Updates and deletes become immutable inserts carrying a version column and a deleted flag, and background merges collapse duplicates. Correct results before a merge require FINAL at query time. Consumers must tolerate duplicate events after restarts, and deleted rows are only purged when clean_deleted_rows is set to Always, a setting with a known bug as of 23.5. The post also compares pull-based and push-based CDC and explains why a Kafka queue protects the Postgres WAL from growing when ClickHouse is unavailable.
- Stream data from Neon to external data sources via logical replication
Neon mediumAdept
Neon now supports outbound Postgres logical replication in beta, letting a Neon database publish WAL-decoded inserts, updates and deletes to warehouses, Kafka, CDC tools and other Postgres databases; inbound replication is coming later. Logical replication covers data changes only, not DDL, so schema changes must be applied to subscribers by hand. It uses publications, decoder plugins like pgoutput, and replication slots that retain WAL until subscribers consume it. In Neon, enabling it restarts all computes, only roles created via Console/CLI/API carry the REPLICATION privilege, and inactive slots are dropped after 75 minutes when other active slots exist. Setup guides cover Airbyte, Fivetran, Confluent, Materialize, Decodable, Bemi, DoubleCloud and Sequin.