Choosing Between Synchronous and Asynchronous Communication in Microservices

D
Dick Edidiong Bassey
·

In a microservices architecture, every inter-service communication is either synchronous (service A calls service B and waits for a response) or asynchronous (service A publishes an event and service B processes it later).

Synchronous communication is appropriate when: the caller needs the response to continue, the operation must be completed before the request is acknowledged to the user, and the downstream service's availability is a hard dependency.

Asynchronous communication is appropriate when: the caller does not need the response immediately, the operation can be retried safely if the downstream service is temporarily unavailable, and decoupling the services' availability is more important than immediate consistency.

The SellTrove pattern: payment confirmation to the payment gateway is synchronous (we need to know if the payment succeeded before confirming the order). Order notification to the fulfilment service is asynchronous (the order is confirmed, fulfilment can process it when ready). Analytics event recording is asynchronous (the user does not need to wait for analytics).

The rule of thumb: if the user is waiting for the result, it is probably synchronous. If the result matters but not immediately, it is probably asynchronous.

— Dick Bassey | DevDick | 2024