Micro Services communication Micro Services communication spring spring

Micro Services communication


You are onto the right way. Exposing a service with a REST architecture is powerful and simple. Each microservice exposes some functionalities that can be invoked by others microservices. You can do this with SpingMVC and the annotation @RestController. To invoke REST API you may use the Spring class RestTemplate.

You probably also need a gateway that redirects requests to the right service. I suggest you to try the Netflix Cloud Stack:

  • Zuul. This is the entry point of your application. Every request is issued to it. It should orchestrate the whole ecosystem.
  • Eureka Client - Eureka Server. All of your microservices should somehow tell somebody that they are up and running and can accept requests. So you can use Eureka Server to accept registrations from your services and mark your microservices as Clients.
  • Ribbon. Another one important thing is the loadbalancing of the requests. With Ribbon you can do this easily.

If you are using Spring Boot you can setup this architecture quickly with some annotations.

You can find here a simple example: https://cloud.spring.io/spring-cloud-netflix/


I don't really like direct API calls from service A to service B or vice versa for two reasons. Firstly it create dependency between service A and B. Secondly it could easily create a spaghetti sort of messy relationships as the number of services grows. What I would like to see is a pub / sub pattern, e.g. service A publishes a message to the transportation layer (RabbitMQ is not a bad choice) and move on. The subscription and business logic to interpret the message are encapsulated nicely in service B. By doing that, service B does not need to know anything about service A at all and yet they can talk to each other nicely.


There is no standard for communication or transport mechanisms for microservices. In general, microservices communicate with each other using widely adopted lightweight protocols, such as HTTP and REST, or messaging protocols, such as JMS or AMQP. In specific cases, one might choose more optimized communication protocols, such as Thrift, ZeroMQ, Protocol Buffers, or Avro.

Communication between microservices can be designed either in synchronous (request-response) or asynchronous (fire and forget) styles. Both approaches have their own merits and constraints. It is not possible to develop a system with just one approach. A combination of both approaches is required based on the use cases.

You should choose ones which suits best to your projects depending on your use cases and requirements.