Journal / Backend
When events arrive twice
In distributed systems, a message can be delivered more than once even when the consumer appears to work correctly.
The underlying problem
Imagine a consumer writes a database change and crashes before acknowledging the message. On restart, the broker delivers it again. If the handler is not idempotent, the business action can happen twice.
A practical approach
Store a stable event identifier with the business change inside the same database transaction, and enforce uniqueness at the database level. A duplicate then becomes a recognized no-op. Consider ordering, retry policies and dead-letter handling separately.