Load Balancing & Proxies
Distribute traffic cleanly across healthy backends while terminating TLS and enforcing routing rules.
In plain words
A load balancer is like a host at a busy restaurant who seats guests at whichever table is free, so no single waiter is overwhelmed.
Think of it like…
A restaurant host who sees which tables are open or busy and seats incoming guests evenly instead of crowding one waiter.
Where you’ve seen it
An online store runs 20 identical web servers. A load balancer spreads incoming shoppers across them and stops sending traffic to any server that crashes.
Words you’ll hear
- Load balancer
- A component that spreads incoming requests across many servers.
- Health check
- A regular ping to see if a server is alive before sending it traffic.
- Reverse proxy
- A server that sits in front of your servers and forwards client requests to them.
- L4 vs L7
- L4 routes by IP and port only; L7 can read the request (URL, headers) to route smarter.
Visual diagram
Theory & deep dive
Forward Proxy vs. Reverse Proxy
A forward proxy sits in front of clients (e.g., a company VPN or school filter) and hides who the client is from the internet. A reverse proxy sits in front of your backend servers (e.g., NGINX, Cloudflare, AWS ALB) and hides your internal servers from clients.
Almost every production web service uses a reverse proxy/load balancer for TLS termination, compression, caching, rate limiting, and routing traffic cleanly.
Layer 4 (Transport) vs. Layer 7 (Application)
An L4 load balancer only reads IP addresses and TCP/UDP ports. It forwards raw packets at blisteringly high speed (millions of connections/sec) without reading HTTP headers.
An L7 load balancer reads the actual HTTP request - URL path (/api/search vs /api/billing), cookies, headers, and JWTs - so it can route smartly, terminate TLS, and enforce rate limits, at slightly higher CPU cost.
Choosing the right balancing algorithm
Round Robin sends requests in order (1, 2, 3, 1, 2, 3) - great when all requests cost the same. Least Connections picks whichever server currently has the fewest active requests - much better when some requests take 10 ms and others take 2 seconds.
Consistent Hashing routes by user ID or cache key so a local cache stays warm on the same node.
How it works, step by step
Step 1 of 41. Client connects to Load Balancer VIP
DNS resolves to a virtual IP (VIP) backed by redundant active-passive or active-active load balancers.
- HA Pair
- VRRP / Anycast
- TLS
- Terminated at LB
When to use it & trade-offs
What it is
A load balancer sits in front of backend servers, monitors health, terminates connections, and spreads incoming requests across healthy instances.
Why it matters: Without load balancing, you cannot scale horizontally or take a server down for deploys without dropping user requests.
When to reach for it
- Spreading load across stateless web/API servers and microservice fleets
- TLS termination, HTTP/2-to-HTTP/1.1 translation, and path-based routing
- Zero-downtime rolling deploys via health checks and connection draining
When to avoid or be careful
- Deploying a single load balancer instance with no failover pair
- Enabling sticky sessions on stateless APIs (causes uneven skew during auto-scaling)
L4 vs. L7 & Balancing Algorithms
Strengths: Minimal memory/CPU per connection; preserves low latency at millions of PPS.
Watch out: Cannot inspect URLs, headers, cookies, or retry idempotent HTTP GETs.
Strengths: Routes by path/host, strips TLS, compresses responses, retries failed GETs.
Watch out: Higher CPU/memory overhead from parsing HTTP and maintaining two TCP connections.
Strengths: Avoids piling slow requests onto a single server (unlike blind round-robin).
Watch out: Requires tracking active in-flight requests per backend.
Interview signals & numbers to know
When this topic comes up
- high throughput
- reverse proxy
- TLS termination
- zero downtime deploy
- routing by path
Benchmarks & rules of thumb
- L7 LB hop overhead
- ~0.5–2 ms
- Health check interval
- 5–10s
- Idle keep-alive timeout
- 60–300s
- Graceful drain timeout
- 30–60s
Common mistakes & follow-ups
Common interview mistakes
- Forgetting that the load balancer itself must be redundant (active-passive or Anycast pool)
- Using round-robin for WebSockets or uneven queries where least-connections prevents skew
- Not forwarding X-Forwarded-For / Traceparent headers to downstream services
Likely interviewer follow-ups
- Forward proxy vs. reverse proxy - how do their roles and placement differ?
- How do you load balance long-lived WebSocket connections?
- What is the Power of Two Choices (P2C) algorithm and why does Envoy use it?
Knowledge check
Put it into practice
Design full architectures with AI feedback
Apply Load Balancing & Proxies inside real High-Level Design prompts or review Q&A flashcards.