Load Balancing and Proxies

Almost nothing on the modern internet talks directly to the server that answers it. In between sit proxies and load balancers — the traffic directors that spread load across many servers, terminate TLS, cache responses, and shield your backends. Understanding this layer is understanding how a single domain name serves millions of users from hundreds of machines.

The previous posts got a secure HTTP request from client to server. But “the server” is usually a fiction — behind one address are many servers, with load balancers and proxies directing traffic among them. This infrastructure layer is where scalability, resilience, and much operational control live. This post covers reverse vs forward proxies, load balancing and its algorithms, the crucial L4-vs-L7 distinction, and CDNs — the pieces that turn “a server” into “a system that scales.”

Proxies: intermediaries with a purpose

A proxy is an intermediary that sits between client and server, forwarding requests and responses. The direction it faces defines its type, and confusing the two is common:

The reverse proxy is the one central to backend architecture, because it’s the single entry point in front of your servers and the natural home for a whole set of jobs:

A reverse proxy is thus the control point in front of your system — one place to terminate TLS, spread load, cache, and enforce policy. Common reverse proxies (nginx, Envoy, HAProxy, cloud load balancers) are foundational infrastructure.

Load balancing: one address, many servers

Load balancing is the reverse proxy’s headline job: distribute incoming requests across a pool of backend servers so no single one is overwhelmed. It’s what makes horizontal scaling possible — add more servers behind the balancer to handle more load — and it delivers two things at once:

The balancer decides which backend gets each request using a load-balancing algorithm:

Health checks underpin all of it: the balancer continuously checks backends and routes only to healthy ones, which is how failures are handled automatically. Choosing an algorithm depends on your traffic; round robin and least-connections cover most cases.

L4 vs L7: the crucial distinction

The most important concept in this post is at which layer a load balancer operates, because it determines what it can do — and it ties directly back to the network stack from post one:

L4: routes on IP:port, blind to content        → fast, simple, connection-level
L7: routes on URL/headers/cookies, HTTP-aware   → powerful, content-based, request-level

The practical guidance: L7 for HTTP applications (you almost always want content-aware routing, TLS termination, and the reverse-proxy features), L4 when you need raw speed or are balancing non-HTTP traffic where you don’t need to inspect content. Most web-application load balancing is L7; L4 shines for high-throughput, protocol-agnostic, or lowest-latency cases. Knowing which layer your balancer works at tells you what routing decisions it can (and can’t) make.

Session affinity: a caveat

One recurring wrinkle: session affinity (sticky sessions) — configuring the balancer to send a given user consistently to the same backend (via cookie or IP hash). This is sometimes needed when a backend holds per-user state in memory (a session). But it’s usually a design smell: it undermines even load distribution and resilience (if that server dies, the user’s state is lost), and it complicates scaling. The better pattern, from the distributed-systems and sessions discussions, is to make backends stateless — store session state externally (a shared cache/database) so any backend can serve any request, and the balancer can distribute freely. Reach for sticky sessions only when you must; prefer stateless backends that don’t need them.

CDNs: load balancing across the globe

Extending these ideas geographically gives the CDN (Content Delivery Network) — a globally distributed network of proxy/cache servers that serve users from a location near them:

A CDN is essentially reverse-proxy + caching + load balancing applied globally, routing each user to a nearby edge — the geographic realization of this whole layer. For any service with a global audience or significant static content, a CDN is standard infrastructure.

The infrastructure that makes “a server” scale

Load balancers, proxies, and CDNs are the layer that turns a single domain into a scalable, resilient system: a reverse proxy fronts your servers (terminating TLS, caching, filtering), a load balancer spreads traffic across many backends and routes around failures (L7 for content-aware HTTP, L4 for raw speed), stateless backends let it distribute freely, and a CDN extends it all globally for latency and scale. This is where the network knowledge from the whole series meets real architecture. The final post brings it down to earth: the networking concerns backend engineers handle in day-to-day code.

Key takeaways

Further reading

Sources & References

Load balancing and proxies