Quick revision
The short answer
We move to cascading replication: the primary streams WAL to two or three intermediate standbys, and those feed the remaining replicas, whose primary_conninfo points at an intermediate. The primary then sends a handful of WAL streams instead of 18, and cross-region traffic crosses once per region instead of once per replica. Each hop adds a little lag, an intermediate's failure stops its downstream replicas until they are repointed, and failover must promote a direct standby while cascaded replicas follow the new timeline, so we run intermediates in pairs and automate repointing. We should also question whether 18 replicas are needed at all.
What to remember
In this answer, we saw that 18 direct replicas mean 18 WAL streams and 9 Gbit/s of egress from one primary. Cascading replication makes a tree: a few direct standbys feed the rest, cutting primary egress and cross-region traffic. Its costs are a little lag per hop and replicas that stall when their intermediate fails, so intermediates run in pairs with automated repointing, and failover promotes a direct standby while others follow the new timeline. Moving reporting to a CDC-fed analytics store and compressing WAL reduce the load itself.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
We move to cascading replication: the primary streams WAL to two or three intermediate standbys, and those feed the remaining replicas, whose primary_conninfo points at an intermediate. The primary then sends a handful of WAL streams instead of 18, and cross-region traffic crosses once per region instead of once per replica. Each hop adds a little lag, an intermediate's failure stops its downstream replicas until they are repointed, and failover must promote a direct standby while cascaded replicas follow the new timeline, so we run intermediates in pairs and automate repointing. We should also question whether 18 replicas are needed at all.
Background to this question
A single primary feeding many replicas is a star, and stars stop scaling when the centre runs out of network or CPU. This question is common at senior levels because the answer is a known PostgreSQL feature, but a good candidate also explains what it does to lag, failover and day-to-day operations, and challenges the requirement. In this answer, we will see why the primary is overloaded, redesign the topology with cascading, follow its effects on lag and failure, plan the failover, and then look at ways to reduce the load instead of carrying it.
1Why the Primary Is Saturated
Each streaming replica has its own WAL sender process on the primary, which reads WAL and sends it over its own connection. Every replica receives the full WAL stream. So if the primary writes WAL at 500 Mbit/s at peak, 18 replicas mean 18 copies of that stream, 9 Gbit/s of egress, and 18 processes reading and sending the same data. Replicas in the second region make it worse: each of their streams crosses the inter-region link separately, so the same bytes cross it once per remote replica.
Adding a nineteenth replica adds another 500 Mbit/s and another process on the one machine that must also run every write. That is why this topology has a ceiling.
2Cascading Replication
PostgreSQL lets a standby send WAL onward to other standbys. A replica that receives WAL from the primary can act as an upstream for others, so we build a tree. The primary feeds a pair of intermediate standbys in its own region and one or two in the other region. The remaining replicas connect to an intermediate in their region.
- Primary (region A)4 WAL senders instead of 18
- Direct standbysint-a1, int-a2 in A; int-b1, int-b2 in B; promotion candidates
- Cascaded replicas in A7 replicas, each pointing at int-a1 or int-a2
- Cascaded replicas in B7 replicas, each pointing at int-b1 or int-b2
4 layers, from the top down. Step through them one at a time.
Cross-region bytes cross the link twice instead of nine times.
Notice the numbers. The primary now sends four streams, about 2 Gbit/s at peak, and the cross-region link carries two copies instead of nine. Replication slots for the downstream replicas live on the intermediates, so WAL retention for them is the intermediates' problem, not the primary's.
3The Cost: Extra Hop Lag and Intermediate Failures
Each hop adds a small delay: the intermediate must receive the WAL before it can forward it. Inside a region this is typically a few milliseconds, but an intermediate that is itself slow, because it is also serving heavy reporting queries, delays everyone behind it. So intermediates should be dedicated or lightly used, and sized like the primary.
The bigger risk is failure. If an intermediate dies, every replica behind it stops receiving WAL and falls further behind until it is pointed elsewhere. That is why we run intermediates in pairs per region and automate repointing: when int-b1 disappears, its downstream replicas change primary_conninfo to int-b2 and reload, which PostgreSQL 13 and later accepts without a restart. A cluster manager such as Patroni can manage these tags and repoint automatically.
4Failover in a Cascading Tree
When the primary fails, we promote one of the direct standbys, preferably one in the same region with zero or the smallest lag. Promotion starts a new timeline, a new branch in the WAL history. The other direct standbys are repointed to the new primary, and the cascaded replicas below them simply keep following their intermediate, which now follows the new primary.
For replicas to cross onto the new timeline, recovery_target_timeline must be 'latest', which has been the default since PostgreSQL 12, so in current versions they follow automatically. The real work is deciding which replicas may be promoted. Cascaded reporting replicas should not be candidates: they are further behind by one hop, and they are often configured to tolerate long query conflicts, so their replay can be minutes behind.
5Do We Really Need 18 Replicas?
Before carrying more load, we should ask what the replicas are for. Much reporting traffic runs long scans that suit a column store far better than PostgreSQL. A change data capture pipeline, Debezium reading the logical replication stream into Kafka, can feed an analytics store such as ClickHouse or a warehouse, which removes most reporting replicas entirely. Hot API reads may be better served from a cache or from purpose-built read models. If those changes take 18 replicas down to six, the problem shrinks without new topology.
We can also send less. wal_compression compresses full-page images in WAL, which are a large share of WAL volume after each checkpoint, and PostgreSQL 15 and later support lz4 and zstd for it. Longer checkpoint intervals produce fewer full-page images. And every replica, intermediate or leaf, must be able to replay at the primary's peak write rate; a replica that replays slower than the primary writes falls further behind every busy hour and never recovers.
6Follow-up questions
Which replicas would you allow to be promoted, and why?
Only the direct standbys, ideally the pair in the primary's region, sized like the primary and kept free of long-running queries so their replay stays close to zero lag. If we use synchronous replication, the synchronous standby is the first choice, because it is guaranteed to have every acknowledged commit. Cascaded reporting replicas are excluded: they are a hop behind, may be paused by query conflicts, and are often smaller machines. In Patroni this is expressed with a nofailover tag on those replicas.
Would logical replication solve the egress problem?
Not by itself. Logical replication also sends changes from the primary per subscriber, and decoding costs CPU on the primary. It helps when subscribers need only a subset of tables, but for full replicas physical cascading is cheaper.
Can a cascaded replica be synchronous?
No. Synchronous replication in PostgreSQL applies only to standbys connected directly to the primary, which is another reason the direct standbys are the promotion candidates.
7Conclusion
In this answer, we saw that 18 direct replicas mean 18 WAL streams and 9 Gbit/s of egress from one primary. Cascading replication makes a tree: a few direct standbys feed the rest, cutting primary egress and cross-region traffic. Its costs are a little lag per hop and replicas that stall when their intermediate fails, so intermediates run in pairs with automated repointing, and failover promotes a direct standby while others follow the new timeline. Moving reporting to a CDC-fed analytics store and compressing WAL reduce the load itself.
Open with
The primary is doing the work of a star: every replica has its own WAL sender, so 18 replicas mean 18 copies of the WAL stream, which is the 9 gigabits per second, and nine of those copies cross the region link.
Then, if they want more
I would move to cascading replication. The primary feeds two intermediate standbys in its own region and two in the other, and the remaining replicas set primary_conninfo to an intermediate in their region, with their replication slots on the intermediate. The primary goes from 18 streams to four, and the cross-region link carries two copies instead of nine.
The effects: each hop adds a few milliseconds of lag, and if an intermediate fails, everything behind it stops receiving WAL. So intermediates run in pairs, are sized like the primary and are kept free of heavy queries, and repointing to the partner is automated, for example with Patroni.
For failover, only the direct standbys are candidates, preferably in the primary's region or the synchronous one; cascaded replicas just follow the new timeline because recovery_target_timeline is latest by default. I would also question the 18 replicas. Much of that is reporting, which a CDC pipeline into an analytics store handles better, and caching can absorb API reads.
And I would turn on wal_compression and make sure every replica can replay at the primary's peak rate, or it falls behind every busy hour.
About this answer
- Last updated
- 13 November 2026
- Versions it names
- PostgreSQL 12, PostgreSQL 13, 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 official documentation for the version you use. 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 "Redesign the replication topology so you can keep adding replicas, and explain the...": https://scrivio-interview-library.netlify.app/architecture/partitioning-and-replication/1512196df4/