Search code examples
microservicesservicebus

Use case of service bus in microservice architecture


I am trying to learn architecting an business application adhering microservices fundamentals and its considerations. I have come across a question to which I am bit confused.

In a microservice architecture having multiple microservices with their own DB if data needs to be shared among each others then what should be the proffered way, service bus or calling them via HttpClient ? I know that with message queue through service bus whenever a message is needed to be shared with others one micro service can publish this message and all subscriber then can retrieve the same, but in this case if that information needs to be stored in other microservice application's DB too, would that not become the redundant data? So isn't enough to read the data simply via HttpClient whenever needed.

Looking forward to see the replies, thanks for the help in advance.


Solution

  • It depends upon the other factor like latency, redundancy and availability. Both options works keeping redundant data or REST call whenever we need data.

    Points that work against direct HTTP Clients calls are -

    1. It impact availability. It reduce overall availability if the system.
    2. It impact performance and latency. Support there is an operation from service A that need data from service B. Frequency of the operation is very high. In that case, it reduce performance and increase latency as well as response time.
    3. It doesn't support JOINs. So, you have to manipulate data. That also impact performance.

    Points that work against message bus approach/event driven -

    1. Duplicate data - So, increase complexity of the system to keep the same in sync.
    2. It reduce consistency of the system. Now, system is eventual consistent.

    In system design, no option is incorrect. All options have some pros and some cons so choose wisely according to your requirement and system.