Search code examples
azureasp.net-coremicroservicesazureservicebus

Using asynchronous messaging (Azure service bus) to handle Client Http requests


I have a microservices-based architecture in place.

Service A has details about Cart and the Cart model looks like this:

Cart {
  Id,
  Items,
  Price,
  UserId
}

Service B has User details. User model:

User {
  Id,
  FirstName,
  LastName,
  Email
}

I want to fetch these User details from Service A by communicating with Service B. I am trying to implement this communication between microservices Asynchronously using a messaging queue. The problem I am facing is how to associate a particular message with the corresponding HTTP request from the client?

Is it a good idea to handle client HTTP requests with asynchronous communication among the services?

Flowchart of the above process

To be more specific, how do I associate the message received in step 5 in the above image with the HTTP request handler in step 1.


Solution

  • Service Bus works great when your two processes are disconnected completely, things like downstream processing of an order after it is placed for example. You want the extra layer of certainty that the downstream process will run even if it takes a retry or two without having to wait for it. Trying to use it for a case where you need an immediate response is going to cause the issues you are seeing- that's not what it is for.

    The best solution is going to be something along the lines of having your cart service call the user service over http so that the data stays properly correlated. If you want to keep a layer in between to remove the direct dependency between the two services, something like API Management is going to be a much better fit.