avatarIsrael Josué Parra Rosales

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

4005

Abstract

munication plays in crafting a nimble, streamlined, and remarkably cooperative system, harmoniously adapting to the ever-evolving dynamics of the microservices ecosystem.</p><h1 id="855c">Understanding synchronous communication</h1><p id="8e32">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.</p><figure id="2dc0"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*kJxWe4rUTxpCDycvQ1whlA.png"><figcaption></figcaption></figure><p id="6f0a">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.</p><p id="8d3d">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.</p><p id="15e2">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.</p><h1 id="9d00">Explaining the characteristics of synchronous communication</h1><p id="f7b5">Some of the key points of this communication pattern are the following:</p><h2 id="f35b">Sequentiality</h2><p id="b41a">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.</p><h2 id="1df7">Blocking</h2><p id="773e">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.</p><h2 id="c7c9">Response Guarantee</h2><p id="caea">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.</p><h2 id="d9ae">Simplicity in implementation</h2><p id="161e">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.</p><h2 id="2b3c">Appropriate use</h2><p id="2973">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.</p><p id="b62b">As expected, this pattern also has its disadvantages, such as the following:</p><ul><li><b>Noticeable latency </b>Synchronous communic

Options

ation 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.</li><li><b>Fragility due to failure </b>If a microservice becomes inaccessible, the client’s microservice may crash or experience long timeouts. This can affect system availability and resilience.</li><li><b>Limited scalability </b>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.</li><li><b>Greater coupling </b>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.</li></ul><h1 id="dd23">Discussing scenarios for using synchronous communication in microservices.</h1><p id="5e8b">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.</p><p id="17ad">Below we will see two examples where this type of communication is widely applied:</p><h2 id="3c16">Online payment processing</h2><p id="6278">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.</p><p id="bd00">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.</p><figure id="0a8a"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*qUlzJzHQZZ0nej7iwA0HlA.png"><figcaption></figcaption></figure><h2 id="c7ed">Password validation</h2><p id="8541">In an authentication system, a client microservice that handles login requests may need to verify user passwords in a centralized authentication microservice.</p><p id="3e82">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.</p><p id="cb49">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.</p><p id="697f">Next readings …</p><p id="a0ad">Wait for Chapter 20 — “Microservice Communication — Asynchronous Communication” .</p><div id="4ba9" class="link-block"> <a href="https://readmedium.com/chapter-20-microservice-communication-8be080e09724"> <div> <div> <h2>Chapter 20 — Microservice Communication</h2> <div><h3>Asynchronous Communication</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*dKmGVuw0wCwiSfjg_EvJNg.jpeg)"></div> </div> </div> </a> </div></article></body>

Chapter 19 -Microservice Communication

Synchronous Communication

The following list is the previous chapters of this series:

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” .

Golang
Programming Languages
Software Development
Software Engineering
Software Architecture
Recommended from ReadMedium