Deferring Service Bus messages when a dependent API is unavailable
Short answer
B Defer the Service Bus message so it stays in the queue and is retrieved by sequence number once the external API recovers, avoiding the DeliveryCount increase that Abandon causes.
Question
Key Takeaways
Azure Service Bus message deferral parks a peek-locked message in the queue so it can be retrieved later by sequence number instead of being redelivered. Defer is the correct action when a dependent external API is temporarily unavailable and the delivery count must not increase, because Abandon triggers broker redelivery and Complete deletes the message.
Expert Analysis
A temporary outage of the dependent external API requires the message to sit idle yet stay addressable, which is exactly what deferring a peek-locked Service Bus message delivers without touching its DeliveryCount.
Peek-lock settlement exposes four distinct outcomes, and deferral is the only non-destructive hold
Azure Service Bus settles a received message in one of four ways while the peek lock is held: complete it, abandon it, dead-letter it, or defer it. Deferring neither deletes, quarantines nor releases-for-redelivery — the broker moves the message into a deferred state where it stays stored in the queue but is invisible to ordinary receive operations, surfacing only when a consumer asks for it by SequenceNumber. That is documented product behaviour, not a naming convention. Two mechanics follow from it: the message is no longer handed out in arrival order, and because the broker is not scheduling a redelivery, DeliveryCount does not climb from repeating abandon/redelivery cycles while the dependency is down. Deferral also presupposes PeekLock receive mode; a receiver configured for ReceiveAndDelete settles and removes the message as it reads it, leaving nothing to defer. Nor is dead-lettering a hold: it relocates the message to the dead-letter queue with a reason and description, which downstream monitoring reads as a fault rather than a pause. Complete is terminal in the opposite direction — once the settlement succeeds the message ceases to exist, so the work it represents is gone. Defer is therefore the one settlement action that is simultaneously non-destructive and non-retrying.
The API dependency makes suspension, not redelivery, the disposition that satisfies every constraint
The blocking fact is that the external API is temporarily unavailable — an availability window, not a payload defect — while processing must resume later and each attempt must not inflate the delivery count. Deferral satisfies all three at once: the message remains accessible through its sequence number, its processing is postponed, and no broker-driven retry loop touches the count. A second, less obvious benefit is throughput isolation. Abandon releases the lock and makes the message immediately visible again, so competing consumers keep picking it up, keep hitting the same dead endpoint, and keep abandoning; within the entity's MaxDeliveryCount (10 by default) the broker automatically dead-letters the message, converting a short outage into permanent eviction from the main queue. Deferral breaks that loop because nothing is scheduled to redeliver until the application asks for the message by number, letting unrelated messages drain normally while the API recovers. Dead-lettering would likewise end the message's active life, just with a different label, and completing would discard the work outright. Only defer keeps the message parked, counted once, and fully recoverable.
Abandon and defer both leave the message queued, but only one hands the retry decision to the application
The two actions look interchangeable because neither removes the message, so the boundary has to be drawn on control and accounting. Abandon declares that the message was not processed and releases the lock; the broker then decides the next delivery, the message becomes visible again straight away, and DeliveryCount advances by one. Defer releases the lock as well, but it instructs the broker to withhold the message from every consumer until someone requests that exact sequence number — reactivation is application-driven and is not treated as another retry attempt. Dead-letter is a third, distinct state: quarantine with a DeadLetterReason, terminal for normal processing. Complete is acknowledgement. The discriminating test is what kind of problem the message has: permanently unprocessable points to dead-letter, already handled points to complete, unprocessed-but-retryable-now points to abandon, and processable-later-on-an-external-condition points to defer. An API recovery is a condition, not a retry. The neighbouring mechanism, scheduling with ScheduledEnqueueTimeUtc, also avoids count inflation, but it demands a known resume time up front, which an unpredictable API recovery does not provide.
Deferral takes effect at settlement inside the peek-lock window, and reactivation depends on the stored sequence number
The decisive step is the settlement call issued against a received message before LockDuration elapses — DeferMessageAsync on the received message, or receiver.DeferAsync with the lock token. Two operational consequences deserve planning. First, timing: if the lock expires before the defer is recorded, the broker redelivers the message and the delivery count increments anyway, so deferral must happen promptly rather than after a long in-handler wait. Second, deferral is a one-way door without bookkeeping — the broker will never surface the deferred message on its own, so the SequenceNumber must be persisted (session state for sessionful entities, a database or cache row otherwise) and a later receiver must call ReceiveDeferredMessageAsync with that number, or peek a range to rediscover it, to obtain a fresh lock and settle it. Deferred messages continue to occupy queue storage and remain subject to the entity's TTL, so a message deferred past expiry simply vanishes. Once the defer call succeeds, the broker writes deferred state and all delivery accounting for that message stops until reactivation.
Official Reference
- https://learn.microsoft.com/en-us/azure/service-bus-messaging/message-deferral
- https://learn.microsoft.com/en-us/azure/service-bus-messaging/message-transfers-locks-settlement
These links open the official vendor documentation in a new tab.
Exam Strategy
When a stem turns on delivery counts or retry side effects, separate holding the message from handing it back: Abandon, Dead-letter and Complete each put the message into a state the broker acts on immediately, while Defer and scheduled enqueue only change when it becomes visible. Ask which action the application must reverse later — deferral needs a stored sequence number, so any mention of keeping the message accessible for later retrieval is the tell.
Related Analysis
Practice All AI-200 Questions
Access 69 questions with complete answers and detailed explanations.
View Full AI-200 Practice Test →