Scrivio Interview library
ScenarioAdvanced7 min read · updated 12 November 2026

A team proposes using PostgreSQL logical replication to feed analytics, search and a new microservice from the monolith database. What are the operational risks, and how would you set it up safely?

The biggest risk is the replication slot: it makes the primary keep WAL until the consumer confirms it, so one stalled consumer can fill the monolith's disk and take it down. Logical replication also does not copy DDL, sequences or large objects, and on older versions its slots were lost on failover (PostgreSQL 17 can synchronise them to standbys). We set it up safely with max_slot_wal_keep_size, slot lag alerts, a schema change process, failover slots, and, when several consumers are involved, one Debezium slot feeding Kafka instead of one slot per consumer.

Why this question is asked

Feeding other systems from a monolith's database is a common first step in breaking it apart, and PostgreSQL's built-in logical replication looks like the cheapest way to do it. It usually works on day one. The trouble comes weeks later, when a consumer is paused for maintenance and the primary's disk starts to fill, or when a developer adds a column and the subscriber stops. Interviewers ask this to see whether we know how the mechanism keeps its promises, and what it costs the source database. In this answer, we will recap how logical replication works, look at the slot risk in detail, cover what it does not replicate, see what changes with failover slots in PostgreSQL 17, and finish with a safer architecture for many consumers.

1A Quick Recap of Logical Replication

Physical replication copies WAL byte for byte to a standby, so the standby is an identical copy of the whole cluster. Logical replication instead decodes the WAL into row changes, insert this row, update that one, and sends them per table. That lets a subscriber be a different PostgreSQL version, hold only some tables, or have extra indexes of its own.

On the source we create a publication, a named set of tables. On the target we create a subscription that connects to the source. Behind the scenes the subscription uses a replication slot on the source: a bookmark that records how far this consumer has confirmed. Slots are what make logical replication reliable, because a consumer that disconnects can resume exactly where it stopped. Logical decoding requires wal_level = logical on the source.

SQL
-- on the monolith (publisher)
CREATE PUBLICATION orders_pub FOR TABLE orders, order_lines;
-- on the new service's database (subscriber)
CREATE SUBSCRIPTION orders_sub
CONNECTION 'host=monolith dbname=shop user=repl'
PUBLICATION orders_pub; -- creates slot orders_sub on the publisher

2Risk 1: A Stalled Consumer Fills the Primary's Disk

The slot's promise works in one direction only: the source will not delete any WAL the consumer has not yet confirmed. If the consumer is healthy, it confirms every few seconds and old WAL is recycled. If it is stopped, broken or very slow, WAL piles up on the primary. A monolith writing 50 GB of WAL a day will fill a 500 GB disk in about ten days with a dead consumer, and much faster during a bulk load. When the disk is full, the primary stops, and the whole company's main database is down because of an analytics feed.

So we monitor every slot's retained WAL and alert long before it matters, and we put a ceiling on it.

SQL
SELECT slot_name, active, wal_status,
pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS retained
FROM pg_replication_slots;
-- orders_sub | t | reserved | 120 MB
-- search_sub | f | extended | 61 GB <- consumer stopped two days ago
ALTER SYSTEM SET max_slot_wal_keep_size = '100GB';
SELECT pg_reload_conf();

With max_slot_wal_keep_size set, PostgreSQL invalidates a slot that would need more WAL than the limit; its wal_status becomes lost. That protects the primary, and the price is that the consumer must be resynchronised from scratch. That is the right trade: rebuilding a search index is an inconvenience, while a full disk on the monolith is an outage. Abandoned slots, created for a test and forgotten, are the classic cause of this incident, so every slot should have an owner.

3Risk 2: What Logical Replication Does Not Copy

Logical replication copies row changes and TRUNCATE. It does not copy DDL, schema changes such as ALTER TABLE. If the monolith team adds a non-null column, the subscriber does not get it, and as soon as an incoming row no longer fits the subscriber's table, the apply worker errors and replication stops while WAL accumulates on the source. So schema changes need a process: add the column on subscribers first, then on the publisher; remove columns in the opposite order. A column list on the publication, available since PostgreSQL 15, also helps by only sending the columns consumers need.

Sequence values are not replicated either, so a subscriber promoted to take writes would hand out ids that already exist; newer releases are improving sequence support, so check your version. Large objects, stored with lo_create, are not replicated at all. Finally, every replicated table needs a replica identity, normally its primary key, so updates and deletes can find the row on the subscriber; a table without one fails on UPDATE.

4Risk 3: Failover of the Primary

Slots are local to the server they were created on. Before PostgreSQL 17, when the primary failed over to a physical standby, the new primary had no logical slots. Consumers could not resume, and changes made around the failover could be missed unless they were rebuilt.

PostgreSQL 17 added failover slots. A logical slot created with the failover option is synchronised to physical standbys when the standby has sync_replication_slots enabled, and synchronized_standby_slots on the primary makes logical consumers wait until those standbys have the WAL, so the slot on the standby is never behind. After promotion, the consumer reconnects to the new primary and continues. Patroni can also manage permanent slots across failover. Either way, we test it in a failover drill before relying on it.

5A Safer Architecture for Many Consumers

With analytics, search and a new microservice, we would have three slots on the monolith, three things that can stall, and three sets of load from decoding the same WAL. A better pattern is change data capture, CDC, done once. Debezium, an open-source CDC connector running in Kafka Connect, reads a single slot and publishes each table's changes to Kafka topics. Every consumer reads Kafka at its own pace, Kafka holds days of history, and a slow consumer no longer affects the primary at all.

Step throughOne slot, many consumers
  1. PostgreSQL monolithone logical slot, max_slot_wal_keep_size, lag alert
  2. Debezium in Kafka Connectdecodes changes once, publishes per table
  3. Kafka topicsretain days of changes, replayable
  4. Analytics, search, new serviceeach consumes at its own pace

4 layers, from the top down. Step through them one at a time.

A stalled consumer now only falls behind in Kafka; the primary is unaffected.

Debezium also emits schema change information and handles snapshots for new consumers, though DDL coordination is still needed. For the new microservice specifically, we might later switch to the outbox pattern, where the monolith writes events to an outbox table on purpose, so consumers depend on a contract rather than on the monolith's internal tables.

6Follow-up questions

How do you alert on slot lag?

Export retained WAL per slot, pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn), and the active flag from pg_replication_slots into the metrics system, for example through postgres_exporter. Alert when retained WAL exceeds a fraction of max_slot_wal_keep_size, say 30 percent, or when a slot has been inactive for more than an hour. Also watch the free disk on the WAL volume directly.

Does logical decoding add load to the primary?

Yes. Each slot's walsender decodes the WAL itself, which costs CPU, and large transactions may be spilled to disk before they are sent (streaming of in-progress transactions, available since PostgreSQL 14, helps). One Debezium slot instead of several subscriptions keeps that cost to one decoder.

What does the consumer see for a long transaction?

By default, changes are sent when the transaction commits, so a transaction that updates ten million rows arrives at the subscriber as one large burst. That can cause lag spikes and memory pressure on consumers, so batch jobs on the monolith should commit in chunks.

7Conclusion

In this answer, we saw that logical replication decodes WAL into row changes and uses a slot that holds WAL until the consumer confirms, which means a stalled consumer can fill the primary's disk unless we cap it with max_slot_wal_keep_size and alert on lag. We saw that DDL, sequences and large objects are not replicated, that slots were lost on failover until PostgreSQL 17's failover slots, and that one Debezium slot feeding Kafka is safer than many direct subscriptions.

What to say in the interviewAbout 90 seconds aloud

Open with

My main concern is the replication slot. A slot makes the primary keep WAL until the consumer confirms it, so if the search consumer is stopped for two days, the monolith keeps all that WAL and can fill its disk, which takes down the main database for everyone.

Then, if they want more

So I would set max_slot_wal_keep_size, which invalidates a slot rather than letting it fill the disk, and alert on retained WAL and inactive slots, with an owner for every slot. Second, logical replication does not copy DDL, so a column added on the monolith can break subscribers.

We need a schema change process: add on subscribers first, drop on the publisher first, and use column lists. It also does not copy sequences or large objects, and tables need a primary key or replica identity. Third, failover: before PostgreSQL 17, logical slots did not survive promotion of a standby.

On 17 I would create them as failover slots with sync_replication_slots on the standbys, and test it in a drill. Finally, with three consumers I would not create three slots. I would run Debezium on one slot into Kafka, so each consumer reads at its own pace and a slow one never affects the primary.

For the new microservice I would push towards an outbox table so it depends on a contract, not the monolith's internals.

About this answer

Last updated
12 November 2026
Versions it names
PostgreSQL 17, PostgreSQL 14, PostgreSQL 15
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.
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 "A team proposes using PostgreSQL logical replication to feed analytics, search and a new...": https://scrivio-interview-library.netlify.app/databases/replication-and-ha/e60f26d720/