Load Balancing In The Right Way

Load Balancing In The Right Way

Have you ever wondered how industry leaders in technology like Google, Zomato, and Swiggy can handle a multitude of concurrent requests? Let's say I developed an application and has been a hit. As users are growing, I need to figure out how to scale, optimize and secure the application all in a fast and reliable manner while keeping costs down and users happy. That’s where load balancing jumps in.

What is Load Balancing?

Load balancing refers to efficiently distributing incoming network traffic across a group of backend servers, also called server farms or server pools. The technique aims to reduce response time, increase throughput, and in general speed things up for each end user.

Load balancing is achieved and managed with a tool or application that is called a load balancer. The fundamental function of a load balancer, whether it be hardware or software, is to distribute network traffic across the many servers in the server pool to avoid overloading. A load balancer acts as the “traffic cop” sitting in front of your servers and routing users’ requests across all servers capable of fulfilling those requests in a manner that maximizes speed and capacity utilization and ensures no server is overloaded with the users’ requests, which might lead to poor performance.

The requests are broken up based on a set of predefined metrics, such as by geographical location, or by the number of concurrent site visitors. Users from a certain region, such as "people in India," may be routed to a server nearby, whereas "Europe" may be sent to a different server nearby. A load balancer lessens the stress on individual servers and keeps the application server from becoming a single point of failure, increasing the availability and responsiveness of the application as a whole.

Redundant Load Balancers – A load balancer may potentially become a single point of failure. To avoid a single point of failure we can deploy more than one load balancer on several physical machines in the same cluster. If the main load balancer goes down then the secondary load balancer takes over.

Thus, a load balancer performs the following functions:

Distribute requests or network load efficiently across multiple servers

Ensure high availability and reliability by sending requests only to that who are capable of fulfilling those requests

Provides flexibility to add or remove servers as per the demand

Types of Load Balancing

There are three types of Load balancers – Physical, Virtual, and Cloud-based.

1. Physical – As the name suggests, this is the most traditional approach. The LB is placed right after the firewall and before the server. They are all physically present in the same data center as the application servers. The benefits that they provide are easily controlled and easy to connect. The drawbacks are that they are quite expensive, you need to buy a lot of hardware and software to control them, and they lack geographical distribution.

2. Virtual – Unlike in physical, where hardware was the major focus, there is no distinct hardware present in virtual. It runs on a virtual machine. The environment in which the load-balancing software operates is provided by the virtual machine. Because it may operate on many computer setups, it is much simpler to apply. It is affordable, and the software rather than the hardware is the main focus. The problem with choosing a virtualization platform is that updates and patches occasionally harm the system.

3. Cloud-based – This is a convenient and robust solution for larger networks. It is a fully distributed load-balancing solution that balances user traffic to multiple backends to avoid congestion, reduce latency, increase security, and reduce costs.

LB choosing the backend server!

Load balancers consider two factors before forwarding a request to a backend server. It first ensures that the server they choose responds appropriately to requests and then uses a pre-configured algorithm to select one from the set of healthy servers.

a. Health Checks: -

To ensure the load balancer forwards traffic to only healthy servers, “Health Checks” periodically attempt to connect to servers to ensure that servers are up and listening. If the server fails a health check, it is automatically removed from the pool, and requests will not be forwarded until it responds to health checks again.

b. Pre-configured Algorithms: -

The benefits of various load balancing algorithms vary, and the way you choose will depend on your needs:

1. Round Robin – Requests are distributed across the pool of servers sequentially.

2. Least Connection – The server with the fewest active connections is chosen as the destination for traffic. This approach is reasonably practical when many persistent user connections are unevenly distributed between the servers

3. Least Response Time – The server with the fewest active connections and the lowest average response time will receive the traffic.

4. Least bandwidth – Sends the traffic to the server serving the least amount of traffic measured in Mbps.

5. IP Hash – A hash of the user's IP address is calculated to determine which server receives the request.

6. Weighted Round Robin – Designed to handle servers with different processing capacities better. Each server is assigned a weight. Servers with higher weights receive new connections before those with fewer weights.

Benefits of Load Balancing

Improving network traffic management and enhancing user experience are the two main goals of load balancing. Therefore, the benefits it provides are the following:

1. Scalability – If you notice a drop or surge in your traffic, you can easily increase or decrease the number of servers to satisfy urgent requirements. They usually appear, for instance, during a promotion or holiday sales.

2. Flexibility – Load balancing enables you to switch the traffic between several servers. In this manner, you have the freedom to carry out routine maintenance tasks without interfering with the normal operations of your application.

3. Redundancy – When you can maintain your application on multiple servers, you can ensure excellent uptime. The hazards of relying on a single server might force your end users to quit. Load balancing is the key if you can’t afford downtime.

4. Efficiency – Load balancers lessen the increased load on a server and maintain smooth operations and responses, providing a better experience for end users.

5. DDoS attack protection – Distributing traffic across servers is very valuable when protecting against Distributed Denial of Service (DDoS) attacks. Load balancing helps when a particular server gets flooded with malicious traffic by a DDoS attack. The attack surface is decreased as the traffic is sent to several servers rather than just one. This way, load balancing eliminates a single point of failure, making your application impervious to such attacks.

Conclusion

Load balancing is deemed to be the most scalable technology for handling concurrent requests from modern applications. Load balancing works in tandem with platforms that make it possible to access numerous applications, to give end users a more reliable and consistent user experience. It is crucial if you want to provide reliable service with performance that scales well as the business grows.

Nowadays, cloud-based LB is used by almost all businesses as it provides the lowest possible latency, excellent uptime, flexibility, and scalability. It also helps you to cut down your costs as cloud models are based on pay-as-you-go. That’s all for now! Check out the references below for more details and a quick start with load balancing.

References:-

  1. https://cloud.google.com/load-balancing/docs/load-balancing-overview#a_closer_look_at_cloud_load_balancers

  2. https://www.cloudskillsboost.google/focuses/12007?parent=catalog

  3. https://www.cloudskillsboost.google/focuses/642?parent=catalog&search_id=22074836

  4. https://www.javatpoint.com/load-balancing-in-cloud-computing

  5. https://www.nginx.com/resources/glossary/load-balancing/

Did you find this article valuable?

Support GDG Cloud Nagpur by becoming a sponsor. Any amount is appreciated!