Compare Service Bus, Event Grid and Event Hubs
Match queues, event notifications and telemetry streams to Service Bus, Event Grid and Event Hubs.
By Invicly Tech, , in Microsoft Azure Cloud Engineering. About 14 minutes to read.
In short
Azure has three main messaging services and each one solves a different problem. Service Bus is a broker for commands and business messages that must not be lost, Event Grid pushes small notifications that something happened, and Event Hubs ingests large streams of telemetry that many readers replay. Picking the right one starts with asking what the message means and who must act on it.
Think of it like this: Service Bus is a registered letter, Event Grid is a doorbell, and Event Hubs is a CCTV recording you can rewind.
Explained simply
When one part of an app needs to tell another part something, it can call it directly or leave a message. Leaving a message means the sender does not wait, and the receiver can be busy, slow or even offline for a while. Azure offers three managed services for this, and they are easy to mix up because their names sound alike.
Service Bus is for messages that carry work, such as charge this order or send this invoice. It keeps each message safe until a receiver says it is done. If the receiver keeps failing, the message moves to a dead-letter queue so a person can look at it.
Event Grid is for short notices that something happened, such as a file was uploaded or a resource was deleted. It pushes the notice to whoever subscribed. The sender does not care who listens or what they do with it.
Event Hubs is for a large, constant stream of data, such as clicks, logs or sensor readings. It stores the stream for a set time, and several readers can each read it at their own pace, even going back to replay it. A simple rule: work goes to Service Bus, facts go to Event Grid, and floods of data go to Event Hubs.
Press Play on a diagram to walk through it one step at a time.
- Commands and business messages
- Receiver pulls with peek-lock
- Queues and topics with subscriptions
- Dead-letter queue built in
- FIFO per session when enabled
- Discrete event notifications
- Pushes to subscribers (handlers)
- Filters by event type and subject
- Retries for up to 24 hours by default
- No ordering guarantee
- High-volume telemetry streams
- Readers pull and track offsets
- Ordered within one partition
- Data kept for a retention period
- Many consumer groups replay the same data
- Service Bus queue
- Charge card for order
- Generate PDF invoice
- Service Bus topic
- Order placed: billing, shipping and loyalty each subscribe
- Event Grid
- Product image uploaded
- Key Vault secret near expiry
- Event Hubs
- Click stream from the web shop
- Application telemetry at high volume
In depth
Commands, events and streams
Start by naming what the message means. A command asks for something to be done and has one owner: process payment 42. If it is lost, the business loses money, so it needs a broker that stores it, hands it to one receiver at a time and keeps failures. An event announces a fact: invoice 42 was paid. The publisher does not know or care how many subscribers react. A stream is a sequence of many small events whose value is in the whole series, like temperature every second. Readers want to process it in order, in bulk, and sometimes again from the start. Once you have named the message, the service choice is usually obvious, and the edge cases are about scale, order and cost.
- Step 1Does one owner have to do work?
Yes: Service Bus queue
- Step 2Do several owners each do work?
Yes: Service Bus topic with subscriptions
- Step 3Is it a reaction to a fact?
Yes: Event Grid subscription
- Step 4Is it a high-volume series to analyse?
Yes: Event Hubs with consumer groups
Service Bus in more detail
A Service Bus namespace holds queues and topics. A queue gives each message to one of many competing receivers, which spreads load. A topic copies each message to every subscription, and each subscription can filter by message properties, so billing and shipping both get the order they care about. Receivers usually use peek-lock: the message is locked while being processed and removed only when completed. Sessions group related messages by a SessionId and deliver them in order to one receiver at a time. Duplicate detection drops a resent message with the same MessageId inside a time window. Tiers matter: Basic has queues only, Standard adds topics, sessions and duplicate detection, and Premium gives dedicated capacity, larger messages and private networking.
- Basic: queues only
- Standard: topics, sessions, duplicate detection; messages up to 256 KB
- Premium: dedicated resources, larger messages, private endpoints
- Dead-letter queue exists on every queue and subscription
Event Grid in more detail
Event Grid routes events from sources to handlers. Sources include Azure services, such as Blob Storage raising Microsoft.Storage.BlobCreated, and your own custom topics. A subscription says which events to send where, filtered by event type and by subject prefix or suffix, such as only files ending in .jpg. Handlers include Azure Functions, webhooks, Service Bus queues, Storage queues and Event Hubs. Delivery is push and at least once. If a handler fails, Event Grid retries with growing delays, by default up to 30 attempts or 24 hours, and can then write the event to a dead-letter blob container if you configured one. Events are small and carry a reference to the data, not the data itself, so the handler reads the blob separately.
Event Hubs in more detail
An event hub is split into partitions. Producers send events, and events with the same partition key land in the same partition, which keeps them in order. Nothing is deleted when read. Instead each reader keeps a checkpoint, an offset saying how far it got, usually stored in a blob container. A consumer group is one independent set of checkpoints, so the alerting service and the archive job read the same data without getting in each other's way. Events stay for the retention period of the tier and then age out. Event Hubs also speaks the Apache Kafka protocol on Standard and higher tiers, so many Kafka clients can connect by changing their settings. Throughput is bought as capacity units, so idle hubs still cost money.
- Sensor to Event hub partition 0: Send reading, partition key device-71Send reading, partition key device-7
- Event hub partition 0 to Alerts reader: Alerts group reads offset 1002Alerts group reads offset 100
- Alerts reader to Event hub partition 0: Checkpoint at offset 1003Checkpoint at offset 100
- Event hub partition 0 to Archive reader: Archive group reads offsets 1 to 100 in bulk4Archive group reads offsets 1 to 100 in bulk
- Archive reader to Event hub partition 0: Checkpoint at offset 100 in its own group5Checkpoint at offset 100 in its own group
Ordering, delivery and cost side by side
None of the three gives exactly-once processing end to end, so idempotent handlers are always part of the design. Ordering differs: Service Bus orders within a session, Event Hubs within a partition, and Event Grid not at all. Retention differs too: Service Bus keeps a message until it is settled or its time to live runs out, Event Hubs keeps everything for a fixed period, and Event Grid keeps an undelivered event only while it retries. Costs follow the model. Event Grid is charged per operation and is cheap for low volume. Service Bus Standard has a monthly base charge plus operations. Event Hubs charges for reserved capacity per hour. For learning, Microsoft publishes Docker-based emulators for Service Bus and Event Hubs, so you can practise locally first.
- Service Bus: ordered per session
- Event Hubs: ordered per partition
- Event Grid: no ordering promise
- All three: at least once, so plan for duplicates
Learn it in 5 short steps
About 30m each. Track them with a timer in your plan.
- 1Use Service Bus for commands~30m
- 2Use Event Grid for notifications~30m
- 3Use Event Hubs for streams~30m
- 4Compare ordering and delivery~30m
- 5Pick one per scenario~30m
Key points
- A command expects one owner to do work; an event only states a fact.
- Service Bus keeps each message until a receiver settles it or it expires.
- Event Grid is push-based and lightweight; handlers must respond quickly.
- Event Hubs is a log: readers move through it, nothing is deleted on read.
- All three deliver at least once, so every handler must cope with duplicates.
Key terms
Tap a card to flip it. 0/6 known
Examples
Three messages in one shop, three services
Contoso's shop has three needs. Step 1: when a customer checks out, the API sends a ChargeOrder command. Losing it is not acceptable and only the payment worker should handle it, so it goes to a Service Bus queue named orders. Step 2: product managers upload photos to Blob Storage and thumbnails must be made. Nothing has to be sent by the app at all: an Event Grid subscription on BlobCreated, filtered to the images container, pushes the event to a Function. Step 3: the web front end emits about 2,000 click events a second for analytics and fraud checks. This goes to an event hub with 4 partitions and two consumer groups, one per team. Step 4: check the choice against failure. If the payment worker is down, orders wait in the queue; if analytics falls behind, it catches up from its checkpoint.
az group create --name rg-msg-lab --location westeurope
az servicebus namespace create --resource-group rg-msg-lab \
--name sb-contoso-lab --sku Standard
az servicebus queue create --resource-group rg-msg-lab \
--namespace-name sb-contoso-lab --name orders --max-delivery-count 10
az eventhubs namespace create --resource-group rg-msg-lab \
--name evh-contoso-lab --sku Standard
az eventhubs eventhub create --resource-group rg-msg-lab \
--namespace-name evh-contoso-lab --name clicks --partition-count 4
# cleanup when finished: az group delete --name rg-msg-lab --yesRouting a storage event into a queue
Sometimes you want an event to become durable work. Step 1: create a storage account and the orders queue from the first example. Step 2: create an Event Grid subscription on the storage account with the Service Bus queue as the endpoint and only the BlobCreated event type. Step 3: upload a test file such as invoice-0001.csv. Step 4: check the queue's active message count; you expect 1. Now a worker can process the upload with peek-lock and dead-lettering. Step 5: delete the resource group to stop charges. This pattern keeps Event Grid for the notification and Service Bus for the reliable work.
ST_ID=$(az storage account show -g rg-msg-lab -n stcontosolab --query id -o tsv)
Q_ID=$(az servicebus queue show -g rg-msg-lab --namespace-name sb-contoso-lab \
-n orders --query id -o tsv)
az eventgrid event-subscription create --name uploads-to-orders \
--source-resource-id "$ST_ID" --endpoint-type servicebusqueue \
--endpoint "$Q_ID" --included-event-types Microsoft.Storage.BlobCreated
az servicebus queue show -g rg-msg-lab --namespace-name sb-contoso-lab \
-n orders --query countDetails.activeMessageCountQuick reference
- Command with one owner: Service Bus queue
- Same message to several owners with filters: Service Bus topic and subscriptions
- Reaction to a resource or app fact: Event Grid subscription
- High-volume telemetry with replay: Event Hubs plus one consumer group per reader
- Order: Service Bus per session, Event Hubs per partition, Event Grid none
- Service Bus Basic has no topics; pick Standard or Premium if you may need them
- All three are at-least-once: make every handler idempotent
- Practise locally with the Service Bus and Event Hubs emulators before paying for a namespace
Common mistakes
- Using Event Grid for work that must be processed exactly in order; it does not promise order.
- Treating Event Hubs like a queue and expecting messages to disappear once read.
- Choosing Service Bus Basic and later needing topics, which Basic does not include.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Classify each message: (a) password reset email must be sent, (b) a VM was deallocated, (c) 500 log lines a second from a web farm, (d) a new order must be billed and also shipped.
- Exercise 2medium
Create a Standard Service Bus namespace with a queue named orders, send one test message from the Service Bus Explorer in the portal, and confirm the count with the CLI. Then clean up.
- Exercise 3hard
A fleet of 50,000 devices sends a reading every 10 seconds. Alerts need readings per device in order; finance needs a nightly export. Design the ingestion: service, partition key, consumer groups and what happens if the alert reader stops for two hours.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- Can I just use Storage queues instead of Service Bus?
- For simple, cheap background jobs, yes. Storage queues lack topics, sessions, duplicate detection and a built-in dead-letter queue, so use Service Bus when business messages need those guarantees.
- Is Event Grid the same as Event Hubs?
- No. Event Grid pushes individual notifications to handlers and forgets them once delivered. Event Hubs stores a high-volume stream that readers pull and can replay.
- Do any of these services give exactly-once delivery?
- Not end to end. Service Bus duplicate detection helps on the sending side, but your handler can still see a message twice after a crash, so design it to be idempotent.
- Can I try these without paying?
- Event Grid has a free monthly allowance of operations. Service Bus and Event Hubs have Docker-based emulators for local development, and a free trial subscription covers a short cloud lab.