How do message locks and retries work in Azure Service Bus?
Updated Feb 20, 2026
Short answer
Azure Service Bus uses message locks to ensure only one consumer processes a message at a time, and retries happen automatically if processing fails or the lock expires.
Deep explanation
When a consumer receives a message from Azure Service Bus, the message is not immediately deleted. Instead, it is locked for a specific duration (lock duration).
During this lock period:
- Only that consumer can process the message.
- Other consumers cannot access it.
If the consumer successfully processes the message, it sends a complete action, and the message is removed permanently.
If something goes wrong:
- The application crashes, or
- The lock expires, or
- The message is not completed in time
then the message becomes available again in the queue for another retry attempt.
This ensures at-least-once delivery, meaning messages are never lost, but they may be processed more than once.
Developers must therefore design processing logic to be idempotent (safe to run multiple times without side effects).
Real-world example
In a food delivery system:
- An order message is received by the delivery service.
- The system starts assigning a driver.
- The service crashes before confirming assignment.
Because the message lock expires, Service Bus re-delivers the same order message, ensuring the order is not lost and is processed again.
Common mistakes
- - Assuming lock duration is infinite (it is time-limited).
- - Not handling duplicate processing.
- - Doing long processing without renewing locks.
Follow-up questions
- What is lock renewal in Service Bus?
- What happens when max delivery count is exceeded?
- How do you tune lock duration?