r/java • u/czetsuya • 24d ago
The Transactional Outbox Solves Dual Writes. It Doesn't Solve Duplicate Processing
I've worked on event-driven systems where the transactional outbox pattern was introduced to solve a fairly common problem: keeping database changes and event publishing consistent.
The idea is straightforward:
- Update the business entity.
- Insert an outbox record in the same database transaction.
- Have a separate publisher deliver the event to Kafka.
This removes the classic dual-write problem where the database transaction commits but event publishing fails.
However, something I've noticed is that implementing an outbox is sometimes treated as if it makes the entire event-processing pipeline reliable.
It doesn't.
The outbox guarantees neither exactly-once delivery nor exactly-once business processing.
Consider this scenario:
- The publisher reads an outbox record.
- It successfully publishes the event to Kafka.
- The process crashes before marking the outbox record as published.
- After recovery, the same event gets published again.
Now the consumer receives a duplicate.
Even if the publisher behaves perfectly, consumers can still process a message more than once when failures occur between business processing and offset acknowledgment.
This is why I think the outbox pattern is only one part of the solution.
For systems where duplicate processing matters, I've generally found that we need to consider:
- Transactional outbox for atomic persistence of business changes and publication intent.
- Consumer idempotency to prevent repeated business effects.
- Inbox or deduplication records when durable duplicate detection is necessary.
- Retries and dead-letter handling for recoverable and non-recoverable failures.
- Ordering guarantees where business operations depend on event sequence.
And even then, the implementation details matter. For example, recording a message as processed in a separate transaction from its business changes can introduce another failure window.
I'm curious how others approach this in production.
Do you implement a transactional inbox alongside your outbox, or do you prefer enforcing idempotency directly through domain constraints and business operations?
I've seen advantages and trade-offs with both approaches, particularly when dealing with high-throughput consumers.