1.

How do microservices communicate with each other?

Answer»

Microservices are OFTEN integrated using a simple protocol like REST over HTTP. Other communication protocols can also be used for INTEGRATION like AMQP, JMS, Kafka, etc.

The communication protocol can be broadly DIVIDED into two categories- synchronous communication and asynchronous communication.

  • Synchronous Communication

RestTemplate, WebClient, FeignClient can be used for synchronous communication between two microservices. Ideally, we should minimize the number of synchronous calls between microservices because networks are brittle and they INTRODUCE latency. Ribbon - a client-side load balancer can be used for better utilization of resource on the top of RestTemplate. Hystrix circuit breaker can be used to handle partial failures gracefully without a cascading effect on the entire ecosystem. DISTRIBUTED commits should be avoided at any cost, instead, we shall opt for eventual consistency using asynchronous communication.

  • Asynchronous Communication

In this type of communication, the client does not wait for a response, instead, it just sends the message to the message broker. AMQP (like RabbitMQ) or Kafka can be used for asynchronous communication across microservices to achieve eventual consistency.



Discussion

No Comment Found