wasAsked.

How would you build idempotent message consumers in .NET for order and payment events?

Razorpay · Full Stack Developer · 3-4-years · technical

Published

Year not specified · .NET, Messaging, Microservices

Community answers

Posted by wasAsked editorial collection

Message delivery is commonly at least once, so a consumer must tolerate duplicates. Give each event a stable ID and record processing atomically with the business change, usually in an inbox table with a unique constraint. Example: BEGIN TRANSACTION; INSERT INTO Inbox(RestaurantId,OutletId,MessageId,ReceivedAtUtc) VALUES(@RestaurantId,@OutletId,@MessageId,@Now); -- unique violation means already processed -- apply business update in the same tenant and transaction COMMIT; Acknowledge only after commit. Make external side effects idempotent with provider keys or an outbox, because a database transaction cannot atomically include email/payment services. Define ordering assumptions, bounded retries, dead-letter handling, retention, and observability.

Backbencher Developer · · 0 likes

Sign in to add your answer

Related interview topics