Azure Message Queues: Queue Storage vs Service Bus
Azure has two message queue services. Queue Storage is a simple queue inside a storage account: small messages, at-least-once delivery, no ordering guarantee, very low cost. Service Bus is a full message broker with ordered sessions, dead-lettering, duplicate detection, and publish/subscribe topics. Start with Queue Storage and move to Service Bus when you need one of those features.
Queue Storage vs Service Bus at a glance
| Queue Storage | Service Bus | |
|---|---|---|
| Max message size | 64 KB | 256 KB on Standard; 1 MB by default on Premium, configurable up to 100 MB |
| Max queue size | The storage account’s capacity | 1 to 80 GB per queue |
| Ordering | Not guaranteed | First in, first out with sessions |
| Delivery | At least once | At least once (peek-lock) or at most once (receive and delete) |
| Dead-letter queue | None built in | Built in for every queue and subscription |
| Duplicate detection | No | Yes, within a configurable window |
| Pub/sub | No | Topics with filtered subscriptions |
| Protocol | HTTPS | AMQP 1.0 |
Microsoft keeps a longer version of this table in its Storage queues and Service Bus queues comparison.
Queue Storage for simple backlogs
Queue Storage does one thing: it holds a backlog of small messages that workers pull from. A worker receives a message, which hides it from other workers for a visibility timeout (30 seconds by default), and deletes it when the work is done. If the worker dies first, the message becomes visible again and another worker takes it, so handlers should be idempotent. Messages expire after seven days unless you set a different time to live.
from azure.storage.queue import QueueClient
queue = QueueClient.from_connection_string(CONNECTION_STRING, "orders")
queue.send_message('{"order_id": "12345", "amount": 100.0}')
for message in queue.receive_messages(visibility_timeout=60):
process(message.content)
queue.delete_message(message)
There is no dead-letter queue. Each message carries a dequeue_count, and it is up to you to move a message that has failed too many times to a second queue. Azure Functions does this for you: after five failed attempts its queue trigger moves the message to a queue named after the original with a -poison suffix.
Queue Storage fits when messages are small, order does not matter, and the queue may grow very large, for example image-processing jobs or a buffer in front of a slow downstream API.
Service Bus for ordering, dead-lettering, and pub/sub
Service Bus queues work in peek-lock mode by default. A receiver locks a message, processes it, then completes it. If it abandons the message or the lock expires, the message is redelivered, and after the maximum delivery count (10 by default) Service Bus moves it to the queue’s built-in dead letter queue.
from azure.servicebus import ServiceBusClient, ServiceBusMessage
client = ServiceBusClient.from_connection_string(CONNECTION_STRING)
with client.get_queue_sender("orders") as sender:
sender.send_messages(ServiceBusMessage('{"order_id": "12345"}'))
with client.get_queue_receiver("orders", max_wait_time=5) as receiver:
for message in receiver:
process(str(message))
receiver.complete_message(message)
Three features are the usual reasons to pay for it. Sessions give strict ordering: messages that share a session ID are handled in order by one receiver at a time, which is how you keep the events for one order or one account in sequence. Duplicate detection drops a message whose ID was already seen within a window you configure, so a producer can retry a send safely. Topics turn a queue into pub/sub: each subscription gets its own copy of every message that matches its filter, so the inventory, billing, and notification services can each consume order events independently.
Service Bus is the choice for workflows where losing, duplicating, or reordering a message has a cost: payments, order state machines, and integrations between line-of-business systems.
Where Event Grid and Event Hubs fit
Two other Azure services carry messages but are not queues. Event Grid pushes events to subscribers over HTTP and suits reacting to things that happened, such as a blob being created. Event Hubs is a partitioned, replayable stream for telemetry and analytics, and it exposes a Kafka-compatible endpoint, covered in Kafka on Azure and Kafka vs Azure Event Hubs. If you are comparing Service Bus with a broker you already run, see Kafka vs Azure Service Bus and RabbitMQ vs Azure Service Bus.
Picking Queue Storage or Service Bus
Use Queue Storage when you need a cheap, durable backlog and can live with at-least-once delivery in no particular order. Use Service Bus when you need ordering, a dead-letter queue, duplicate detection, or several consumers for the same message. Moving later is a code change, not a migration of concepts, so starting simple is a reasonable default.
Both stop at the edge of your own infrastructure. When the consumer is a customer’s server, the delivery mechanism is a webhook, and the retries, signing, and endpoint management it needs are what Svix provides.