wasAsked.

Event Flow — Publish to Consumption: Can you walk me through an example flow of a single event from publish to consumption via Azure Service Bus?

Dodge Construction Network · Senior Developer · technical

Published

Asked in 2026 · Azure

Community answers

Posted by wasAsked editorial collection

Example: an "OrderPlaced" event flowing from the Orders API to a shipping worker through a Service Bus topic. 1. Business action and outbox The Orders API saves the new order. In the same database transaction, it writes an OrderPlaced message to an outbox table, so the event is never lost or published for an order that was not saved. 2. Publishing A background publisher reads the outbox and sends the message with the Azure.Messaging.ServiceBus SDK: var message = new ServiceBusMessage(BinaryData.FromObjectAsJson(evt)) { MessageId = evt.EventId.ToString(), // enables duplicate detection CorrelationId = evt.OrderId.ToString(), Subject = "OrderPlaced" }; await sender.SendMessageAsync(message, ct); It marks the outbox row as sent. Authentication uses a managed identity with the Azure Service Bus Data Sender role. 3. Inside Service Bus - The message goes to the "orders" topic. Each subscription (shipping, notifications, analytics) receives its own copy, optionally filtered with SQL or correlation filters on properties. - Duplicate detection (if enabled) drops a resend with the same MessageId within the configured window. - Messages are stored durably until consumed or expired (time-to-live). 4. Consumption A worker (BackgroundService with ServiceBusProcessor, or an Azure Function with a ServiceBusTrigger) receives from the "shipping" subscription in peek-lock mode: the message is locked, not deleted. 5. Processing - The consumer deserialises the event, checks an inbox or processed-messages table to ignore duplicates (idempotency), and creates the shipment. - On success it completes the message, which removes it from the subscription. 6. Failures - Transient error: the message is abandoned or the lock expires, so it becomes available again and is retried; each attempt increases DeliveryCount. - After MaxDeliveryCount attempts (default 10), Service Bus moves it to the dead-letter queue with a reason. Operations investigate, fix and resubmit. - Long processing: renew the lock (the processor can do this automatically with MaxAutoLockRenewalDuration). 7. Ordering, if needed Use sessions (SessionId = OrderId) so messages for the same order are processed in sequence by one consumer. 8. Observability Trace context flows in message properties (Diagnostic-Id / traceparent), so Application Insights shows one end-to-end trace from the API through the consumer.

Ravindra Wadile · · 0 likes

Sign in to add your answer

Related interview topics