๐Ÿ”ฅ 0
โญ 0
Lesson 1 of 5 15 min +150 XP

Why Load Balancing Matters

It's Black Friday. Your e-commerce site is getting 50,000 requests per second. A single server can handle maybe 2,000. Without load balancing, you're about to lose millions in sales.

Load balancing is the traffic cop of the internet - distributing incoming requests across multiple servers so no single machine gets overwhelmed.

The Single Server Problem

WITHOUT LOAD BALANCING

50,000 requests/sec
        โ”‚
        โ–ผ
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   โ”‚ Server  โ”‚  โ† Overwhelmed!
   โ”‚  (1)    โ”‚     Crashes at 2K req/s
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
        โ”‚
        โ–ผ
     ๐Ÿ’ฅ DOWN

WITH LOAD BALANCING

50,000 requests/sec
        โ”‚
        โ–ผ
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   โ”‚   Load   โ”‚
   โ”‚ Balancer โ”‚
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
    โ”‚    โ”‚    โ”‚
    โ–ผ    โ–ผ    โ–ผ
  โ”Œโ”€โ”€โ” โ”Œโ”€โ”€โ” โ”Œโ”€โ”€โ”  โ† 25 servers
  โ”‚S1โ”‚ โ”‚S2โ”‚ โ”‚..โ”‚     2K each = 50K total
  โ””โ”€โ”€โ”˜ โ””โ”€โ”€โ”˜ โ””โ”€โ”€โ”˜

What Load Balancers Do

โš–๏ธ
Distribute Traffic

Spread requests across multiple servers

๐Ÿ’“
Health Monitoring

Remove failing servers from the pool

๐Ÿ”’
SSL Termination

Handle encryption at the edge

๐Ÿ“
Session Affinity

Route users to the same server

The Load Balancing Flow

Client Request โ†’ DNS โ†’ Load Balancer โ†’ Backend Server โ†’ Response

Step by step:
1. User visits myshop.com
2. DNS resolves to load balancer IP (e.g., 203.0.113.10)
3. Request hits load balancer
4. Load balancer picks a healthy backend server
5. Request forwarded to chosen server
6. Server processes and responds
7. Response flows back through load balancer to client

Benefits of Load Balancing

1. High Availability

No Single Point of Failure

If one server crashes, the load balancer routes traffic to healthy servers. Users never see downtime. You can even do rolling deployments - update servers one at a time while others handle traffic.

2. Horizontal Scalability

Traffic growing? Just add more servers.

Before:  LB โ†’ [S1] [S2] [S3]           = 6,000 req/s capacity
After:   LB โ†’ [S1] [S2] [S3] [S4] [S5] = 10,000 req/s capacity

No code changes. No downtime. Just provision and add.

3. Flexibility

Scenario Without LB With LB
Server maintenance Downtime required Drain and maintain transparently
Traffic spike Server crashes Auto-scale and distribute
Server failure Complete outage Automatic failover
Deploy new version Blue-green is complex Rolling deploy or canary

Real-World: Netflix's Load Balancing

Netflix at Scale

Netflix uses a multi-tier load balancing approach. At the edge, they use their own CDN (Open Connect) with edge servers worldwide. For internal services, they use Eureka for service discovery and Ribbon for client-side load balancing. A single popular show launch can generate millions of concurrent streams - all seamlessly distributed.

Types of Load Balancers

Hardware Load Balancers

Physical appliances (F5, Citrix). Expensive but extremely fast. Common in enterprise data centers.

Software Load Balancers

NGINX, HAProxy, Envoy. Run on commodity hardware. Flexible and cost-effective.

Cloud Load Balancers

AWS ALB/NLB, GCP Load Balancer, Azure LB. Managed, auto-scaling, pay-per-use.

Where Load Balancers Sit

                    Internet
                        โ”‚
                        โ–ผ
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ”‚  DNS (Route 53) โ”‚
              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                       โ”‚
                       โ–ผ
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ”‚ Global LB (CDN) โ”‚  โ† Cloudflare, AWS CloudFront
              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                       โ”‚
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ”‚              โ”‚              โ”‚
        โ–ผ              โ–ผ              โ–ผ
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   โ”‚Region A โ”‚   โ”‚Region B โ”‚   โ”‚Region C โ”‚
   โ”‚   LB    โ”‚   โ”‚   LB    โ”‚   โ”‚   LB    โ”‚  โ† Regional LBs
   โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜
        โ”‚              โ”‚              โ”‚
    โ”Œโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”
    โ”‚Serversโ”‚     โ”‚Serversโ”‚     โ”‚Serversโ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Common Load Balancer Features

  • Health Checks - Continuously monitor backend servers and remove unhealthy ones
  • SSL/TLS Termination - Decrypt HTTPS at the load balancer, send HTTP to backends
  • Session Persistence - Sticky sessions to keep users on the same server
  • Connection Draining - Gracefully remove servers without dropping active connections
  • Rate Limiting - Protect backends from traffic spikes or DDoS attacks

Key Takeaways

  • Load balancers distribute traffic - No single server bears all the load
  • Enable horizontal scaling - Add more servers to handle more traffic
  • Improve availability - Automatic failover when servers go down
  • Foundation for modern architecture - Essential for any high-traffic application

Next up: Load Balancing Algorithms - Round Robin, Least Connections, IP Hash, and more.

๐Ÿง  Quick Quiz

Test your understanding of this lesson.

1

What is the primary purpose of a load balancer?

2

What happens if you have multiple servers but no load balancer?

3

Which scenario most benefits from load balancing?