What Is a Load Balancer?

Load Balancing: The Key to Scalable Infrastructure

Load balancing is a technique that distributes incoming network traffic across multiple servers to prevent any single server from becoming overwhelmed.

How Load Balancers Work

A load balancer acts as an intermediary between clients (users) and servers, distributing incoming network traffic across multiple servers. Its primary function is to ensure that no single server becomes overwhelmed with requests, preventing potential crashes or downtime. By spreading the workload evenly, load balancers help maintain high availability and responsiveness in your application.

Types of Load Balancing

There are several types of load balancing techniques, each with its own strengths and weaknesses:

  • Round-Robin: Each incoming request is sent to the next available server in a predetermined sequence.
  • Least Connection: New requests are directed to the server with the fewest active connections.
  • IP Hash: Requests from a client are always routed to the same server, based on their IP address.

Benefits of Load Balancing

Implementing load balancing can bring numerous benefits to your infrastructure:

  • Improved scalability: Easily handle increased traffic by adding more servers behind the load balancer.
  • Enhanced availability: Ensure high uptime and minimize downtime due to server crashes or maintenance.
  • Better performance: Reduce response times and improve overall application responsiveness.

Comparison of Load Balancing Techniques

The choice of load balancing technique depends on your specific use case. Here's a comparison of the most popular techniques:

Technique Description
Round-Robin Each incoming request is sent to the next available server in a predetermined sequence.
Least Connection New requests are directed to the server with the fewest active connections.
IP Hash Requests from a client are always routed to the same server, based on their IP address.

When to Use Load Balancing

Load balancing is essential for applications that experience sudden spikes in traffic or require high availability and scalability. Consider implementing load balancing if you have:

  • High-traffic applications: E-commerce sites, social media platforms, or other high-demand services.
  • Distributed systems: Microservices architecture or cloud-based infrastructure.
  • Business continuity: Ensure uptime and availability during peak hours or critical periods.

Health Checks and High Availability

A load balancer continually runs health checks against its backend servers — periodic requests to a known endpoint — and stops sending traffic to any server that fails, routing around outages automatically. Production deployments usually run the load balancer itself in a redundant pair (active-passive or active-active) so the balancer is not a single point of failure.

Load balancers come in three forms: dedicated hardware appliances, software such as Nginx or HAProxy running on commodity servers, and managed cloud services like AWS Elastic Load Balancing or Google Cloud Load Balancing that scale automatically with demand.

Load balancers pair with other infrastructure — see what a proxy server is and Kubernetes, which load-balances containerized services automatically.

Frequently Asked Questions

A reverse proxy forwards client requests to one or more backend servers and can add caching, TLS termination, and security filtering. A load balancer's specific job is to spread traffic across multiple servers to maximize availability and throughput. Many reverse proxies, such as Nginx and HAProxy, can also act as load balancers, so the roles often overlap in a single piece of software.

Round-robin sends each request to the next server in turn; least connections routes to the server with the fewest active connections; IP hash maps a client's IP address to a specific server to preserve session affinity; and weighted variants of these send more traffic to more powerful servers.

Layer 4 load balancing routes traffic using network information such as IP address and TCP or UDP port, without inspecting the payload. Layer 7 load balancing operates at the application layer and can route based on the contents of a request, such as the URL path, HTTP headers, or cookies, enabling content-based routing at the cost of more processing per request.