📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

How would you test that a message consumer is idempotent when the broker delivers the same message twice?

Senior Theory Advanced

🎯 Key points

  • Stable message id or business key recorded in an inbox table with a unique constraint
  • Inbox insert and business change in the same transaction
  • Real broker / emulator and database in Testcontainers
  • Sequential duplicate: exactly one business effect and one inbox record
  • Concurrent duplicates released together to test the race; constraint, not a pre-check, protects it
  • Losing duplicate completes cleanly; downstream events and notifications happen once

⏱ 30-second answer

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.

🔍 What the interviewer is checking

Checks they can turn a distributed-systems guarantee into a concrete, deterministic test.

↩ Usually asked after

More in Senior Testing Topics

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me