Server vs Client-side load balancing
This article discusses the key features of server-side and client-side load balancing. At the end of the post, there is a link to a spring-boot based POC on how to set up client-side load balancing using Netflix Ribbon, Feign client and Netflix Eureka libraries.
Q. Why do we need load balancing?
Ans. When using scalable microservices, a client needs to be able to route its requests to one of the multiple backend server instances. Multiple requests from the client(s) need to be load-balanced across the backend servers so that no single backend server gets overloaded.
There are 2 approaches for load balancing:
1. Server-side load-balancing: All backend server instances are registered with a central load balancer. A client requests this load balancer which then routes the request to one of the server instances using various algorithms like round-robin. AWS ELB is a prime example of server-side load-balancing that registers multiple EC2 instances launched in its auto-scaling group and then routes the client requests to one of the EC2 instances.
Advantages of server-side load balancing:
- Simple client configuration: only need to know the load-balancer address.
- Clients can be untrusted: all traffic goes through the load-balancer where it can be looked at.
- Clients are not aware of the backend servers.
2. Client-side load-balancing: The load balancing decision resides with the client itself. The client can take the help of a naming server (eg. Netflix Eureka) to get the list of registered backend server instances, and then route the request to one of these backend instances using client-side load balancing libraries like Netflix Ribbon.
Advantages of client-side load balancing:
- No more single point of failure as in the case of the traditional load balancer approach.
- Reduced cost as the need for server-side load balancer goes away.
- Less network latency as the client can directly invoke the backend servers removing an extra hop for the load balancer.
Click here for POC on setting up client-side load balancing using spring-boot microservices. Take note of important annotations used:
- @EnableEurekaServer -> With the main class of the Eureka server
- @EnableDiscoveryClient -> With the main class of Eureka server clients.
- @FeignClient along with @RibbonClient -> For the proxy interface pointing to the service app and its method.
.
3 å¹´aws cloud provides scalability and high availability by using ECS and ELB load balancers then why we need spring cloud concept like eureka server?and ribbon load balancers ? could you please explain and clear me? when we have to choose spring cloud eureka server and ribbon load balancer in aws ?
Results-oriented and highly skilled software engineer with 17 years of experience in Data Structures , Java, Microservices, Spring Boot, Docker, and more.
3 å¹´Hi, I have few queries. Pls resolve. How the benefits of client side load balancing even fit 1 percent? If client side load balancer goes down, then is it not a single point failure? Less Network Latency : The request goes to client side load balancer and then goes to specific server instance. Same way in server side load balancing, request goes to load balancer and then goes to specific server instance. How the n/w latency is less? Even in Client side load balancing, it has to make extra call to[e.g. Netflix Eureka] find addresses of all backend servers.
Live to learn and make the future reality.
3 å¹´Thanks for this post. I've only heard of server-side load balancing before. How does client-side load balancing prevent servers from overloading? You can't know the servers' loads in advance on the client, so how do you prevent all clients randomly sending requests to the same one server while other servers would be available?
Software Engineer at Priceline | Ex NSE
3 å¹´A client side load balancing can completely remove dependency of server side load balancer like ELB? Or both of them are must as client side load balancing can be used by microservices while communicating other microservice?