Traditional server side load balancer has some drawbacks. It requires an additional hop from client to load balancer and then load balancer to service. Also there is a burden to run and manage load balancer itself. Client side load balancer is the solution to overcome these problems. In this architecture there is an addition inbuilt load balancer component that resides inside client.
In this example we will see how client side load balancer works with eureka discovery server.
1. When service (discovery client) boots up it registers itself with discovery server. Multiple instances register itself with discovery server. Here spring.application.name is use to identify a particular service
2. Client application will also resister itself to discovery client to find instance for load banacer
3. Now load balancer within client can find the service with the help of service name
Please find complete codes from github repository -
Discovery server code -
Ribbon service code -
Ribbon client code -