We have two microservices: Employee-Service and Department-Service. When the Employee-Service is called, it retrieves employee information along with the department details associated with that employee. Internally, the Employee-Service communicates with the Department-Service to fetch the required department information for the respective employee.
To demonstrate load balancing, we will create two instances of the Department-Service.
- First Scenario: Both instances of the Department-Service will be running simultaneously. We will make requests to the Employee-Service using Postman and observe how the load is distributed between the two instances.
- Second Scenario: We will stop one instance of the Department-Service and make requests again using Postman. This will help us verify how the load balancer redirects traffic to the remaining active instance.
Used Technologies and Tools-
- Spring boot 3.3.4
- Spring Cloud Netflix Eureka Server
- IntelliJ IDEA
- MySQL
- Postman
Step 1: Set the application name in the configuration file (Application.properties). Remember this name is registered in Service Registry(Netflix Eureka Server).
![]() |
![]() |
Step 3: Employee-Service Call Department-Service to get department info of a employee.
![]() |
Up to Step 3, everything is done. In the below steps, we just test the load balancing. We will create an extra .jar file of Department-Service and run that one also, so we will get two instances of Department-Service. One is from IDE, and another is from the .jar file. Then, we will test load balancing by stopping one instance.
![]() |
Step 5: Check in /target folder that .jar file created or not.
![]() |
Step 6: Run the above .jar file in either IDE's Terminal or CMD in a different port (8093). Here we have run by CMD.
- Open CMD : win + R (type cmd)
- Go to the microservice directory (just before /target folder)
- cd RMN\Projects\Java_Spring_Boot\Micro-services\Payroll\dept_service_py
- D: [This to channge the directory]
- Finally run in 8093 port using below command
- java -jar -Dserver.port=8093 target/dept_service_py-0.0.1-SNAPSHOT.jar
![]() |
Step 7: Open Netflix Eureka server in the browser and the two instances created for Department-Service. Netflix Eureka server will automatically load balance between two instance of Department-Service. If any instance is down it will go for running instance.
![]() |
![]() |
Successfully return the response with department info. Here is department info coming from Department-Service. |
0 Comments