Try for free Book a demo

Azure Service Bus Topics vs Event Grid

Microsoft Azure

6 Mins Read | Last modified on March 4th, 2024

Azure Service Bus Topics vs Event Grid

Introduction

This blog will brief on the distinction between Azure Service Bus Topics and Azure Event Grid. First let us see a short introduction of what these Azure services are, before getting deeper into their distinctions. It is important to note the difference between services that deliver an event and services that deliver a message. Service Bus topics handles messages whereas Azure Event Grid handles events.

Event

An event is a lightweight notification of a state change. The publisher of the event has no expectation of how the event is handled at the other end. The consumer of the event decides what to do with the received event. Events can be discrete units or part of a series.

Discrete events report state change and are actionable. To proceed with the further step, the consumer only needs to know that something happened. The event data has information on what happened but not the data that triggered the event. Discrete events are ideal for serverless solutions that need to scale.

Series events report a condition and are analyzable. The events are time-ordered and interrelated. The consumer relies on the sequenced series of events to examine what happened.

Message

A message is raw data produced by a service to be consumed or stored. The message contains the data that triggered the message pipeline. The publisher of the message has an expectation about how the consumer handles the message. A contract exists between the two sides. For example, the publisher sends a message with the raw data and expects the consumer to create a file from that data and send a response when the work is done.

Azure Service Bus Topics

Azure Service Bus Topic is a messaging service offered by Microsoft Azure. Topics along with subscriptions provide a one-to-many form of communication, in a publish/subscribe pattern. Messages are sent to a topic and delivered to one or more subscriptions, based on filter rules that are set on a per subscription basis. The subscriptions can use additional filters to restrict the messages that are to be received. A topic subscription resembles a virtual queue that receives copies of the messages that are sent to the topic. Messages are received from a subscription in the similar way they are received from a queue. Topic Subscriptions support the following patterns like competing consumer, temporal decoupling, load leveling, and load balancing.

Azure Service Bus Topics

Azure Event Grid

Azure Event Grid is a fully managed event service that enables us to easily manage events across many different Azure services and applications. It is an event routing service running on top of Azure Service Fabric. It has built-in support for events coming from Azure services, like storage blobs and resource groups. Event Grid also has support for own events, using custom topics. Filters can be used to route the specific events to different endpoints, multicast to multiple endpoints, and make sure the events are reliably delivered. It supports dead lettering for events which are not delivered to an endpoint. It simplifies building event-driven applications and serverless architectures. Mechanisms involved in Event Gird working is beyond the scope of this blog.

Azure Event Grid

Key Features of Azure Service Bus Topics vs Event Grid

Azure Service Bus Topics

Azure Service Bus Topics is a heavyweight solution that offers a full stack messaging bus. It has the following characteristics:

  • Advanced messaging features like
    1. FIFO
    2. Batching/Sessions
    3. Transactions
    4. Dead lettering
    5. Temporal control
    6. Routing and filtering
    7. Duplicate detection
    8. At least once delivery
  • Reliable asynchronous message delivery that requires polling.
  • Ordered delivery, where messages will be transferred in the exact order as they are received. This is something that is not possible with Event Grid (possible with custom implementation).

Azure Event Grid

Azure Event Grid is a lightweight notification and alerting solution. It has the following characteristics:

  • Dynamically scalable
  • Messaging features like
    1. At least once delivery
    2. Dead Lettering
    3. Includes retry mechanism
  • Advanced message routing and filtering capabilities
  • Uses push mechanism, which means there is no need for long polling.
  • Provides out of the box integration with various Azure services, both as event sources and event handlers.
  • Lower cost
  • Serverless

Comparison of Services

Service

Purpose

Type

When to use

Service Bus

High-value enterprise messaging

Message

Order processing and financial transactions

Event Grid

Reactive programming

Event distribution (Discrete)

React to status changes

Message/Event Delivery

Event Grid is a publish/subscribe(push-push) model where all the events are pushed to the event handlers, whereas in the case of Azure Service Bus Topic it keeps checking the topic subscription if there are any messages available. This means that the Message Processor can control when and how many messages it wants to process and thus controls the load handled. In short Azure Event Grid uses push-model whereas Azure Service Bus Topics uses a pull-model.

  • Protocols used by Azure Service BusTopic to communicate – AMQP, TCP/IP, HTTP.
  • Azure Event Grid is based on HTTP protocol.

Message/Event Processing

Since Azure Service Bus Topics uses pull mechanism the Message Processor oversees getting new messages. It has full control on the pace in which it processes the messages. If the ingestion throughput is more, the messages will pile up until the size of the topic is met. With Azure Event Grid the messages are pushed into the Event Handlers. This means that the Event Handler needs to be capable to handle the load and provide enough throttling to protect from crashing.

Throughput

Event Grid allows the processing of 10 million events per second, per region. This is comparatively more than what Azure Service Bus can handle unless it is distributed across multiple Service Bus namespaces which has a limit of 100 per subscription.

Message/Event Sizes

Azure Service Bus supports the maximum message size of 256 KB for basic/standard tier or 1 MB in case of the premium tier. Anything beyond these quotas is rejected and an exception is received by the calling code. In Event Grid topic, the size of an array can be up to 1 Mb. Each event in an array is limited to 64 KB.

Conclusion

In short, both these services are used for delivering events and messages throughout a solution. Although these services have some similarities, each service is designed for certain scenarios. Any of this can be used based on necessity. When we are looking for processing millions of events with high throughput, velocity and near-real-time processing Azure Event Grid can opt-in comparison with Azure Service Bus Topic whereas Azure Service Bus Topics can be used for more fan-out transactional processing.

This article was originally published on Mar 12, 2020. It was most recently updated on Mar 4, 2024.

Related Articles