Idempotency needs a duplicate-detection mechanism: a stable message id (or business key) recorded in an inbox table with a unique constraint, in the same transaction as the business change. Test it against a real broker or emulator and the real database in Testcontainers. Sequential duplicates: publish the same message twice with the same message id, wait until both deliveries are processed, then assert exactly one business effect (one row in the payments table, one outbox event) and one inbox record. Concurrent duplicates: deliver both copies at once (or call the handler from two tasks released by the same gate) to exercise the race where both pass an "already processed?" check; only the unique constraint or a lock makes that safe, and the losing copy must complete without error rather than dead-lettering. Also assert side effects downstream (published events, notifications) happened once.
Checks they can turn a distributed-systems guarantee into a concrete, deterministic test.
Last updated 23 Nov 2026.