Reliable Communication in Distributed Systems with Azure Messaging Models

Aniruddha Mane
Globant
Published in
6 min readJan 5, 2024
A Distributed System

If your application has modules on different servers, you must ensure reliable communication between them. Azure provides various communication tools, such as Queue Storage, Event Hubs, Event Grid, and Service Bus. This article will teach you how to choose the right tool for your communication needs, and you will learn:

  • When to use Messages and when to choose Events.
  • When to choose Storage Queue.
  • When to use Event Grid, Event Hub, or Service Bus for messaging.

Let’s start with a Distributed System.

What is a Distributed System?

A distributed system is a computing system in which multiple components, such as computers, servers, and devices, work together to achieve a common goal. These components are connected and communicate with each other to share resources and information.

Communication between components is crucial in a distributed system. This communication can occur through various methods, such as message passing, remote procedure calls, or other communication protocols.

This article will assist you in selecting the appropriate Azure messaging technology for distributed applications.

Deciding Between Messages and Events: Making the Right Choice

Imagine you’re planning the architecture of a distributed File-sharing application (Video files/music files/ data files). You want to ensure the application is as reliable and scalable as possible, and you have decided to use Azure Technologies for communication.

To select the correct Azure technology, learn how different parts of the application communicate. You can opt for distinct Azure technologies for each communication instance.

In communication, we must know if we’re sending messages or events. This knowledge helps you choose the right Azure service for your needs.

What is a Message?

A message is nothing but data produced by one entity and consumed by another entity. The objective of the consumer who takes that data is to process that data.

For example, suppose a user uploads a file using a mobile application; then that file must be sent to WebAPI, which runs on Azure. Here, the file itself must be sent, not just a notification. So, this is an example of a message.

What is an Event?

Events are notifications. The ones who send events are called “publishers.” The ones who receive them are called “subscribers.” When events happen, the parties that get them decide which ones they like and subscribe for them. Azure Event Grid and Azure Event Hubs are middlemen for handling these subscriptions. When publishers send out an event, this middleman forwards it to the subscribers who want that info.

Imagine you have an application with an API that checks if users are real. After a user logs in successfully, the API sends a notification to client applications to show they’re online. This notification is considered an event and contains only basic status information.

Choose the right option for message-based delivery

Imagine you have an e-commerce application where users can place orders. Instead of processing the orders directly within the web application, you want to offload the order processing to a separate background service to ensure the responsiveness of your website. This scenario is a perfect use of a message-based system, and Azure offers two solutions to this problem:

  • Azure Queue Storage
  • Azure Service Bus

What is Azure Queue Storage?

Queue Storage is a simple and temporary location to store messages between components of a distributed Application. It uses Azure Storage to store millions of messages securely. Messages can be accessed from anywhere via a REST-based interface.

Azure Queue Storage (Source: Microsoft learn https://learn.microsoft.com/)

What is Azure Service Bus Queue?

Service Bus is like a special system for enterprise apps. These apps often use different ways of talking, have special data rules, need extra safety, and could be both in the cloud and on your computers. Service Bus is made using a special messaging system that’s great for these situations.

Both services use a queue to hold your messages until the receiver is ready.

What are Azure Service Bus Topics?

Think of Azure Service Bus topics as a way to share messages but with more than one subscriber. When you send a message to a topic, it can tell multiple components to start doing their tasks.

Service Bus Topics (Source: Microsoft learn https://learn.microsoft.com/)

Which Service should I prefer?

  • Use Service Bus Topics if you need multiple receivers to handle each message.
  • Use Service Bus Queues if you need a FIFO (First-In-First-Out) guarantee and when messages are to be delivered only once.
  • Use Queue storage if you want to track progress for processing a message inside of the queue.

What is Azure Event Grid?

Many apps use the publish-subscribe method to notify distributed components about something that happened or when something changed. Suppose you have a streaming service app that distributes films, music, etc., with a web API that runs on Azure. When any new movie arrives, you must notify all mobile/browser clients about the new release. In such cases, the Event grid is the perfect solution; here publisher won’t expect any action from the subscriber.

Event Grid distributes events from different sources, such as Blob Storage and Service Bus, to different handlers, such as Azure functions and Logic Apps.

Below are the main components of the Event Grid that connect a source to the handler.

  • Event: Something that occurred.
  • Event sources: Where it happened.
  • Topics: Where senders send events.
  • Event subscriptions: The way events are directed, sometimes to many handlers. Handlers also use subscriptions to choose events.
  • Event handlers: Apps or services that respond to events.

The following diagram shows that the Event Grid is positioned between multiple sources and Handlers.

Event Grid. (Source: Microsoft learn https://learn.microsoft.com/)

The Event Grid delivers one event at a time to subscribers. Event Grid is not useful if you want to handle a large stream of events. In such cases, Event Hub is useful.

What is Azure Event Hub?

Event Hubs helps you create a way to handle lots of events super quickly. It can deal with data from lots of places at once and send it to different analysis tools. This makes things happen in real-time, and you can also look at the same data repeatedly if you need to.

Choose Event Hub if:

  • you want to record a continuous flow of events and save them in places like Data Lake or Blob Storage.
  • you want to gather information from your events or study patterns in the stream, sort of like doing calculations on them.
  • you want a way to make sure your events are sent and received properly, like a strong system for communication.

However, if you’re looking for an easy way to share events among specific people, like using a simple system for sharing from your web server, then Event Grid is the one you should go with.

Summary

In this part, you learned about Azure messaging services. These services help you create strong and reliable applications spread over many parts. To pick the right one, think about what kind of information you want to send between the parts (like messages or events).

--

--