If latency budgets leave no room for synchronous retries, replace SQL polling on high-throughput outbox tables with PostgreSQL WAL Logical Replication (Debezium `pgoutput`), or pair time-partitioned outbox tables with `DROP`/`TRUNCATE` rotation to eliminate MVCC bloat.
TL;DR30-second simplified summary▾
Core Mechanics: Writing payment ledger rows and outbox_events in one ACID transaction eliminates dual-write bugs. However, when 8 relay workers poll outbox_events every 50 ms using `SELECT ...
Visual & Structural Flow: Depicts FOR UPDATE SKIP LOCKED Polling vs. Debezium pgoutput (Ledger Tx (15k/s) -> outbox_events Heap -> 8x SQL Pollers -> WAL + Debezium); Append-Only Partitioned Outbox + Sequential WAL CDC (Payment Service (20k/s) -> Postgres WAL (pgoutput) -> Partitioned outbox_events -> Debezium -> Kafka (<50ms)).
Trade-Offs & Production: Aggressive autovacuum_vacuum_cost_limit cannot reclaim dead tuples pinned by a 15-minute read-replica or analytics xmin snapshot. Sustain 20,000 outbox inserts/sec with < 50 ms p99 Kafka relay lag: Append-Only outbox_events (Zero UPDATE/DELETE): Insert events in the same ACID transaction as the ledger, and never update or delete rows.
Failure Modes & Application: The CDC-backed Transactional Outbox is the gold standard for atomic DB-to-Kafka publishing: Payment Ledgers & Order State Machines: Guarantees every committed balance change emits an ordered domain event.
outbox table inside the exact same ACID database transaction as the business state change, then relaying them asynchronously to Kafka/RabbitMQ.Why SQL polling breaks PostgreSQL MVCC at 15,000+ outbox writes/sec.
Why this matters: The mechanism: understand how Why SQL polling breaks PostgreSQL MVCC at 15,000+ outbox writes/sec works from first principles.
Writing payment ledger rows and outbox_events in one ACID transaction eliminates dual-write bugs.
However, when 8 relay workers poll outbox_events every 50 ms using `SELECT ...
Dead-tuple explosion, autovacuum starvation, and bloated B-trees.
Why this matters: The problem: see what breaks without Dead-tuple explosion, autovacuum starvation, and bloated B-trees under real concurrency or scale.
PostgreSQL MVCC never overwrites rows in place—every UPDATE or DELETE creates dead tuples:
- 2x Dead-Tuple Churn:
15k/sinserts +15k/supdates/deletes generate30ktuple versions/sec that cannot be vacuumed while any analyticsxminsnapshot is open (15 min). - Index & Lock Thrashing: The
status = 'PENDING'B-tree bloats to gigabytes of dead entries, blowing past40,000IOPS.
FOR UPDATE SKIP LOCKED Polling vs. Debezium pgoutput
Replacing SQL polling with WAL-based CDC (Debezium pgoutput) eliminates UPDATE/DELETE dead tuples and polling IOPS.
- Problem
- How to implement Scaling the Transactional Outbox with CDC without hitting unbounded tail latency, state divergence, or operational fragility.
- Naive Solution
- Use a single unpartitioned path with unbounded retries and synchronous global coordination.
- Why It Fails
- Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
- Alternatives
- Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
- Engineering Decision
- If latency budgets leave no room for synchronous retries, replace SQL polling on high-throughput outbox tables with PostgreSQL WAL Logical Replication (Debezium
pgoutput), or pair time-partitioned outbox tables withDROP/TRUNCATErotation to eliminate MVCC bloat. - Trade-Offs
- Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
When Scaling the Transactional Outbox with CDC experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?
Why tuning autovacuum or adding partial indexes is not enough.
Why this matters: The problem: see what breaks without Why tuning autovacuum or adding partial indexes is not enough under real concurrency or scale.
Think of Why tuning autovacuum or adding partial indexes is not enough as the intuition layer for Scaling the Transactional Outbox with CDC: The problem: see what breaks without Why tuning autovacuum or adding partial indexes is not enough under real concurrency or scale.
Aggressive autovacuum_vacuum_cost_limit cannot reclaim dead tuples pinned by a 15-minute read-replica or analytics xmin snapshot. Meanwhile, polling every 50 ms still wastes thousands of random heap/index IOPS competing directly with payment transactions.
Why tuning autovacuum or adding partial indexes is not enough
Enterprise solution: Append-Only Partitioned Outbox + Debezium pgoutput.
Why this matters: Operational control: configure bounds, failure handling, and safe production defaults.
Sustain 20,000 outbox inserts/sec with < 50 ms p99 Kafka relay lag:
- Append-Only
outbox_events(ZeroUPDATE/DELETE): Insert events in the same ACID transaction as the ledger, and never update or delete rows. - Debezium
pgoutputWAL Streaming: Read sequential Write-Ahead Log records directly from the replication slot (zero polling queries, zero lock contention), usingOutboxEventRouterSMT to partition Kafka byaggregate_idfor per-aggregate ordering. - Hourly Range Partitions +
DROP TABLE: Partitionoutbox_eventsbycreated_at(hourly/daily) and drop expired partitions inO(1)metadata time—bypassingVACUUMcompletely.
Append-Only Partitioned Outbox + Sequential WAL CDC
1.Zero Dead Tuples: No UPDATE/DELETE means zero MVCC bloat even with 15-min analytics xmin snapshots.
2.Sequential WAL Read: Debezium tails the WAL sequentially instead of random B-tree index scans.
3.DROP Partition Rotation: Hourly range partitions are dropped instantly without triggering VACUUM.
Append-only partitioned outbox tables paired with Debezium WAL CDC eliminate MVCC bloat and sustain 20k+ events/sec.
Where CDC-backed outboxes power event-driven platforms.
Why this matters: Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.
The CDC-backed Transactional Outbox is the gold standard for atomic DB-to-Kafka publishing:
- Payment Ledgers & Order State Machines: Guarantees every committed balance change emits an ordered domain event.
- Saga Orchestrators: Atomically persists saga state transitions and outgoing command events.
- Microservice Event Buses: Decouples OLTP throughput from downstream consumer lag.
Practice: Make the trade-off yourself.
Why does an append-only partitioned `outbox_events` table paired with Debezium `pgoutput` outperform `SELECT ... FOR UPDATE SKIP LOCKED` polling at 15,000+ writes/sec?