Articles

Azure Service Bus or Event Grid: which do you need?

CMT Software. Published

Use Azure Service Bus when a system is handing over work that must be done, such as an order to invoice or a payment to record, and the message must not be lost. Use Event Grid when a system only needs to announce that something has happened, such as a file landing in storage or a record changing, and other systems decide for themselves whether to act. Many integrations use both: Event Grid to hear about changes, Service Bus to carry the work that follows.

What is the difference between a message and an event?

A message is a piece of work. The sender expects someone to process it, and usually expects it to be processed once. "Create this invoice" or "here is order 10452 with its lines, customer and delivery address" are messages. If nobody processes them, the business has a problem.

An event is a notification. It says that something happened and usually carries just enough to identify it: "a blob was created at this path" or "customer 3381 was updated". The publisher doesn't know or care who reacts. Once it has announced the change, its job is done, and the source system still holds the data.

Service Bus is built for messages. Event Grid is built for events.

What is Azure Service Bus?

Service Bus is a managed message broker. Senders put messages on a queue, or on a topic that several subscriptions read from, and receivers take them off when they are ready. The broker holds messages until they are processed or expire, so a receiver can be offline for maintenance and catch up afterwards.

It has the features you need when each message matters:

  • Peek-lock, where a receiver locks a message, processes it and only then marks it complete. If the receiver crashes, the lock expires and the message becomes available again.
  • Dead-letter queues, where messages that keep failing, or that expire when dead-lettering on expiry is switched on, are moved aside instead of being retried forever or discarded.
  • Sessions, which keep related messages in order, for example every update to one order, while different orders are still processed in parallel.
  • Duplicate detection, switched on when the queue or topic is created, which drops a repeat of a message with the same ID sent within a set time window.

Topics and subscriptions let one message reach several receivers, each with its own filter and its own copy. That makes Service Bus a reasonable choice for publishing business events too, when every subscriber needs reliable, durable delivery.

What is Azure Event Grid?

Event Grid is an event routing service. Publishers send events to a topic, and Event Grid pushes each event to every subscriber whose filter matches, typically a webhook, an Azure Function or a queue.

Many Azure services publish events to Event Grid without any code on your side. A new file in Blob Storage, a resource change in a subscription or a secret nearing expiry in Key Vault can all raise events you subscribe to. Your own applications can publish to custom topics.

It is designed for high volumes of small notifications. Subscriptions can filter on event type and subject, so a handler only receives what it cares about. Delivery is at least once, so handlers have to cope with the occasional duplicate. If a handler is unavailable, Event Grid retries with increasing delays for a limited period. Events that still can't be delivered are dropped unless you have configured dead-lettering to a storage account.

How do Service Bus and Event Grid compare?

Service BusEvent Grid
Best forBusiness messages that must be processedNotifications that something happened
DeliveryReceivers pull messages when readyPushed to subscribers as they arrive
Holding messagesUntil processed or expiredRetried for a limited period, then dead-lettered or dropped
OrderingAvailable through sessionsNot guaranteed
DuplicatesOptional duplicate detection on send; handlers still need to cope with redeliveryHandlers must cope with repeats
Failed itemsBuilt-in dead-letter queueDead-letter to storage, if configured
Azure service eventsNot received directly; route them through Event GridMany Azure services publish natively
Typical receiverA worker or Function processing a backlogA Function, webhook or queue reacting to a change

Event Grid namespaces also offer pull delivery, but for most business integrations the table holds: Event Grid tells you something happened, Service Bus holds the work until it is done.

When should you use Azure Service Bus?

Choose Service Bus when:

  • The message carries work the business depends on, such as orders, invoices, payments or stock movements.
  • The receiving system is sometimes slow or offline, and messages must wait for it rather than be lost.
  • Load comes in bursts, such as a sale or a month-end run, and the receiver needs to work through a backlog at its own pace.
  • Order matters for related messages. An order's cancellation must not be applied before the order itself.
  • You need a clear place where failed messages end up, so someone can inspect, fix and resubmit them.

A typical example: an e-commerce platform places each paid order on a Service Bus queue. A Function picks it up, checks it and sends it to the finance system. If finance is down, the Function retries, and orders that run out of retries go to the dead-letter queue to be resubmitted once finance is back. An order with bad data is dead-lettered straight away and raises an alert while the rest carry on.

When should you use Azure Event Grid?

Choose Event Grid when:

  • You need to react to something happening in Azure, such as a file arriving in storage from a supplier.
  • The publisher shouldn't need to know who is listening, and new subscribers may be added later.
  • The event is a lightweight notification and receivers can fetch the full details from the source if they need them.
  • You want to fan one event out to several handlers with simple filtering and no infrastructure to manage.

A typical example: a supplier drops a stock file into Blob Storage each morning. Event Grid raises a "blob created" event, and a Function picks up the file and processes it as soon as it arrives, instead of a scheduled job checking the folder every few minutes.

When should you use both?

Often. A common pattern is Event Grid for the trigger and Service Bus for the work. Event Grid can deliver events straight to a Service Bus queue, which gives you push-based notifications from Azure services and the durability, retries and dead-lettering of Service Bus for the processing that follows.

In the stock file example, if each file needs several slow ERP calls, route the "blob created" event to a Service Bus queue. Failures are then retried from the queue and end up in the dead-letter queue, not lost after Event Grid's retry window.

What mistakes should you avoid?

  • Using Event Grid for work that must not be lost without configuring dead-lettering. A handler outage that lasts longer than the retry period can quietly drop events.
  • Assuming exactly-once delivery from either service. Both can deliver a message or event more than once, so every handler should check whether it has already processed it.
  • Putting large payloads in messages or events. Both services have size limits. Store large documents in Blob Storage and send a reference.
  • Not monitoring the dead-letter queue. A dead-letter queue nobody watches is just a slower way to lose data.

How do you decide for your integration?

Ask these questions about each flow:

  1. If this is never processed, does the business lose something? If yes, it is a message, and it belongs on Service Bus.
  2. Is it a lightweight notification of a change, where receivers can fetch the details if they need them? Event Grid fits.
  3. Is the source an Azure service that already publishes events? Start with Event Grid.
  4. Does the order of related items matter? Use Service Bus sessions.
  5. Will the receiver need to absorb bursts or work through a backlog? Service Bus.

If the answers point both ways, they usually mean Event Grid at the edge and Service Bus behind it. For the wider choice of whether a flow needs events at all, see our guide to point-to-point or event-driven integration.

We design and build event-driven integrations on Service Bus and Event Grid, and set up the monitoring that goes with them. Read more about our event-driven architecture service and our work on Azure integration.

Email [email protected] with your brief.