1
votes

Anywhere you read about Microservices, it says microservice should communicate asynchronously. It is understandable why asynchronous communication is preferred as it removes dependencies and provides low-coupling, and availability, etc.

Suppose, there is a common authorization service that is invoked every time a user calls an API. In this scenario you cannot move further util you have the response from the authorization service. Although you can call the authorization service asynchronously using Async IO, however, it is still a request/reply pattern.

Questions I have

  1. Is possible to get rid of synchronous communication or more appropriately request/reply pattern in microservices-based system design?
  2. Although it is possible to implement a reply/response pattern asynchronously through messaging and callbacks, which add significant overhead and latency but is it worth converting every request/reply to asynchronously?
  3. If synchronous calls cannot be eliminated completely, then which scenarios it is ok to have synchronous calls among microservices?
1
Take a look at IAM with Okta okta.com/blog/2019/05/…Vinnie James

1 Answers

1
votes

I think the short answer for your question is: request-reply pattern doesn't mean synchronous. It can also be asynchronous. Which you already mentioned.

Long answer:

Request-Reply is just a principle. For example you send an email to a friend. The message contains data relevant to you and you are expecting a response but didn't say that explicitly. Your friend will see the email when he will get back from work and then he may or may not reply to you. Only you know that you need an answer from him.

Now there are a few options while waiting for your response. Either block your entire life until your friend responds (which will mean synchronous communication) either do something else until the response arrives in your inbox (which is asynchronous).

Now, to the point:

Is possible to get rid of synchronous communication or more appropriately request/reply pattern in microservices-based system design?

Yes, you already have answered that at the second point. Even though it is possible I think it should be used where it is required.

Although it is possible to implement a reply/response pattern asynchronously through messaging and callbacks, which add significant overhead and latency but is it worth converting every request/reply to asynchronously?

For the right scenario, yes. The messaging system have very good performances so the latency should not be an issue. When a latency problem occurs in a messaging system there are other options to improve it.

If synchronous calls cannot be eliminated completely, then which scenarios it is ok to have synchronous calls among microservices?

Yes.

There is one more thing that needs to be added. Synchronous doesn't always mean blocking. In a reactive world, if you make an HTTP call to another service the caller sends the request and then awaits for the response in a non-blocking manner. When the responses arrives, the caller is notified the the response has arrived and so the process continues. While "awaiting" the CPU can do other stuff.