Postgres WAL Replay Outpaces Logical Replication Under Write Bursts

Oct 20, 2026 By Sara Park

A write burst exposes the difference between physical WAL replay and logical replication more sharply than any benchmark. Physical replay ships raw blocks and scales with sequential write bandwidth. Logical decoding parses every change, and that per-row tax compounds under load. This piece explains why the gap exists, walks through a real failure at a payments startup, and lays out an operational playbook for keeping logical subscribers from becoming a liability.

WAL Replay Wins on Burst Throughput

Physical replication ships raw blocks. The primary writes WAL records, and a standby replays those records without interpreting them as SQL. A block change is a block change. The standby does not need to know which table it belongs to, which index it touches, or what the planner would do with the statement that produced it.

Logical replication works differently. It reads the same WAL stream but runs each record through an output plugin, which reconstructs a row-level change. That means parsing the record, looking up catalog metadata, and emitting a message the subscriber can apply. The overhead is small per transaction and large per million.

Bursts expose the gap. A batch job that inserts a few million rows in a short window produces a WAL volume that physical replay consumes at disk speed. Logical decoding consumes it at parse speed, which is slower and less predictable. Replay scales with sequential write bandwidth. Decode scales with CPU and catalog contention.

The shape of the WAL matters too. Physical replay is indifferent to transaction boundaries in the sense that it applies page changes as they arrive, so a single enormous transaction does not create a cliff at commit time. Logical decoding holds the whole transaction in memory until commit, then emits it in one burst of messages. The larger the transaction, the more pronounced the spike at the moment it lands. Batch jobs that wrap millions of rows in one transaction hit the decoder and the subscriber at exactly the same instant, which is the worst possible timing for a system that wants steady, predictable apply rates.

Logical Replication Decodes Every Change

Output plugins parse WAL records into a logical format. The built-in pgoutput plugin, used by native logical replication, reads each record and produces insert, update, or delete messages. For every change, it consults the system catalogs to resolve relation OIDs, column types, and replica identity settings.

Catalog lookups add per-transaction cost. The plugin caches some metadata, but a burst that touches many tables or creates temporary relations forces repeated lookups. Long transactions amplify memory pressure because the decoder must hold change data until commit. A single transaction that writes a million rows can pin a large chunk of memory in the walsender process.

Subscribers apply changes single-threaded by default. Postgres has added parallel apply for logical replication in recent versions, but the default remains one apply worker per subscription. The subscriber becomes the bottleneck even when the publisher keeps up. The decode tax on the publisher and the apply bottleneck on the subscriber compound under sustained write pressure.

There is a subtler cost that shows up only under bursts: the decoder has to maintain a consistent snapshot view while it works. When the workload churns through schema changes, or when a batch job touches a wide set of partitions, the catalog cache thrashes. Each miss is a catalog read, and catalog reads compete with the same buffer pool the rest of the system is using. At steady state this is noise. At burst rates it turns into a measurable drag on the whole primary, not just the walsender.

The 2 AM Incident at a Payments Startup

A payments startup ran a logical replication slot to feed an analytics cluster. The slot was created for a selective set of tables and had worked fine for months at steady-state traffic. Then a nightly batch settlement job changed shape. A new pricing rule caused the job to write several times more rows than before, in a tighter window.

The logical subscriber fell hours behind. The walsender kept decoding, but the apply worker on the subscriber could not keep pace. WAL segments accumulated on the primary because the slot retained them until the subscriber confirmed receipt. Postgres does not discard WAL that an active slot still needs, so the primary's disk filled.

Failover to a physical standby restored service. The standby had been replaying the same WAL stream at block level and was nearly current. Promoting it took seconds. The logical slot on the old primary was abandoned, and the analytics feed was rebuilt from a fresh snapshot the next day. The incident cost a few hours of analytics freshness and one tense morning.

What made the incident instructive was the sequence. The disk did not fill because the primary was slow. The primary was healthy and writing at full speed. The disk filled because a consumer that had nothing to do with serving traffic could not confirm receipt fast enough, and the retention rule held the primary hostage to that consumer's pace. The failure mode lived entirely in the coupling between a fast producer and a slow, optional consumer.

Why Replay Avoids the Decode Tax

There is no SQL parsing on the standby. The standby reads WAL records and applies page-level changes to shared buffers. It does not run the planner, evaluate expressions, or check constraints in the same way. Constraint checks happened on the primary. The standby trusts the WAL.

Block-level copy skips the planner entirely. A physical standby does not need to know why a page changed. It applies the change and moves on. That is why replay latency stays predictable under sustained load, even when the workload includes large transactions and many small ones interleaved.

Recent Postgres versions added parallel redo, which lets the standby apply WAL records using multiple processes. The feature is not a cure-all, and it depends on the workload, but it widens the margin between replay and decode under burst conditions. The standby's apply rate tracks disk throughput more closely than CPU headroom.

Predictability is the real prize. A logical subscriber's lag is a function of row shape, table count, catalog churn, and subscriber apply capacity, which means it can swing by an order of magnitude between two workloads that generate identical WAL volume. A physical standby's lag is a function of disk write bandwidth, which is boring and therefore easy to reason about. When you are deciding what to put behind a promotion button, boring wins.

When Logical Replication Still Earns Its Place

Cross-version upgrades need logical slots. A physical standby must run the same major version as the primary. Logical replication can bridge a major-version upgrade with less downtime, because the subscriber can run the new version while the publisher runs the old one. That flexibility has real value during a migration window.

Selective table replication for analytics is another case. Logical replication can publish a subset of tables, which keeps the analytics cluster from carrying data it does not need. Physical replication ships everything. For a primary with large tables that analytics never touches, the selectivity is worth the decode cost.

Zero-downtime migrations across clusters often depend on logical replication. The same mechanism that makes it slower under bursts makes it more flexible for cutovers. Accept the decode cost when schema flexibility or version bridging matters more than raw throughput. The trade-off is real, and it is not always the wrong choice. This site has argued before that failure reasoning matters more than framework fluency, and the same logic applies here: know which failure mode you are optimizing for.

There is a middle path worth naming. You can run logical replication for the tables that genuinely need row-level filtering and keep everything else on physical replication, so the decode tax applies only to the slice of traffic that benefits from it. Splitting the workload this way keeps the burst-sensitive bulk path on block replay while the analytics feed carries only the narrow tables it was built for. It costs you a second slot to manage and a second set of lag metrics to watch, which is a fair price for removing the coupling that caused the incident above.

Operational Playbook for Write Bursts

Set max_slot_wal_keep_size to cap disk risk. The setting limits how much WAL a slot can retain. When the limit is exceeded, Postgres invalidates the slot rather than filling the disk. An invalidated slot breaks the subscriber, but a broken subscriber is easier to rebuild than a full primary.

Monitor pg_stat_replication lag continuously. The view reports write, flush, and replay lag for each standby and logical subscriber. Alert on sustained lag growth rather than a fixed threshold, because a burst can push lag up briefly without indicating a real problem. Sustained growth is the signal that matters.

Keep a physical standby as the failover target. A logical subscriber is not a failover target. It applies changes through a different path, and it may be behind in ways that make promotion unsafe. The physical standby should be the promotion candidate, with the logical subscriber reserved for its specific purpose.

Test logical subscribers against peak write rates. A subscriber that keeps up at steady state can fall far behind during a batch job. Run the batch job against a staging replica and measure apply lag. If the subscriber cannot keep up, either add parallel apply workers or move the feed to a different mechanism.

Alert on WAL generation rate spikes. A sudden increase in WAL generation often precedes a replication problem. The rate spike is visible before lag grows, which gives operators time to react. Pair the alert with a runbook that names the slot, the subscriber, and the failover target. For teams thinking about how to staff this kind of operational reasoning, a related piece on SRE hiring and routing depth covers the broader skill question.

Size the retention budget against real disk headroom, not against a round number. If the primary has a few hundred gigabytes free, a slot cap in the low tens of gigabytes is a reasonable guardrail, and the exact figure should come from measuring how long a rebuild takes versus how long the disk can absorb a stalled consumer. The cap is a fuse, and a fuse you have never sized against your own rebuild time is a fuse you are trusting blindly.

Recommend Posts
Tech

CDN Work Pays Before the Routing Knowledge Does

By Deepa Iyer/Oct 20, 2026

CDN and edge roles pay a premium early, but the routing judgment that compounds is learned in on-call shifts, peering changes, and postmortems, not in control planes.
Tech

Chip Vendors Ship Firmware Updates Their Maintainers Cannot Support

By Sara Park/Oct 20, 2026

Chip vendors ship firmware as opaque binaries and the support burden lands on volunteer maintainers. What that work costs, and what maintainers can demand from procurement.
Tech

License Audits Catch Copyleft Drift Before Release Builds

By Yusuke Tanaka/Oct 20, 2026

How teams catch copyleft drift before release builds freeze license obligations into shipped binaries, and how to run license audits as a merge-time gate.
Tech

SRE Hiring Shifts Toward Anycast Routing Depth as CDNs Collapse the Stack

By Lucas Mendes/Oct 20, 2026

CDNs absorbed the easy edge work. SRE hiring now rewards engineers who can debug BGP withdrawals and anycast routing at packet level, and the trade-offs that come with it.
Tech

ClickHouse and ClickHouse Cloud Diverge on Who Pays for Merges

By Yusuke Tanaka/Oct 20, 2026

ClickHouse ships under Apache 2.0 while ClickHouse Cloud bills by usage. The same merge work gets paid for twice, and only one side sends the invoice.
Tech

Mobile Hiring Rewards Store Review Latency Over Cross-Platform Fluency

By Sara Park/Oct 20, 2026

Why store review latency, not cross-platform fluency, is the rarer mobile hiring signal, and how engineers build review-resilient skills across iOS and Android.
Tech

Inside Database Teams, Debugging Skill Outweighs Query Modeling

By Yusuke Tanaka/Oct 20, 2026

Database teams hire for schema design, but daily work is lock waits, replication drift, and bad plans. A technical look at the trade-offs and what to practice.
Tech

Quorum Reads Mask the Cost of Cross-Shard Write Coordination

By Yusuke Tanaka/Oct 20, 2026

Quorum reads return fast while cross-shard writes still pay coordination cost. Here is how to measure prepare-to-commit spans, quorum gaps, and settlement lag.
Tech

Fine-Tuning Budgets Outrun Inference Savings After Launch

By Sara Park/Oct 20, 2026

Fine-tuning often cuts inference costs by 20 to 40 percent, not 90. Here is where the savings leak away after launch and how to budget for retraining, labeling, and eval.
Tech

Patch Deploys Stall Where Security Sign-Off Budgets Run Out

By Sara Park/Oct 20, 2026

Security sign-off is unpaid senior-engineer time, and patch queues stall when that budget runs dry. A look at where the hours go, who pays, and what a workable review looks like.
Tech

Passkeys Reduce Phishing Risk but Shift Recovery Burden to Help Desks

By Lucas Mendes/Oct 20, 2026

Passkeys defeat relay phishing kits but push the weak point to account recovery. A technical look at WebAuthn's guarantees, help desk ticket load, and how to harden resets.
Tech

Fork Maintenance Costs Grow Where Upstream Licenses Change

By Sara Park/Oct 20, 2026

Upstream license changes shift compliance work downstream. How forks absorb the cost, where budgets break, and the practical moves that keep maintenance tractable.
Tech

Distributed Systems Hiring Rewards Failure Reasoning Over Framework Fluency

By Sara Park/Oct 20, 2026

Backend hiring loops still score framework recall while distributed systems work runs on failure reasoning. Here is how to redesign the loop and what it costs engineers.
Tech

Postgres WAL Replay Outpaces Logical Replication Under Write Bursts

By Sara Park/Oct 20, 2026

Why physical WAL replay outpaces logical replication during write bursts, and how to keep a logical subscriber from filling the primary's disk.
Tech

Cross-Platform Frameworks Add Abstraction Layers iOS and Android Do Not Need

By Sara Park/Oct 20, 2026

Cross-platform frameworks promise code reuse but add bridge latency, startup overhead, and accessibility gaps. A technical look at when native development still wins.
Tech

Rendering Latency Tracks Paint Complexity More Than Framework Choice

By Deepa Iyer/Oct 20, 2026

Swapping frameworks rarely fixes slow pages. Rendering latency follows paint complexity—shadows, filters, and layers—not the library you chose. Here's how to profile it.
Tech

Database Hiring Pays for Incident History Over Schema Design

By Yusuke Tanaka/Oct 20, 2026

Database hiring now rewards engineers who can narrate real outages and failover drills over textbook schema design. Here is how the pay, contracts, and ownership follow the pager.
Tech

Bun and Node Split on Runtime Speed or Built-In Tooling

By Lucas Mendes/Oct 20, 2026

Bun and Node.js diverge on speed, tooling, and governance. A working engineer's comparison of what each runtime genuinely gets right and wrong in 2026.
Tech

Audit Maintainer Trust in Security Patches Before Merging

By Deepa Iyer/Oct 20, 2026

Signed commits prove authorship, not safety. A maintainer-side look at patch trust, reviewer bandwidth, and the practical checks worth running before a merge.
Tech

App Store Fees Outlive the Apps That Generated Them

By Deepa Iyer/Oct 20, 2026

Store commission clauses, account ownership, and audit rights often outlast the app itself. A breakdown of what mobile developers actually sign up for.