Module 13: Load Balancing & Proxies
As applications scale, single servers can’t handle the load. Load balancers distribute traffic across multiple servers, while proxies act as intermediaries for various purposes. This module covers both in depth. Think of a load balancer like a host at a busy restaurant. When customers (requests) arrive, the host does not send everyone to the same waiter (server). They distribute customers across all available waiters based on who is least busy, who can handle the largest parties, or simply in rotation. Without the host, all customers would crowd around one waiter while the others stood idle.Estimated Time: 3-4 hours
Difficulty: Intermediate
Prerequisites: Modules 4-6 (Network fundamentals)
Difficulty: Intermediate
Prerequisites: Modules 4-6 (Network fundamentals)
13.1 Why Load Balancing?
The Single Server Problem
The Solution: Distribute Load
13.2 Load Balancing Algorithms
1. Round Robin
Requests are distributed sequentially.2. Weighted Round Robin
Servers with higher capacity get more requests.3. Least Connections
Send to server with fewest active connections.4. Least Response Time
Send to server with fastest response time + fewest connections.5. IP Hash
Same client IP always goes to same server.6. Least Bandwidth
Route to server currently serving least traffic (Mbps).Algorithm Comparison
13.3 Layer 4 vs Layer 7 Load Balancing
Layer 4 (Transport Layer)
Operates on TCP/UDP level. Sees IP addresses and ports only. It does not terminate the TCP connection or inspect the payload — it simply forwards packets based on IP and port information.Layer 7 (Application Layer)
Operates on HTTP/HTTPS level. The load balancer terminates the client’s TCP connection, reads the full HTTP request, makes a routing decision, and then opens a new TCP connection to the backend server./api/* to API servers, /static/* to CDN), SSL termination, caching, compression, header injection (X-Forwarded-For), A/B testing
Cons: More processing overhead, higher latency (must parse HTTP), only works for HTTP/HTTPS
Analogy: A Layer 7 LB is like a hotel concierge who reads your request, understands what you need, and directs you to the right department — they actually open and read the letter.
Which should you use? Default to Layer 7 for web applications — the routing flexibility and SSL termination are worth the small overhead. Use Layer 4 for non-HTTP protocols (databases, game servers, custom TCP services) or when you need maximum throughput and do not need content-based routing.
When to Use Which
13.4 Proxy Types
Forward Proxy
Sits between clients and the internet. Clients know about it.- Content filtering (block certain sites)
- Caching (reduce bandwidth)
- Anonymity (hide client IPs)
- Access control (authentication)
Reverse Proxy
Sits between internet and servers. Clients don’t know about it.- Load balancing
- SSL termination
- Caching static content
- DDoS protection
- Compression
- URL rewriting
13.5 SSL/TLS Termination
The Problem
Encryption is CPU-intensive. Every server doing SSL:The Solution: SSL Termination
Load balancer handles all SSL:- Servers freed from SSL overhead
- Single place to manage certificates
- Easier SSL certificate renewal
SSL Passthrough vs Termination vs Re-encryption
13.6 Session Persistence (Sticky Sessions)
Some applications need the same user to always reach the same server.Why Needed?
Sticky Session Methods
1. Cookie-based:Better Alternative: Shared Session Store
13.7 Health Checks
Load balancers must know which servers are healthy.Passive Health Checks
Monitor real traffic for failures:Active Health Checks
Periodically probe servers:Health Check Configuration
Health Check Endpoints
Your application should expose health endpoints. Think of these like a doctor’s checkup — each endpoint tests something different:13.8 Common Load Balancer Products
Cloud Load Balancers
Software Load Balancers
Hardware Load Balancers
13.9 Load Balancing Patterns
Blue-Green Deployment
Canary Deployment
A/B Testing
13.10 Reverse Proxy Use Cases
URL Rewriting
Path-Based Routing
Header-Based Routing
Caching
13.11 Real-World Architecture
Typical Web Application
Microservices Architecture
13.12 Key Takeaways
L4 vs L7
L4 is fast but simple. L7 is smart but more overhead.
Algorithm Matters
Choose based on your traffic pattern and server capabilities.
Health Checks
Always configure proper health checks to avoid routing to dead servers.
SSL Termination
Offload SSL to load balancers to simplify certificate management.
Next Module
Module 14: Network Troubleshooting
Master the tools and techniques for diagnosing network issues.