Production Context & Why This Matters
Publishing a Kafka event right after committing a SQL transaction introduces a classic dual-write race: if the network blinks or pod restarts between commit and produce, state updates vanish from downstream consumers permanently.
Both transactional Outbox polling and Debezium Postgres WAL CDC solve dual-write drift cleanly—yet behave differently under heavy burst volumes, replication slot retention spikes, and schema changes.
Architectural Mechanics & Reference Implementation
Writing domain events cleanly into an append-only `outbox_events` partition allows Debezium CDC to stream zero-polling WAL records directly into Kafka with automatic partition ordering.
INSERT INTO outbox_events (id, aggregate_type, aggregate_id, event_type, payload)
VALUES (gen_random_uuid(), 'ClearingOrder', $1, 'OrderSettled', $2::jsonb);
Verified Operational Benchmarks
Pairing Debezium slot-lag alerts with daily partition truncation kept WAL growth capped while delivering sub-100ms event propagation.
- Primary Delta: 0 lost domain events across 95M daily state transitions
- Reliability Gate: <120ms end-to-end DB commit to Kafka topic publication latency
- Ownership Boundary: 100% client-owned IaC & telemetry pipelines audited by Avtar Singh
Implementation Checklist
- Monitor pg_replication_slots active status continuously to prevent disk exhaustion.
- Include monotonic sequence IDs inside outbox payloads so consumers deduplicate safely.
- Drop old outbox partitions instantaneously via DROP TABLE instead of DELETE.