data-consistencyeventsmicroservicesreliability
Transactional Outbox Pattern
Atomically persist business state and event records in one DB transaction, then publish asynchronously.
Definition
The outbox pattern writes both domain mutation and event row in the same transaction to avoid dual-write inconsistency.
When To Use
- Service boundaries that emit events after DB mutations.
- Microservices requiring reliable integration events.
- Systems where exactly-once cross-system writes are infeasible.
When Not To Use
- Purely internal systems with no event fanout requirements.
- When source datastore cannot support transactional writes to outbox.
- Teams unable to maintain outbox drain workers reliably.
Tradeoffs
- Prevents dual-write loss, but introduces outbox drain lag and worker ops.
- Improves event reliability, with added storage and cleanup overhead.
- Decouples publish latency from request path, but requires replay tooling.
Common Failure Modes
- Outbox worker outage causes event publication backlog.
- Duplicate publishes occur without idempotent consumer handling.
- Cleanup policy misconfiguration bloats primary DB.
Interview Framing
Use this structure when the interviewer asks for this pattern explicitly.
Explain transaction boundaries, outbox polling/streaming strategy, and dedup semantics on consumer side.
Related Project Deep Dives
Change Data Capture (CDC) Pipeline
Design a system that captures database changes in real-time and streams them to downstream systems with schema evolution support, exactly-once delivery, and multi-database compatibility.
Event Deduplication Platform for Idempotent Processing
Design a platform that removes duplicate events across distributed pipelines with low latency.
Related Concepts
Idempotency Keys
Guarantee repeated client retries do not create duplicate side effects.
Exactly-Once Processing (Practical)
Achieve effective exactly-once outcomes via idempotency, transactions, and dedup rather than magic guarantees.
Change Data Capture (CDC)
Stream database changes from logs to downstream systems with low-latency propagation.