Message As a Service — Service Bus

calendar_today ago • schedule2 min read
— Originally published at dev.to

When two components such as microservices are communicating with each other, the usual communication mechanism is the traditional, synchronous HTTP request, which consists of component A sending a request via HTTP and waiting for component B to respond.

Image description
The approach has a wide range of benefits, such as:

  • Immediate response: the caller blocks until its request gets processed
  • Immediate error feedback: both components can deal with failures once the failure happens
  • No extra infrastructure: you need to implement the endpoints, auth, error handling, and so on, but you don't need to configure an external service or platform

The traditional approach has several benefits, but what happens if the component needs to perform a large number of operations? What if it doesn't need to wait until every integration with an external system finishes? What if you don't want the temporal coupling? What about cascading failures, when component A calls component B that calls component C and so on? What if you need an asynchronous communication style?
That's when the asynchronous messaging concept comes into play. By using this approach, you can build asynchronous operations. For instance, component A can send a message to a message broker, which can deliver it to the listeners that are interested in it.
The message broker is a central component that receives all the incoming messages into queues or topics, and the listeners fetch these requests from the message broker. This approach has a wide range of benefits as well, such as:

  • Asynchronous operation: the component sending the request does not need to wait until it finishes
  • Usually the message broker offers a lot of built-in features such as retry mechanisms and dead-letter queues
  • Decoupling
  • Resilience: the consumer can be down and the messages wait
  • Load levelling: it can absorb traffic spikes

On Azure, one of the options for implementing this communication style is Service Bus.
Azure Service Bus is a managed enterprise message broker with queues and publish-subscribe topics.
You can choose between queues and topics.
Queues store messages in a queue until the receiving component is available to process them. It follows the competing consumers pattern, one message to one consumer.
Topics support multiple subscriptions, so each topic subscription receives a copy of the message. On Azure, the Basic tier doesn't support topics.

Image description
It is important to be aware of some drawbacks as well, such as:

  • Eventual consistency: the data across services won't be in sync immediately
  • Complexity
  • Harder debugging and tracing
  • Requires idempotent consumers

To conclude, it is important to know the communication styles and their benefits and drawbacks, so this knowledge can sharpen and guide our decisions instead of just doing things willy-nilly.

1 Comment

0 votes
🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

How AI Is Changing Web Development, and What Developers Still Need to Understand

Daniel Decker - Nov 10

A Message From Our Founder: On the Winding Down of LaaSy™

Ken W. Algerverified - Oct 29

Dozens of email accounts: learning AI coding tools as a student

rahuldk1105 - Oct 27

How to Reduce Your AWS Bill by 50%

rogo032 - Jan 27

10 Proven Ways to Cut Your AWS Bill

rogo032 - Jan 16
chevron_left
154 Points • 2 Badges
2Posts
0Comments
https://raffaeleloi.dev

Commenters (This Week)

1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!