Tuesday, November 19, 2024
Google search engine
HomeLanguagesJavaSpring Cloud – Server Side Load Balancer

Spring Cloud – Server Side Load Balancer

Spring Cloud is a collection of projects like load balancing, service discovery, circuit breakers, routing, micro-proxy, etc will be given by Spring Cloud. So spring Cloud basically provides some of the common tools and techniques and projects to quickly develop some common patterns of the microservices.

What is Load Balancer in Spring Cloud?

Taking about the general definition, Load Balancer is a network device that sits between a set of backend servers and clients. It distributes the incoming traffic to multiple servers to reduce the load. Load Balancers typically use various algorithms, such as round-robin to determine which server to send incoming traffic to. Please refer to the below image and observe how the above problem is fixed by Load Balancer.

So, in Spring, if you want to use Load Balancer then Spring Cloud provides us with some already developed ready-made Load Balancer. By using this you don’t need to write any Load Balancer or create your own, you can just use the tool very easily by importing some dependencies and writing minimal code.

Type of Load Balancer

There are two ways to load balance the request

  1. Client-Side Load Balancer
  2. Server-Side Load Balancer

So in this article, we are going to discuss what are the Server Side Load Balancers available in Spring Cloud.

Server-Side Load Balancer

If you are keeping the load balancer on the server side and giving the load balancing responsibility to the server, then it’s called Server-Side Load Balancing. In Server-side load balancing, the instances of the service are deployed on multiple servers and then a load balancer is placed in front of them. Firstly, all the incoming requests come to the load balancer which acts as a middle component. Then it determines to which server a particular request must be directed based on some algorithm. Let’s understand this with an example in the context of Spring Boot Microservices.

Imagine we have two microservices called address-service and employee-service. Please refer to the below image. This is your address-service instance 1 and this is running on port number 8081. Another instance of the address app we have deployed inside a different server. So address-service instance 2 is running on port number 8081. Similarly, we have only one instance of employee-service and this is running on port number 8080. So basically we have started two instances of our address server or address service and one instance of employee-service.

 

Right now in our employee-service we are making calls to the address-service. So if there is no load balancer every time whenever we are making a call the call is going to port number 8081. But let’s say lots of loads are coming to the address-service instance 2 (Port – 8082), so we have scaled up our application and created another instance of our address-service (address-service instance 1). So what we want is sometimes the load should go to the address-service instance 1 and sometimes the load should go to the address-service instance 2. So this way the load will be distrusted between these 2 instances. So the goal is any request is coming we should equally maintain the load. And this thing could happen by introducing a Load Balancer.

Point to Remember:

  • Server-Side Load Balancer Provided by Spring Cloud: Spring Cloud Gateway, Netflix Zuul

Advantages of Server-Side Load Balancing

  • The first advantage of Server-Side Load Balancing is the configuration is very simple. We only need to know the load-balancer address.
  • Clients are not conscious of the backend servers.

Disadvantages of Server-Side Load Balancing

  • The first disadvantage of Server-Side Load Balancing is the single point of failure as if it fails, then all the instances of the microservice become unavailable as only the load balancer has the list of servers.
  • Since each microservice will have a particular load balancer, the complexity of the system rises and it is hard to manage.
  • The cost is high to implement Server-Side Load Balancing in comparison to Client-Side Load Balancing.
  • And network latency also rises in Server-Side Load Balancing.
Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments