Chapter 19 -Microservice Communication
Synchronous 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)
Structure
- Understanding synchronous communication
- Explaining the characteristics of synchronous communication
- Discussing scenarios for using synchronous communication in microservices.
Synchronous Communication
In the upcoming section will be studied the synchronous communication within the microservices architecture. Our exploration commences with a comprehensive examination of the core concepts that underlie synchronous communication, allowing us to gain a profound understanding of its intricacies. We will then dissect the manifold scenarios in which synchronous communication assumes a pivotal role within the microservices architecture, shedding light on its practical applications.
As we navigate through these insights, we will unearth the indispensable role that synchronous communication plays in crafting a nimble, streamlined, and remarkably cooperative system, harmoniously adapting to the ever-evolving dynamics of the microservices ecosystem.
Understanding synchronous communication
In the microservices word, Synchronous communication refers to a pattern of interaction between software components in this case, microservices, in which one microservice waits for an immediate response from another before continuing its own execution. In this context, the client microservice initiates a request to the server microservice and remains in a waiting state until it receives a response, at which point it resumes its own processing.

The most common example of this type of communication is a synchronous HTTP request. When a client microservice makes an HTTP request to another microservice through a synchronous API, the client waits until it receives the HTTP response before continuing.
While synchronous communication offers advantages like straightforward error handling and ease of implementation, it can also pose challenges related to scalability and performance, particularly in environments with high levels of concurrent activity. Therefore, it becomes crucial to conduct a thorough assessment of when and how to employ synchronous communication within a microservices architecture. In cases where efficiency and scalability are paramount, exploring alternatives such as asynchronous communication may be necessary to ensure the optimal functioning of the system.
In the upcoming sections, we will delve into an analysis of the primary characteristics and address the key disadvantages associated with synchronous communication. To conclude this section, we will examine two use cases where synchronous communication can be effectively implemented.
Explaining the characteristics of synchronous communication
Some of the key points of this communication pattern are the following:
Sequentiality
In synchronous communication, requests and responses follow a sequential flow. The client microservice initiates a request to the server and then pauses its operation until it receives a response.
Blocking
A critical characteristic of synchronous communication is that the client microservice becomes blocked during the waiting period for a response from the server. This feature can introduce performance considerations, as a client in a blocked state while awaiting responses may impact the overall responsiveness of the system, particularly when dealing with a high volume of simultaneous requests.
Response Guarantee
Synchronous communication typically assures a response, providing the client with a level of confidence that it will receive either a successful response or an error response. This predictability simplifies error handling and control flow within the client code.
Simplicity in implementation
Synchronous communication tends to be simpler to implement and understand compared to asynchronous communication. From the coding approach, developers can structure the code more linearly, making it easier to debug and maintain.
Appropriate use
Synchronous communication is appropriate in cases where response latency is acceptable and immediate and predictable interaction between microservices is needed. This may include scenarios where close coordination between components is required or when immediate confirmation is needed that an action has been performed successfully.
As expected, this pattern also has its disadvantages, such as the following:
- Noticeable latency Synchronous communication can introduce noticeable latency into an application as the client must wait for the request to complete and the response to be received. This can impact the user experience in time-sensitive applications, such as interactive web applications.
- Fragility due to failure If a microservice becomes inaccessible, the client’s microservice may crash or experience long timeouts. This can affect system availability and resilience.
- Limited scalability Blocking and waiting for resources can limit the system’s ability to handle a large number of simultaneous requests. When a synchronous request involves a long or expensive operation, such as intensive data processing, it may block the client for a long period of time, which is not efficient in terms of resource utilization.
- Greater coupling Synchronous communication often implies greater coupling between microservices, since the client and server must know each other and be available at the same time for communication to be successful. This can make it difficult to evolve microservices independently.
Discussing scenarios for using synchronous communication in microservices.
Synchronous communication among microservices is well-suited for scenarios demanding an immediate and predictable response, a prerequisite for the client microservice to proceed with its execution. This is especially pertinent when obtaining or transmitting data in the context of interactions with secondary microservices.
Below we will see two examples where this type of communication is widely applied:
Online payment processing
When a customer makes an online payment transaction, the microservice in charge of processing the payment needs an immediate response to confirm whether the transaction was successful or if problems were encountered.
In this scenario, synchronous communication ensures that the customer receives a response immediately, which is crucial to providing a smooth user experience and preventing duplicate or incorrect transactions from being made.

Password validation
In an authentication system, a client microservice that handles login requests may need to verify user passwords in a centralized authentication microservice.
In this scenario, synchronous communication is used to send the password verification request and wait for an immediate response to determine whether the login is valid. This ensures secure and accurate authentication before allowing access to the application.
As you can analyze, in those examples synchronous communication looks essential because an immediate and accurate response is required before proceeding to the next action. This ensures an efficient and reliable user experience, as well as the integrity of data and transactions in the system. However, it is important to note that, in each case, measures must be implemented to address the disadvantages seen above related to this type of communication.
Next readings …
Wait for Chapter 20 — “Microservice Communication — Asynchronous Communication” .





