Load Balancer
Task: Keep serving requests when a server dies
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
A client sends a request to the website
The load balancer receives it first
It decides which server should handle the request
The chosen server processes and responds
The load balancer keeps repeating this for every new request
Common algorithms
| Algorithm | Description |
|---|---|
| Round Robin | Assigns requests in rotation (Server 1 → 2 → 3 → repeat). |
| Least Connections | Sends new requests to the server with the fewest active connections. |
| IP Hash | Uses 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: