Load Balancer in Microservices

Usha Devasi
3 min readApr 17, 2020

--

Load Balancer helps keep system resilient by maintaining the overwhelmed incoming traffic.

Let’s list out what are the takeaways from this article :

  1. Concept of Load-Balancing
  2. Need for the Load Balancer
  3. Type of Load-Balancer
  4. Load Balancer Mechanism is based on what?

What is Load Balancing (LB)?

Load balancing is a process of distributing no. of incoming requests evenly to multiple servers.

Let’s make it more clear by going through its literal meaning: Load + Balance

Compare the situation with the commonly used term “Work-Life Balance”. Why this work-life balance is needed? It is because if you make a mistake at any of the sides, then it will impact your personal as well as your professional life and you will get depressed.

Similarly, Load balancing is needed in the system also. Because, if it’s not there then there are high chances that the system will be down/crashed and unable to perform the purpose for which is it made.

Typically, the client is kept behind a load balancer. This allows distributing the load evenly so that one server doesn’t crash and take down the whole system.

We have seen how API Gateway work, that is our entry point but to be more resilience, we have to build a network having the cloned instance of API Gateway with the same data.

Note: There are few API Gateways where load balancing is inbuild and is encapsulated.

Need for Load Balancer:

I hope from the above part it got clear too why we need it but let me repeat it.

We need Load Balancers to manage the incoming requests from the client and respond to them without making any delay.

Think logically and feel the frustration, what happens when you are booking tickets for your travel but the website is down and you don’t have any option except trying again and again. That’s the moment where load balancer comes in picture to make you 😊.

Advantages of load Balancer: where are many but I want to highlight two of them:

  • Scaling and handle more users than what can be done with a single server.
  • Redundancy — if one server fails, others are available to ensure the application stays online.

If I talk about a broad category of LB than it is Hardware and software load Balancing but here we gonna consider only Software load balancing.

Types Of Load Balancer in microservices:

  • Client-side Load balancing: e.g. Ribbon (it’s a Netflix Client-side LB which uses eureka server inside it)
  • Server-side Load balancing: e.g. NGINX or AWS Load Balancer.

Question: How it is being decided by Load Balancer to use which server instance?

Answer: LB mechanism is done based on different algorithms like :

  • Round Robin (by default)
  • Hash
  • IP hashing (only for HHTP)
  • Least Time
  • Least Connections

I hope, here you got a basic understanding of LB.

--

--

Usha Devasi

Tech Lead/ Engineering Manager, Mentor, Coach, Certified Professional Scrum Master and SomeOne who is Passionate about Learning and exploring.