Skip to content
What is a Load Balancer — Simple Explanation with Examples

What is a Load Balancer — Simple Explanation with Examples

DodaTech Updated Jun 20, 2026 5 min read

A load balancer distributes incoming network traffic across multiple servers to ensure reliability, availability, and optimal resource utilization, preventing any single server from becoming overwhelmed.

In this guide, you’ll learn how load balancers work, the different types and algorithms, and how to configure one for your own applications. Load balancers are essential for any system that needs high availability and scalability.

Why Load Balancers Exist — The Problem They Solve

A single web server has limits:

  • Capacity: A typical server handles 10,000–50,000 concurrent connections before slowing down.
  • Reliability: If the server crashes, the entire application goes down.
  • Maintenance: Updating software requires downtime — no server to serve requests.

Adding more servers solves these problems, but creates a new one: which server should handle each request? A load balancer sits in front of multiple servers and decides where each request goes.

The Single Point of Failure Problem

Without a load balancer:

User ─────► Web Server (single) ─────► Database
            └── If this fails, the entire app is down ──

With a load balancer:

            ┌────► Web Server 1 ─────┐
User ─────► Load Balancer ────► Web Server 2 ────► Database
            └────► Web Server 3 ─────┘
            (If one fails, traffic goes to the others)

The Analogy — Airline Check-In Counters

Imagine an airport with a single check-in counter. All passengers queue at that one counter. If the counter closes (server crash), no one checks in. If a rush of passengers arrives, the queue grows endlessly.

Now imagine 20 check-in counters with a queue manager (load balancer) who directs each passenger to the shortest queue. If one counter closes, the manager sends passengers to the other 19. If all counters are busy, passengers wait, but the system keeps working.

The load balancer is that queue manager — it ensures no counter is overloaded and every passenger gets served.

Layer 4 vs Layer 7 Load Balancing

FeatureLayer 4 (Transport)Layer 7 (Application)
OSI LayerTransport (TCP/UDP)Application (HTTP/HTTPS)
Routing decisionIP + portURL, headers, cookies
PerformanceVery fast (less processing)Slightly slower (parses packets)
FeaturesBasic distributionContent-based routing, SSL termination
ExampleAWS NLB, HAProxy (TCP mode)AWS ALB, NGINX, HAProxy (HTTP mode)

Layer 4 Example

Directs all TCP traffic on port 80 to a pool of servers — no inspection of HTTP content.

Layer 7 Example

Routes based on URL path:

/api/*   → API servers (backend pool)
/images/* → Image servers (optimized pool)
/*        → Web servers (general pool)

Load Balancing Algorithms

AlgorithmHow It WorksBest For
Round RobinRequests go to each server in rotationEqual-capacity servers, similar workloads
Least ConnectionsSends to server with fewest active connectionsVariable-length requests (e.g., API calls)
IP HashHash of client IP determines serverSession persistence (sticky sessions)
Weighted Round RobinServers with higher weight get more trafficHeterogeneous server capacity
RandomRandomly selects a serverSimple distribution, testing

Health Checks

Load balancers periodically check if servers are healthy:

# NGINX — health check upstream servers
upstream backend {
    server 10.0.0.1:3000 max_fails=3 fail_timeout=30s;
    server 10.0.0.2:3000 max_fails=3 fail_timeout=30s;
    server 10.0.0.3:3000 backup;  # Only used if others fail
}

location / {
    proxy_pass http://backend;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
}

If a server fails 3 health checks in 30 seconds, it’s removed from the pool until it recovers.

Example NGINX Load Balancer Config

http {
    upstream app_servers {
        least_conn;  # Least connections algorithm
        server 10.0.0.1:3000 weight=3;
        server 10.0.0.2:3000 weight=2;
        server 10.0.0.3:3000;
    }

    server {
        listen 80;
        server_name example.com;

        location / {
            proxy_pass http://app_servers;
            proxy_set_header X-Real-IP $remote_addr;
        }
    }
}

Expected behavior: Requests arrive at port 80, NGINX distributes them using least-connections algorithm, and servers with higher weight get proportionally more traffic.

SSL Termination

Load balancers can handle TLS decryption, offloading the CPU-intensive work from backend servers:

server {
    listen 443 ssl;
    server_name example.com;

    ssl_certificate /etc/ssl/certs/example.com.pem;
    ssl_certificate_key /etc/ssl/private/example.com.key;

    location / {
        proxy_pass http://app_servers;  # Backend receives plain HTTP
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Backend servers communicate over HTTP internally, while the load balancer handles HTTPS externally. This reduces CPU load on app servers.

Cloud Load Balancers

AWSGCPAzureDescription
ALBHTTP(S) LBApp GatewayLayer 7 — HTTP/HTTPS routing
NLBTCP/UDP LBLoad BalancerLayer 4 — TCP/UDP, high throughput
CLBLegacy (Classic) load balancer
GWLBLayer 3/4 for third-party appliances

AWS ALB Example

# Create a target group
aws elbv2 create-target-group \
    --name my-targets \
    --protocol HTTP \
    --port 80 \
    --vpc-id vpc-12345678

# Register targets
aws elbv2 register-targets \
    --target-group-arn arn:aws:elasticloadbalancing:... \
    --targets Id=i-0abcdef1234567890 Id=i-0abcdef1234567891

# Create ALB
aws elbv2 create-load-balancer \
    --name my-alb \
    --subnets subnet-12345678 subnet-87654321 \
    --security-groups sg-12345678

Common Use Cases

1. Web application scaling

Distribute HTTP traffic across multiple web servers. Add or remove servers based on traffic without downtime.

2. Database read replicas

Route read queries to multiple read replicas while sending writes to the primary database.

3. Microservices routing

Layer 7 load balancers route API requests to the appropriate microservice based on URL path or headers.

4. Global load balancing

Route users to the nearest data center using geographic DNS routing plus local load balancers.

5. Blue-green deployment

Route traffic to the “blue” environment while the “green” environment is tested. Switch instantly when ready.

FAQ

What is the difference between a load balancer and a reverse proxy?

A reverse proxy typically handles one server (caching, SSL, compression). A load balancer distributes traffic across multiple servers. NGINX and HAProxy can do both.

Can a load balancer be a single point of failure?

Yes, unless it’s deployed in a highly available pair (active-passive with keepalived or active-active with DNS round-robin).

How does session persistence work?

Sticky sessions (session affinity) send all requests from the same client to the same server using cookies, IP hash, or URL rewriting.

What is a health check endpoint?

A simple endpoint like /health that returns 200 OK. The load balancer pings this periodically to determine if the server is healthy.

How many servers can a load balancer handle?

Modern load balancers can manage thousands of servers. AWS ALB handles hundreds of thousands of concurrent connections across hundreds of targets.

Related Terms

Reverse Proxy, DNS, CDN, Caching, High Availability

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro