# Load Balancing and Proxies

> Learn how traffic is spread across instances, the difference between L4 and L7 balancing, and what forward and reverse proxies do. Free notes, key concepts,...

Canonical: https://www.internhack.in/roadmaps/tracks/devops/load-balancing-proxies
Last updated: 2026-11-28

Learn how traffic is spread across instances, the difference between L4 and L7 balancing, and what forward and reverse proxies do.

Intermediate · about 5 hours · difficulty 3/5

Learn first: [HTTP and HTTPS](https://www.internhack.in/roadmaps/tracks/devops/http-https)

Load balancers make services scalable and highly available. Almost every production request passes through at least one proxy, so their behaviour shapes latency, errors and failover.

### Proxies

- A **forward proxy** acts for clients (corporate egress, caching).
- A **reverse proxy** sits in front of servers: TLS termination, routing, compression, caching, rate limiting. Nginx, HAProxy, Envoy and cloud load balancers are all reverse proxies.

### Load balancing

- **Layer 4** balances TCP/UDP connections by IP and port; fast and protocol-agnostic (AWS NLB).
- **Layer 7** understands HTTP and can route by host, path or header (AWS ALB, ingress controllers).
- **Algorithms**: round robin, least connections, weighted, consistent hashing.
- **Health checks** remove bad instances; **connection draining** lets in-flight requests finish during deploys.
- **Session affinity** (sticky sessions) is sometimes needed but hurts even spreading.

### Beyond one region

DNS-based and anycast global load balancing, and CDNs as edge proxies.

### Pitfalls

Health checks that only test "process is up" rather than "can serve traffic", lost client IPs (use `X-Forwarded-For` or the PROXY protocol), and mismatched idle timeouts between the balancer and the app causing sporadic 502s.

**Good enough to move on:** you can choose between L4 and L7 for a use case, configure meaningful health checks, and explain how draining enables zero-downtime deploys.

## Key concepts

- **Forward vs reverse proxy**
- **L4 vs L7 load balancing**
- **Balancing algorithms**
- **Health checks and draining**
- **Sticky sessions**
- **Client IP preservation**
- **Global load balancing and anycast**

## Mini project

Run three copies of a small app that returns its hostname, put a reverse proxy in front with round robin and a health check, then kill one instance and show traffic keeps flowing.

## Check yourself

Why can a load balancer idle timeout that is longer than the app's keep-alive timeout cause random 502 errors?

## Free resources

- [What is load balancing?](https://www.cloudflare.com/learning/performance/what-is-load-balancing/) (Cloudflare)
- [Elastic Load Balancing docs](https://docs.aws.amazon.com/elasticloadbalancing/) (AWS)

Previous: [TLS and Certificates](https://www.internhack.in/roadmaps/tracks/devops/tls-certificates) · Next: [Firewalls, Security Groups and NAT](https://www.internhack.in/roadmaps/tracks/devops/firewalls-nat)

## More in Networking You Will Actually Debug

- [How the Internet Works: TCP/IP and the OSI Model](https://www.internhack.in/roadmaps/tracks/devops/internet-tcpip)
- [DNS in Practice](https://www.internhack.in/roadmaps/tracks/devops/dns)
- [HTTP and HTTPS](https://www.internhack.in/roadmaps/tracks/devops/http-https)
- [TLS and Certificates](https://www.internhack.in/roadmaps/tracks/devops/tls-certificates)
- [Load Balancing and Proxies](https://www.internhack.in/roadmaps/tracks/devops/load-balancing-proxies)
- [Firewalls, Security Groups and NAT](https://www.internhack.in/roadmaps/tracks/devops/firewalls-nat)
- [SSH, Bastions and VPNs](https://www.internhack.in/roadmaps/tracks/devops/ssh-vpn)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [DevOps Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/devops)
