A load balancer distributes incoming network traffic across multiple servers to ensure no single server bears too much demand. This improves application responsiveness, availability, and reliability.
When a client request reaches a load balancer, it evaluates the request and forwards it to an appropriate server based on its algorithm. The server processes the request and sends the response back through the load balancer to the client.
This process happens in milliseconds. For example, if you visit a website hosted on a cloud platform like AWS, your request might go through an application load balancer that distributes it to one of hundreds of web servers.
| Type | Use Case | Protocol |
|---|---|---|
| Application Load Balancer | Web applications, HTTP/HTTPS traffic | Layer 7 (HTTP) |
| Network Load Balancer | High-performance applications, TCP/UDP traffic | Layer 4 (TCP/UDP) |
| Global Server Load Balancer | Multi-region deployments, disaster recovery | DNS-based |
Load balancers use different algorithms to determine which server should handle each request. Common algorithms include:
Load balancers continuously monitor the health of servers using health checks. If a server fails or becomes unresponsive, the load balancer stops sending traffic to it and reroutes traffic to healthy servers. This automatic failover ensures high availability.
Load balancing provides several key benefits:
For example, during peak shopping seasons, e-commerce websites use load balancers to handle sudden spikes in traffic without crashing.
Many people confuse load balancers with reverse proxies. While both forward client requests to backend servers, load balancers distribute traffic across multiple servers, whereas reverse proxies typically serve as a single entry point to a group of servers.
Another misconception is that load balancers only work for web traffic. In reality, they can balance various types of traffic, including database queries, API calls, and even gaming sessions.