⬅ Previous Topic
Horizontal vs Vertical ScalingNext Topic ⮕
CDN (Content Delivery Network)⬅ Previous Topic
Horizontal vs Vertical ScalingNext Topic ⮕
CDN (Content Delivery Network)A load balancer is a critical component in system design that distributes incoming traffic across multiple servers to ensure no single server becomes a bottleneck. It acts as the “traffic controller” for your infrastructure, improving responsiveness, reliability, and availability.
Imagine a website receiving thousands of requests every second. If all requests go to one server, it may crash or become unresponsive due to overload. Load balancers help by distributing this load evenly across multiple servers.
There are several types of load balancers based on how they distribute traffic:
Let’s say you’re running an online shopping platform like Amazon. During a festival sale, millions of users visit the site simultaneously.
If all requests go to a single web server, it will get overwhelmed. To handle this load, a load balancer is placed in front of multiple web servers.
When a user makes a request (like opening a product page), the load balancer:
Answer: No. The user interacts only with the load balancer’s endpoint. The internal distribution is completely abstracted.
Load balancers use algorithms to decide how to distribute requests. Here are some common ones:
Consider a user logging into a banking application. Their session must stay on the same server to maintain session state. This is called a "sticky session."
A load balancer with IP hashing or cookie-based routing ensures the user is routed to the same server throughout their session.
Answer: Yes. If one server gets more sticky sessions than others, it might become overloaded. This is why sticky sessions should be used carefully.
Load balancers constantly check the health of servers by sending periodic health check requests. If a server fails the check, it’s temporarily removed from the rotation.
Suppose your system has 3 web servers behind a load balancer. If one server crashes:
This ensures that users don’t experience downtime or failed responses.
A common question is: If all traffic goes through the load balancer, isn’t it a single point of failure?
Yes, unless we make the load balancer itself redundant. This is often done by:
Answer: Yes. You can have global load balancers for routing between regions and local load balancers for routing within a data center.
In a microservices architecture, each service may have multiple instances. A load balancer helps route requests to the right instance of a service.
Tools like Envoy and Istio act as service mesh load balancers inside Kubernetes clusters.
Load balancers are foundational to building scalable, resilient systems. They:
Next, we will explore Content Delivery Networks (CDNs) and how they complement load balancers by improving global content delivery speed and efficiency.
⬅ Previous Topic
Horizontal vs Vertical ScalingNext Topic ⮕
CDN (Content Delivery Network)You can support this website with a contribution of your choice.
When making a contribution, mention your name, and programguru.org in the message. Your name shall be displayed in the sponsors list.