Microservices are an IT and software programming architecture style that is mainly characterized by the breakdown of its applications into smaller elements that are independent one to another. This approach adds flexibility and dynamism, since it is easier to add new features to a computer program when dividing it into multiple parts than it is when organized as a single application (monolithic architecture). But, on the other hand, it also implies challenges and problems that need to be solved, such as the communication between microservices.
What is the communication between microservices?
One of the most important aspects of developing an application or software based on microservices is the communication between them; a process that can turn out to be quite complex.
In a monolithic architecture program, which runs as a single process as a result, the various components communicate with each other via language-level calls. These components may be closely linked to each other in case-specific objects are created via code, or loosely coupled connections can be established if references to abstractions are used, using dependency insertion.
A microservices-based application or software as a system that is also run on different processes, services, and oftentimes, also on several servers or hosts. Since it is common for each service instance to work as a separate process, services need to work through the use of a process communication protocol. Depending on the nature of each service, these protocols may be HTTP, AMQP or a binary TCP protocol.
All of this implies that, in the microservices architecture, it is necessary to change the communication mechanisms. There are several possible solutions, and it is important to choose the most suitable for each software developed through microservices, since some communication systems are inefficient and lead to poor performance of the software or application.
The truth is that there is not a one, but several microservice communication solutions. Below we will list the different options.
Types of microservice communications
The communication between the client and the different microservices can be accomplished through different types of communications, each focused on a different scenario. In general, there are two criteria to classify these communication systems:
- Based on the type of protocol: synchronous or asynchronous.
- Based on the number of receivers: one or many.
Synchronous or asynchronous protocol
These are the differences between them:
- Synchronous protocol. It is characterized for being a system that implies isolating each microservice as much as possible, since sub-processes get locked. HTTP/HTTPS would be a typical example of asynchronous microservice communication protocol, where the client can only continue its operation when it receives a response from the server.
- Asynchronous protocol. In this case, the sub-processes are not locked and protocols that are compatible with many operating systems and cloud environments are used. One example would be the AMQP protocol, where the client’s or message sender’s code usually does not wait for a reply. What is does is simply send a message to a RabbitMQ queue or any other messaging agent.
One or many receivers
The second classification criterion of microservice communication protocols is the number of receivers, distinguishing between one or many receivers.
- Single receiver. In this case, each request must be processed by a receiver or service. One example of this type of communication is the Command pattern.
- Many receivers. One example of this type is the event-driven microservices architecture, which is based on a messaging agent or event bus interface that broadcasts the data updates among different microservices via events. Generally, this interface is implemented through a service bus or similar device, such as Azure Service Bus, using themes and subscriptions.
Communication styles between microservices
One the type of communication between microservices to be used is chosen, there is a wide range of protocols and different options: this is what is known as microservice communication styles.
For example, if you are going to use asynchronous communication method – therefore, based on the request-response method –, you have the possibility of using different approaches of communication styles. In this case, the HTTP protocol and the REST protocol are the most widespread.
But there are other options, such as the Docker host or the microservices cluster, to establish communication services internally, or the binary format communication mechanisms, such as WCG over TCP. Another option is to use message-based asynchronous communication mechanisms such as AMQP.
Some developers choose to opt for a non-standard binary format for internal communication between microservices. This option is possible both for the Docker host and for the microservices cluster (for example, Docker orchestrators), and also for client-owned applications that communicate with the microservices.
Normally, microservice-based applications use systems that combine different communication styles. The most common type is a single-receiver communication via an asynchronous protocol, with HTTP/HTTPS being one of the most used. Complementarily, microservices commonly use messaging protocols in the asynchronous communication between microservices.
Reach out to us, we are certain we can guide you with the best solution!