Navigate back to the homepage

Load Balancing

Nancy Chauhan
September 29th, 2021 · 2 min read

We encounter load balancers every day. Even when you are reading this medium article, your requests flow through multiple load balancers, before this content reaches your browser.

Load balancing is one of the most important and basic concepts we encounter every single day. It is the process of distributing incoming requests across multiple servers/processes/machines at the backend.

Why do we need load balancing?

Usually, when we make an application, clients will route their request to one of the backend servers, but as soon as traffic grows, that server will reach its limits. To overcome this, we can spin up another server to share the traffic. But how do we let the clients know to connect to the new machine?

Load balancing is the technique used for discovery and decision-making for this routing. There are two ways of achieving this — server-side load balancing or client-side load balancing.

Single application server gets overloaded with request

Server-side Load Balancing:

There is a middle layer, a load balancer that forwards the incoming requests to different servers to remove that complexity. All backend servers get registered with a load balancer which then routes to one of the server instances using various algorithms. AWS ELB, Nginx, Envoy are some examples of server-side load balancers.

Server-side load balancing

Advantages

  • No need for client-side changes.
  • Easy to make changes to load balancing algorithms and backend servers.

Client-Side Load Balancing:

In client-side load balancing, the client handles the load balancing. Let’s take an abstract look at how this can be achieved. To perform load balancing on the client-side -

  • The client should be aware of all available web servers
  • A library on the client-side to implement a load balancing algorithm

The client routes the requests to one of the servers using client-side load balancing libraries like Ribbon. Client-side load balancing is also used for service discovery. Suppose Service A (client-side) wants to access Service B (server-side). Service B has three instances and register all at the discovery server (X). Service A has enabled the Ribbon client which allows doing the client-side load balancing. It fetches the available Service B instances from the discovery server and redirects the traffic from the client-side and constantly listens for any changes.

Here I have implemented client-side load balancing using consul service discovery: https://github.com/Nancy-Chauhan/consul-service-discovery

Client-side

Advantages

  • No need for additional infrastructure.

Benefits of Loadbalancing

Reference: https://www.nginx.com/resources/glossary/load-balancing/
Load balancers are the foundation of modern cloud-native applications. The concept of load balancing and the ability to be dynamically configured has created innovations such as service mesh.

More articles from Nancy Chauhan

Thank you, July

This month has been very special to me. I got a chance to reconnect with people and took a break from work to recharge myself. People think overworking themselves will get more jobs done. But on the contrary, the harder you work without taking a break, the less productive and creative you are.

July 31st, 2021 · 2 min read

Enforcing Coding Best Practices using CI

High-performing teams usually ship faster, better, and often! Organizations irrespective of their level, focusing on stability and continuous delivery, will deploy frequently. Hundreds of continuous integration build run for every organization on a typical day. It indicates how CI has become an integral part of our development process. Hence to ensure that we are shipping quality code, we should integrate code quality checking in our CI.

May 30th, 2021 · 3 min read
© 2018–2021 Nancy Chauhan
Link to $https://twitter.com/_nancychauhanLink to $https://github.com/Nancy-ChauhanLink to $https://www.linkedin.com/in/nancy-chauhan/Link to $https://www.instagram.com/_nancychauhan/Link to $https://medium.com/@_nancychauhan