The major difference between service-oriented architecture and microservices architecture is the fact that, in a service-oriented architecture, the application consists of different services, each providing the functionality to work on one of the business domains of an organization. These services communicate with each other through the use of the enterprise service bus, which routes the messages from one service to another while also providing a common format for message exchange.
In the case of microservices, the application will consist of a number of small microservices, where each microservice is responsible for providing only a single functionality that may not map to a complete domain of an organization and may just be a subset of larger problem domain. These microservices communicate with each other through the use of APIs exposed by the individual microservices or through the use of stateless message routers that allow the delivery of messages from one service to another.
To ensure that a microservice-based application has a high uptime, we can make use of the following techniques:
- Not using a single storage for all of the microservices
- Running multiple instances of the same microservice behind the load balancer
- Using API gateways to provide graceful degradation in a service where the client still receives a response when a critical service has failed
The use of service-level agreements—or SLAs—provides a number of guarantees, such as the following:
- A guarantee about the API stability of a service
- A guarantee about the uptime of a service
- A guarantee of the expected response times of a service
- A guarantee of the request rate limitation implemented by a service
The API gateways can communicate directly with the service registry through the use of the SDK provided by the service registry or through the use of the APIs exposed by the service registry. This allows the API gateway to automatically fetch the correct location for a given service from the service registry.
Asynchronous communication inside microservices can be implemented through the use of stateless message brokers. To implement asynchronous communication, some microservices act as producers and send a message to the message-broker queue. Then, other microservices may consume that message, process it, and send a response back to the microservice that sent the message. The response is then processed by the callback that was set by the requesting microservice. This is how the asynchronous communication between the microservices is established.