Benefits of using async communication in microservices
When designing microservices, there are two kinds of communication styles that you can choose. Those are synchronous communication and asynchronous communication.
Usually, most architects prefer to use an async communication style because it gives you loose coupling and gives you many benefits. You can see the advantages of async communications below with my diagrams
- It enables independent scaling of service A and B and allows service B to consume messages
at a regular rate even during spikes in traffic to service A,
while sync communication can cause problems if service B cannot scale at the rate of service A
2. It provides fault tolerance by allowing service B to process messages after it is back, while sync communication results in lost messages if service B is down.
3. It can improve performance by reducing latency for the caller service and increasing throughput through the use of message buses like Kafka and SQS. Service A doesn’t need to wait for service B.
4. It can improve resilience by reducing the number of synchronous call chains in microservices,
which can minimize the blast radius and cascading failures in the event of a failure.
5. Async communication using pub/sub patterns makes services more maintainable and modular, allowing new services to easily subscribe to events without altering the existing architecture or changing code.
That being said, the async communication style is not a silver bullet. There are some drawbacks to using this pattern such as increasing complexity, managing out-of-order events, and handling errors. Hopefully, this article will be helpful for you when you are designing your architecture.