Microservice Communication in a Distributed System

This Java and microservices tutorial shows how one microservice communicates with another dependent microservice service via the service registry and Eureka Server. 

Let's see the sequence of how one microservice calls another microservice using Eureka server.

Need help how to start Eureka Follow this guide?


Registering the Service: 
Each microservice should be registered into the service registry with a unique name {service-id}, so it can be identified. 

Please note that it is an important step, as one of the main benefits of microservices is autoscaling; we can’t rely on the hostname/IP address, so a unique name is important in a distributed environment.

Fetching the Registry: 

Before calling the downstream/dependent service, the caller service fetches the registry from Eureka server. The registry contains all the active services registered into the service registry.

Finding the Downstream Service: 
Now, using the unique service Id, the caller service gets the instance of the downstream service.

Resolving Underlying IP Address: 

Please note the Iniques service id act as a Key in service registry but network does not know about it network expects Hostname to call the desired Rest Endpoint on the dependent service like (localhost:8080/employee/{id} or employee.cognizant,com/2 etc). 

So it is required to resolve the actual hostname of the dependent service Eureka API provides a method for that we just invoke that method to get the Ip address, For a distributed system it is the public IP of Load balancer.

Call the Rest Endpoint: 

After resolving the IP address using Spring Resttemplate, we call the actual Rest endpoint and get the data.


For more updates keep an eye on this website!

Chandra Sekhar

A Blogger and Author! This post was written and edited by me, a technologist. I started this site to share my inspirations, work, and free materials, which I hope others may find useful as well. Man with a creative streak who enjoys experimenting with various web design strategies.

Previous Post Next Post

Microservice Communication in a Distributed System