Search code examples
asynchronousmicroservicesmessagingmessagebroker

In asynchronous messaging, is client-broker communication synchronous?


While discussing asynchronous messaging on page 67 of the Microservices Patterns book by Chris Richardson (2019), the author writes:

Synchronous—The client expects a timely response from the service and might even block while it waits.

Asynchronous - The client doesn’t block, and the response, if any, isn’t necessarily sent immediately

Given that, it seems that moving from "synchronous" to "asynchronous" communication actually just swaps one synchronous service (e.g., Service A) with a different synchronous service (e.g., a listening port on the message broker like Active MQ, Kafka, IBM MQ, AWS Kinesis, etc.).

That's because the client, presumably, must still block (or at least use 1 thread or connection from a pool) while communicating with the broker, instead of communicating directly with Service A--especially since the client probably expects a broker response (e.g., SUCCESS) for reliability purposes.

Is that analysis correct?


Solution

  • Yes, your analysis is correct.

    Working on your case, the broker's client library provides the asynchronous functionality to the caller code (ServiceA for example), which means that it doesn't block the ServiceA's thread until the operation is finished, but it lets you provide a callback that will be invoked (with the results of the async operation) when it is finished.

    Now the question is: who will invoke that callback? Well, some code from the broker's client library, which runs on a thread that presumably does some periodic checks to see if the operation is finished (or any other logic that will eventually emit this result).

    So yes, there has to be some background thread that does some synchronous work to grab those results.