100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

What is Load Balancing?

Learn load balancing — round-robin, least-connections, health checks and Layer 4 vs 7 — with examples and system design interview questions answered.

easyQ1 of 224 in System Design Est. time: 5 minsLast updated:
Open Code Lab

Expected Interview Answer

Load balancing is the practice of distributing incoming network traffic across multiple backend servers so no single server is overwhelmed, improving availability, throughput and responsiveness.

A load balancer sits in front of a pool of servers and routes each request using an algorithm such as round-robin (rotate through servers in turn), least-connections (send to the server with the fewest active connections), or IP-hash (map a client consistently to one server). It typically runs health checks and stops routing to servers that fail them, so the system keeps serving even when instances go down. Load balancers operate at Layer 4 (transport, by IP and port) or Layer 7 (application, by HTTP path or headers).

  • Spreads traffic so no single server is a bottleneck
  • Removes unhealthy servers via health checks (high availability)
  • Enables horizontal scaling behind one endpoint

AI Mentor Explanation

A load balancer is like a captain rotating the bowling attack instead of making one bowler send down every over. As deliveries (requests) keep coming, the captain assigns each over to whichever bowler is freshest — round-robin rotation, or least-connections when picking the least-tired bowler. If a bowler is injured (fails a health check), the captain simply stops giving them overs and the game continues. That even, health-aware distribution is exactly what a load balancer does for servers.

Step-by-Step Explanation

  1. Step 1

    Receive the request

    Clients hit one endpoint (the load balancer), not individual servers.

  2. Step 2

    Pick a backend

    An algorithm chooses a server: round-robin, least-connections or IP-hash.

  3. Step 3

    Run health checks

    Servers failing checks are removed from the pool and get no traffic.

  4. Step 4

    Forward and return

    The request goes to the chosen server and the response flows back to the client.

What Interviewer Expects

  • Definition as distributing traffic across multiple servers
  • Named algorithms: round-robin, least-connections, IP-hash
  • Health checks and removing unhealthy instances
  • Layer 4 vs Layer 7 load balancing awareness

Common Mistakes

  • Confusing load balancing with horizontal scaling itself
  • Not naming any distribution algorithm
  • Forgetting health checks and failover
  • Ignoring the load balancer as a single point of failure (needs redundancy)

Best Answer (HR Friendly)

Load balancing spreads incoming traffic across several servers so no single one gets overwhelmed. It routes each request to an available server and skips any that are unhealthy, which keeps the service fast and available even under heavy load.

Code Example

Nginx round-robin and least-connections upstream
upstream app_servers {
    # round-robin is the default
    server 10.0.0.1:8080;
    server 10.0.0.2:8080;
    server 10.0.0.3:8080;
}

upstream app_least_conn {
    least_conn;                 # send to the fewest active connections
    server 10.0.0.1:8080;
    server 10.0.0.2:8080;
}

server {
    listen 80;
    location / {
        proxy_pass http://app_servers;
    }
}

Follow-up Questions

  • What is the difference between Layer 4 and Layer 7 load balancing?
  • How does least-connections differ from round-robin?
  • How do you prevent the load balancer from being a single point of failure?
  • What is sticky session (session affinity) and when do you need it?

MCQ Practice

1. Which algorithm routes each request to the server with the fewest active connections?

Least-connections picks the backend currently handling the fewest connections, balancing uneven request durations.

2. What do load balancer health checks accomplish?

Health checks detect unhealthy servers and remove them from the pool so traffic only goes to working instances.

3. A Layer 7 load balancer can route based on?

Layer 7 operates at the application layer, so it can route by HTTP attributes like path, host or headers.

Flash Cards

What is load balancing?Distributing incoming traffic across multiple servers so none is overwhelmed.

Round-robin?Rotates requests through servers in turn, one after another.

Least-connections?Routes to the server with the fewest active connections.

Purpose of health checks?Detect failed servers and remove them from the routing pool.

1 / 4

Continue Learning