The Inbox pattern is the consumer-side counterpart to the Outbox pattern, solving the duplicate message processing problem that arises from at-least-once broker delivery. The implementation uses a PostgreSQL inbox_messages table with ON CONFLICT DO NOTHING for idempotent inserts, a generic MassTransit IConsumer that writes incoming messages to the table instead of processing them directly, and a background processor that fetches unprocessed messages in batches using FOR UPDATE SKIP LOCKED for safe concurrent processing. Batch updates use UNNEST to minimize round-trips. The post also covers operational concerns like table growth, poison messages, ordering guarantees, and monitoring, plus a comparison between the Inbox pattern and the Idempotent Consumer pattern explaining when to use each.

7m read timeFrom milanjovanovic.tech
Post cover image
Table of contents
Why You Need an InboxInbox Database SchemaInbox ConsumerInbox ProcessorThings to Watch Out ForInbox vs. Idempotent ConsumerSummary

Sort: