Scrivio Interview library
ScenarioAdvanced6 min read · updated 13 November 2026

Debezium captures changes from a PostgreSQL 16 primary that has a hot standby. During a planned failover the standby is promoted; the connector, pointed at the new primary, fails because its replication slot does not exist there.

The team recreates the slot and resumes, and a week later reconciliation shows a few hundred order updates missing from Kafka. Explain the gap and design CDC so database failover does not lose changes.

Logical replication slots live on the primary and, before PostgreSQL 17, are not copied to standbys, so the promoted standby had no slot. The new slot started at the WAL position current when it was created, and everything committed between the old slot's confirmed position and that moment was never streamed. We repair with incremental snapshots of the affected tables, and prevent it with failover slots on PostgreSQL 17 or later, or a failover runbook on older versions, plus slot lag monitoring and reconciliation.

Why this question is asked

Database failover is routine, and most teams test that the application reconnects. Fewer test what happens to change data capture, which depends on a piece of state, the replication slot, that a standby may not have. Interviewers ask this scenario because the resulting gap is silent: nothing errors after the slot is recreated, and the missing changes surface only when someone reconciles. In this answer, we will recap what a replication slot does, replay the failover to locate the gap, repair the missing changes, and design CDC so failover does not lose data, on PostgreSQL 17 and later and on older versions.

1A Quick Recap of Logical Replication Slots

Debezium reads PostgreSQL changes through logical decoding, which turns the write-ahead log, the WAL, into row changes. It does this through a logical replication slot, a named object on the server that remembers how far the consumer has confirmed reading, its confirmed_flush_lsn, where an LSN is a position in the WAL. The slot makes PostgreSQL keep every WAL segment the consumer has not yet confirmed, so Debezium can stop and resume without missing anything.

The catch is where the slot lives. Before PostgreSQL 17, logical slots exist only on the server where they were created. Physical streaming replication copies the data and the WAL to a hot standby, but not the logical slot's state. So after a failover the new primary has the data but no idea where Debezium had got to.

2Where the Gap Came From

The sequence of events explains the missing updates exactly.

Step throughHow the changes were lost
DebeziumOld primaryStandby / new primaryOrders app
confirmed up to LSN 0/5A00
commits updates up to LSN 0/5F00
WAL replicated, slot not copied
promoted to primary
commits more updates
connect: slot does not exist, connector fails
slot recreated at current LSN 0/6400
streams from 0/6400 on; 0/5A00 to 0/6400 never sent

8 messages in order. Play them, or step through them one at a time.

LSNs are illustrative.

Every change committed after the old slot's confirmed position and before the new slot was created was never decoded for Debezium. On the old primary those changes were still waiting in WAL for the slot; on the new primary there was no slot to hold them, and the new slot starts at the current position, so it begins after them. A few minutes of failover and troubleshooting with normal write traffic is easily a few hundred order updates. Nothing failed afterwards because, from Debezium's point of view, the new slot is perfectly consistent from its own starting point.

3Repairing the Missing Changes

We know the window: from the old slot's last confirmed position, visible in the connector's last committed offset, to the new slot's creation time. The simplest reliable repair is an incremental snapshot of the affected tables, triggered with an execute-snapshot signal, which re-emits the current state of every row as op r events while streaming continues. Where tables are large, an incremental snapshot with a filter on an updated_at column covering the failover window, if the version supports filters and the table has such a column, re-emits only the rows that could have changed.

Consumers receive these rows as upserts, which is correct if they are idempotent and keyed by primary key. One limitation to state honestly: a snapshot re-emits current state, so intermediate states during the window, and rows deleted in it, are not recovered as events. If consumers need every intermediate change, for an audit trail for example, that history must come from the database itself.

4Failover Slots on PostgreSQL 17 and Later

PostgreSQL 17 can synchronize logical slots to a physical standby, so the slot survives promotion with its position. Three things are needed: the slot is created with failover enabled, the standby synchronizes slots, and the primary waits for the standby before sending changes to logical consumers, so a slot never gets ahead of what the standby knows.

SQL
-- slot created with failover enabled (Debezium 3.x can do this with slot.failover=true; check your version)
SELECT pg_create_logical_replication_slot('debezium_orders', 'pgoutput', false, false, true);
# standby postgresql.conf
sync_replication_slots = on
hot_standby_feedback = on
primary_slot_name = 'standby1_slot' # physical slot used by this standby
# primary_conninfo must include dbname=... for slot synchronization
# primary postgresql.conf
synchronized_standby_slots = 'standby1_slot' # physical slots of standbys that must confirm first

With this in place, after promotion the new primary already has debezium_orders at a position no later than what Debezium confirmed, and the connector continues where it left off. Managed database services expose this differently or not at all, so we check what ours supports before relying on it.

5A Runbook for Older Versions and Ongoing Checks

On PostgreSQL 16, as in this scenario, the slot cannot follow the failover, so the runbook must handle it. For a planned failover: stop application writes, let Debezium drain until the slot's confirmed_flush_lsn reaches the current WAL position, promote the standby, start the connector against the new primary so it creates its slot, and only then reopen writes. Nothing is lost because nothing was written in between. For an unplanned failover we cannot drain, so the runbook schedules an incremental snapshot of the captured tables, or the affected window, every time. Some high-availability tools can also copy logical slots to standbys; check yours.

We also monitor, because a gap should be found in hours, not a week. Slot lag is pg_current_wal_lsn() minus confirmed_flush_lsn, from pg_replication_slots; the connector's MilliSecondsBehindSource metric shows capture delay; and a scheduled reconciliation compares row counts and checksums per table between the database and the latest state in the CDC topics or their downstream copy.

6Follow-up questions

Why not just create the slot on the standby in advance on PostgreSQL 16?

Logical decoding on a standby is possible from PostgreSQL 16, but a slot created there is not synchronized with the primary's slot, so it does not know what Debezium confirmed. It would either start at a different position or need manual work to line up. Proper synchronization arrived only with PostgreSQL 17 failover slots.

Could Debezium detect the gap itself?

When the slot is missing, the connector fails, which is the signal. Recreating the slot is the moment to stop and ask what was missed. Some teams make the connector refuse to start on a slot newer than its stored offset, so a human must choose between a snapshot and accepting the gap.

What does slot lag cost the database?

A slot that falls behind keeps WAL on the primary's disk until Debezium confirms it. If the connector is down for a long time, WAL can fill the disk, so we alert on slot lag and set max_slot_wal_keep_size as a safety limit, accepting that hitting it invalidates the slot.

7Conclusion

In this answer, we saw that before PostgreSQL 17 logical replication slots stay on the primary, so the promoted standby had no slot, and the recreated slot started at the current WAL position, skipping every change between the old confirmed position and its creation. We repaired with incremental snapshots of the affected tables, prevented future gaps with failover slots on PostgreSQL 17 (failover-enabled slot, sync_replication_slots on the standby, synchronized_standby_slots on the primary) or a drain-and-create runbook on older versions, and added slot lag, capture delay and reconciliation monitoring.

What to say in the interviewAbout 90 seconds aloud

Open with

Logical replication slots live on the primary, and before PostgreSQL 17 they are not copied to physical standbys. So after the failover, the new primary had no slot.

Then, if they want more

When the team recreated it, the new slot started at the current WAL position, which means every change committed between the old slot's confirmed position and the moment the new slot was created was never streamed. That is the few hundred missing updates, and nothing errored because the new slot is consistent from its own starting point.

To repair it, I would run incremental snapshots of the affected tables, or a targeted comparison and re-emit for the failover window, and consumers take those snapshot rows as upserts.

To prevent it on PostgreSQL 17 or later, I would use failover slots: create the slot with failover enabled, run the standby with sync_replication_slots on, and list the standby's physical slot in synchronized_standby_slots on the primary, with a Debezium version that can create such slots, after checking what our managed service supports.

On older versions I would put it in the runbook: stop writes, let Debezium drain, create the slot on the new primary before opening writes, and after any unplanned failover run an incremental snapshot. And I would monitor slot lag, the connector's MilliSecondsBehindSource, and schedule count and checksum reconciliation between the tables and the CDC topics.

About this answer

Last updated
13 November 2026
Versions it names
PostgreSQL 17, PostgreSQL 16
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Apache Kafka documentation
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "The team recreates the slot and resumes, and a week later reconciliation shows a few...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-streams-connect/e0f05e39e6/