Skip to content

Load Balancer


Task: Keep serving requests when a server dies

ClientLoad BalancerServer 16Server 26Server 32REMOVED FROM POOL

Why we need a Load Balancer

Analogy

  • Imagine a busy restaurant with many customers.
  • Instead of one waiter serving everyone, customers are distributed among several waiters.
  • This ensures no single waiter is overloaded and everyone gets served faster.
  • That's exactly what a Load Balancer does for servers.

What is a Load Balancer?

Definition

  • A Load Balancer is a system that distributes incoming network traffic across multiple servers.
  • It ensures no single server gets overwhelmed.
  • Example: If 100 users visit a website, the load balancer divides requests among servers evenly.

Why use it?

  • Prevents server overload.
  • Improves performance and reliability.
  • Ensures high availability: if one server fails, others keep working.

How it works

  1. A client sends a request to the website

  2. The load balancer receives it first

  3. It decides which server should handle the request

  4. The chosen server processes and responds

  5. The load balancer keeps repeating this for every new request


Common algorithms

AlgorithmDescription
Round RobinAssigns requests in rotation (Server 1 → 2 → 3 → repeat).
Least ConnectionsSends new requests to the server with the fewest active connections.
IP HashUses client IP to decide which server handles the request.

Advantages

  • Better scalability: easily add more servers.
  • Fault tolerance: if one server fails, traffic reroutes automatically.
  • Improved user experience: faster response times.

Real-world example

  • Websites like Amazon or YouTube use load balancers to handle millions of requests per second.
  • Without them, a single server would crash under heavy traffic.

🎯 Quick recap

Key takeaway

  • Load Balancer = traffic manager for servers.
  • Distributes requests evenly.
  • Improves speed, reliability, and uptime.

A visual diagram showing how a load balancer distributes requests among multiple servers:

WITHOUT A BALANCERClientOne serverWITH A BALANCERClientBalancer