When to NOT use a message broker such as RabbitMQ in a micro-services architecture?

Viewed 1596

I am new to the concept of messaging brokers such as RabbitMQ and wanted to learn some best practices.

RabbitMQ seems to be a great way to facilitate asynchronous communication between micro-services, however, I have a beginners question that I could not find an answer to anywhere else.

When would one NOT use a message broker such as RabbitMQ in a micro-services architecture?

As an example:

Let's say I have two services. Service A and Service B (auth service)

The client makes a request to service A which in turn must communicate with service B (auth service) to authenticate the user and authorize the request. (using Basic Auth)

           Internet                
Client ----------------> Service A +-------> Service B [Authenticate/Authorization]
         HTTP request            HTTP or AMQP??

In my limited understanding, the issue I can foresee with using an AMQP in scenarios such as the one outlined above is service A being able to process the request and send a response to the client within an acceptable timeframe, given it must wait for service B to consume and respond to a message.

Essentially, is it a bad idea to make Service A wait for a response from Service B via an AMQP?

Or have I missed the point of an AMQP entirely??

1 Answers

Well actually what you are describing is mostly close to the HTTP.

HTTP is synchronous which means that you have to wait for a response. The solution to this issue is AMQP as you mention. With AMQP you don't necessarily need to wait(you can configure it).

Its not necessarily a bad idea but what most microservices depend on is something called eventual consistency. As this will be a quite long answer with a lot of ifs I would suggest taking a look into Microservices Architecture

For example here is the part about the http vs amqp since its mostly a question about sychronous vs asychronous communication It goes into great detail about different approaches of microservices design listing pros and cons for your specific question and others.

For example in your case the Auth would happen at the API gateway as its not considered best practice to leave the microservices open for all the client applications.

Related