Why is the outbox relay at least once, and what must the consumer do about it?
Sketch your own answer first, then compare it with the one below.
A strong answer
The relay publishes, then marks the row sent. These are two steps on two systems, so the dual-write problem appears again inside the relay. If it crashes between them, it publishes the event again on restart. It cannot do better without a shared transaction with the broker.
So consumers must be idempotent. Each event carries a stable id. The consumer records the ids it has applied, in the same transaction as its effect, and drops an id it has seen. That turns at-least-once delivery into effectively-once processing.
Ordering is a related point. Publish events for one entity in the order of the outbox, and key the partition by entity.
Sources
- Chris Richardson (2018). Pattern: Transactional outbox.
- Martin Kleppmann (2017). Designing Data-Intensive Applications.
- Pat Helland (2005). Data on the Outside versus Data on the Inside.