Chapter 20 — Microservice Communication
Asynchronous Communication

The following list is the previous chapters of this series:
- Chapter 1 — Introduction to Microservices
- Chapter 2 — Introduction to Microservices (Part 2)
- Chapter-3 Domain-driven design and microservices
- Chapter -4 Advantages of using Go for web development
- Chapter — 5 Understanding HTTP Protocols and REST APIs
- Chapter-6 HTTP Package in Golang
- Chapter 7 — Step-by-step guide on building a simple web service using Go
- Chapter 8 “ Documenting our APIs — Introduction to OpenAPI”
- Chapter 9 -Building a Microservice with Go (Defining the technologies )
- Chapter 10-Structuring our project
- Chapter 11- Coding our Microservice (Part 1)
- Chapter 12 — Coding our Microservice (Part 2)
- Chapter 13 — Coding our Microservice (Part 3)
- Chapter 14 — Coding our Microservice (Part 4)
- Chapter 15 — Coding our Microservices (Part 5)
- Chapter 16 — Coding our Microservices (Part 6)
- Chapter 17 — Coding our Microservices (Part 7)
- Chapter 18 — Microservice Communication (Part 1)
- Chapter 19 — Microservice Communication (Part 2)
Structure
- Understanding asynchronous communication
- Describing characteristics such as message queues, publish-subscribe, and non-blocking nature.
- Discuss scenarios for using synchronous communication in microservices.
Asynchronous Communication
In this section, we will explore a pivotal concept within microservices architecture: asynchronous communication. Will be explored in detail this communication pattern to understand the nuances of asynchronous communication and how it distinguishes itself from its synchronous counterpart. As we delve deeper, we will uncover the fundamental characteristics of this mode of interaction, including the utilization of message queues, the adoption of publish-subscribe patterns, and its non-blocking nature. Furthermore, we will scrutinize specific scenarios where asynchronous communication emerges as the most suitable option for implementing microservices effectively. This section aims to serve as a comprehensive guide, equipping you with the knowledge to comprehend and proficiently harness asynchronous communication in the design and development of microservices-driven systems.
Understanding asynchronous communication
Asynchronous communication in terms of microservices architecture stands as a potent strategy, facilitating versatile and streamlined interactions within microservices-driven architectures. This communication pattern can be defined as a method in which one microservice dispatches a request or message to another microservice, and it doesn’t await an immediate, synchronous response. Instead, it permits the originating microservice to carry on with its execution seamlessly, free from the constraints of blocking or immediate response expectations from the recipient
This mode of communication proves especially valuable in scenarios demanding decoupling, scalability, fault tolerance, and enhanced flexibility within the architecture of distributed systems.

Explaining the characteristics of asynchronous communication
Let’s explore some of the pivotal characteristics that define asynchronous communication among microservices:
Non-blocking Nature
By nature, asynchronous communication is non-blocking. This means that a microservice is not blocked or neither waits for an immediate response after sending a message.
Message Queues
A fundamental element in asynchronous communication is the utilization of message queues. In this context, microservices can publish messages to a message queue, and other microservices can consume these messages asynchronously. This mechanism enables decoupled communication among microservices, as the senders and receivers are not required to have knowledge of each other or be active simultaneously.
Publish-subscribe pattern
A prevalent pattern in asynchronous communication is the publish-subscribe pattern. In this arrangement, a microservice assumes the role of a publisher, transmitting messages to an event handler. Other microservices have the option to subscribe to this handler to receive the messages. This method streamlines the efficient distribution of information to multiple consumers.
Decoupling
The strength of asynchronous communication lies in its ability to decouple microservices from each other, eliminating the need for them to be aware of each other’s existence or to be active simultaneously for communication to occur. This high level of decoupling paves the way for the independent evolution of microservices and the seamless integration of new components into the system without disrupting the existing ones.
Scalability
By not blocking resources or relying on immediate responses, asynchronous communication allows for better scalability.
Fault tolerance
In the event of a temporary outage in a microservice, pending messages have the capability to accumulate within the queue until the service is restored, at which point they can be seamlessly processed.
Asynchronous Communication Chaleneges
Asynchronous communication offers substantial benefits within the framework of a microservices architecture, but it also introduces complexities related to message administration, flow control, latency management, and error handling. Effectively tackling these complexities necessitates meticulous planning, precise implementation, and the application of suitable patterns and best practices to establish a dependable and efficient system.
Some of the most notable challenges are the following:
- Complexities in Message Management Effectively overseeing the delivery, durability, and delivery assurance of such messages can prove intricate, demanding meticulous implementation to prevent message loss or redundant work.
- Flow control and coordination Coordination and flow control mechanisms need to be established to ensure that messages are processed in the correct order and that dependencies between microservices are handled appropriately.
- Error and exception handling When this type of communication is implemented, microservices must implement robust logic to handle failed messages or retry operations in case of transient failures.
- Scalability and resources Although asynchronous communication greatly enhances scalability, it can also place substantial demands on critical resources, such as message storage and queue processing capacity. Ensuring optimal performance requires careful resource planning and sizing to avoid potential bottlenecks.
- Coherence and atomicity Sustaining consistency and atomicity in operations that involve multiple asynchronous messages can pose a considerable challenge. It necessitates the careful implementation of strategies to guarantee the proper handling of complex transactions and the preservation of data integrity
Discuss scenarios for using synchronous communication in microservices
Asynchronous communication between microservices is recommended in cases where it seeks to provide flexibility, scalability and resilience in scenarios in which synchronous communication may not be efficient or practical.
Here a common use cases for asynchronous communication between microservices:
Online order processing
Imagine an e-commerce platform with several microservices responsible for different aspects, such as product management, price calculation, user authentication, and order processing.
When a customer makes a purchase, the order processing microservice can use asynchronous communication to send a message to the inventory microservice to check and update product availability. Instead of blocking the order process while waiting for an immediate response, the order processing microservice can continue its execution and process the order.
As can be seen asynchronous communication is valuable for providing quick response to users while performing intensive processing tasks in the background or delivering real-time notifications. It also enables a scalable and resilient architecture by offering the ability to handle variable load and decongest the main flow of the application.
Next readings …
Wait for Chapter 21“Microservice Communication — Communication Protocols”.





