Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Zalando Engineering 10 min read Case study mediumAdept

Patching the PostgreSQL JDBC Driver

Postgres logical replication slots for clients watching low-traffic tables never advance, so the server retains all WAL generated by other tables until disk fills and the node goes read-only. Zalando fixed this upstream in PgJDBC: the driver now tracks the last received and last confirmed replication LSNs, and when they match and a KeepAlive message reports a higher server LSN, it confirms that LSN, safely advancing the slot without skipping relevant events. The fix, merged for PgJDBC 42.7.0, removes the need for the common dummy-write workaround and was validated by comparing WAL size graphs before and after a patched Debezium image rollout across hundreds of event streams.

Assumes: PostgreSQL WAL basicslogical replicationchange data capture

Related posts

  • Contributing to Debezium: Fixing Logical Replication at Scale

    Zalando Engineering hardMaster

    Zalando 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.

  • Fan-out from Postgres with Change Data Capture using Debezium and Upstash Redis

    Neon mediumAdept

    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.

  • Don't add a read replica until you've read this

    incident.io mediumAdept

    incident.io moved nearly all Postgres read traffic to a read replica and had to preserve read-after-write consistency without hand-routing each query. Within a request, a Go context flag is tainted on any write or transaction so later reads go to the primary, a simple SELECT-prefix check classifies queries, and a circuit breaker falls back to the primary if the replica is unreachable. Across async boundaries, 0.1–0.5% of queue messages hit NotFound errors because workers ran faster than replication. The fix stamps each message and each mutating API actor (user or API key) with the primary's WAL LSN and checks pg_last_wal_replay_lsn() before reading from the replica. Lagging messages are nacked with exponential backoff, which doubles as backpressure, and replica lag is best monitored in bytes rather than time.

  • A Guide to Logical Replication and CDC in PostgreSQL with Airbyte

    Neon mediumAdept

    PostgreSQL logical replication builds on the write-ahead log: logical decoding turns byte-level WAL records into row-level INSERT/UPDATE/DELETE changes, and replication slots track each subscriber's LSN while retaining WAL until it is consumed. Unlike physical replication, logical replication can filter tables, rows and columns but does not replicate schema or DDL, so additive schema changes should be applied to subscribers first. Postgres-to-Postgres setup uses wal_level=logical, a replication role, publications and subscriptions, while Airbyte's CDC connector moves data into warehouses such as BigQuery or Snowflake, including from Neon. Tuning wal_compression, max_wal_size and min_wal_size helps limit WAL buildup between syncs.

  • What you get when you think of Postgres storage as a transaction journal

    Neon mediumAdept

    Neon treats Postgres storage as a transaction journal: the write-ahead log becomes the source of truth instead of a recovery aid. WAL is streamed to Safekeepers, which make it durable through Paxos-like consensus, and Pageservers turn it into page versions stored in S3, so compute nodes can stay stateless. Because any page can be rebuilt at any LSN, branching is copy-on-write via a pointer to an LSN, point-in-time restore is a specialized branch, read replicas share the Pageserver instead of copying data, and time-travel queries are possible. A walkthrough of WAL segment naming and pg_waldump output shows the underlying records.

The quest for software engineering knowledge.

Look:
Layout: