Contents
What are the ways to communicate between microservices?
There are two basic messaging patterns that microservices can use to communicate with other microservices.
- Synchronous communication. In this pattern, a service calls an API that another service exposes, using a protocol such as HTTP or gRPC.
- Asynchronous message passing.
If two microservices are supposed to use code together, the code can be transferred into a shared library (see Figure 7.4). The code is removed from the microservice and packaged in a way that enables it to be used by the other microservices. A shared library means that the microservices become dependent on each other.
How do you share common data between microservices?
Another way to share data is to share a data store. Services can share a relational database, NoSQL store, or another data storage service. One or more services publish the data to the database, and other services consume it when required. Most databases and data stores provide data via request/response mechanisms.
Should microservices use shared libraries?
As Sam Newman describes in building microservices, it’s important not to introduce unnecessary coupling between microservices. Shared libraries should provide cross-cutting infrastructure rather than service domain logic or product functionality.
What are client libraries in microservices?
They are custom client libraries which have the only purpose – to make interactions (request/response) with the only microservice. For example, there is some microservice-b which offers some microservice-b-client.
What is the difference between a microservice and a library?
Both libraries and microservices provide a way of providing a functionality behind a versioned interface. In the case of a microservice the versioning needs to be supported by the service on its external interfaces (eg versioned messages or apis), in the case of a library the version is applied by the version of the package.
How to implement event based communication between microservices?
Implementing event-based communication between microservices (integration events) 1 Using message brokers and services buses for production systems. As noted in the architecture section, you can choose from multiple messaging technologies for implementing your abstract event bus. 2 Integration events. 3 The event bus. 4 Additional resources
How is synchronous communication used in microservices architecture?
Not only that, in some articles, you might read that synchronous communication is an anti-pattern, especially when there are many services in a calling route. The other frequent comparison we might read about compares microservices to SOA architecture. In SOA, the most common communication protocol is SOAP.
You do not want to do that for the same reasons that you do not want to share a common domain model across multiple microservices: microservices must be completely autonomous. There are only a few kinds of libraries you should share across microservices.