Key Network Components
Modern web applications depend on a small set of critical networking components that provide scalability, fault tolerance, and global performance. This lesson covers the foundational pieces of distributed-systems networking: load balancers, API gateways, proxies, and CDNs.
Load Balancers
Load balancers distribute incoming traffic across multiple backend servers, providing horizontal scalability, fault tolerance, and reduced response times. They give clients a single entry point and automatically reroute traffic away from unhealthy servers.
Types by layer
Algorithms
How each algorithm picks
| Algorithm | Selection rule | Where it goes wrong |
|---|---|---|
| Round-robin | Cycle server 1, server 2, server 3, then back to 1 | Fair only when servers have similar capacity and requests cost about the same |
| Weighted round-robin | A weight of 3 receives three times the requests of a weight of 1 | The weight is static. A large server that is already saturated still receives its share |
| Hash of client IP or session id | The same key maps to the same server | A hot key pins one server. Adding or removing a server remaps keys unless the hash is consistent |
| Least connections | Choose the server with the fewest active connections | Right when request duration varies. Few connections can still mean a slow server |
| Least response time | Fewest connections, biased by recent response speed | The latency sample lags. Traffic keeps arriving at a server that just got worse |
| Least loaded | CPU and memory, not connection count | The metric lags a burst. The sample you route on is already stale |
Sticky sessions
Some apps need a user to stay on the same backend (because session state lives there). Two approaches:
- Cookie-based affinity β Layer 7 only. LB inserts a cookie on first request; routes by cookie thereafter.
- Source IP affinity β Layer 4 or 7. Routes based on client IP. Breaks behind NATs and corporate proxies.
The better long-term answer is to externalize session state (Redis, JWT) so any backend can serve any request.
Production essentials
API Gateways
While load balancers distribute requests across identical servers, API gateways manage API complexity in distributed architectures. They make intelligent routing decisions based on request characteristics β /users/profile to user services, /orders/history to order services β and handle cross-cutting concerns.
What gateways add
Choosing one
- Hybrid (Kong, Ambassador, Istio Gateway) β combine API management with high-performance load balancing. Self-hosted; flexible; more operational complexity.
- Pure managed gateway (AWS API Gateway, GCP Endpoints, Azure API Management) β fully managed, integrate well with their cloud, throughput limits in extreme scenarios.
- Pure load balancers (NLB, HAProxy, F5) β best raw performance; require additional tooling for API management.
For most multi-tenant SaaS platforms, a managed cloud gateway in front of an internal service mesh is the pragmatic combination.
Proxies
A proxy is any service that sits between clients and servers and forwards requests. Two main flavors:
The line between reverse proxy and load balancer is blurry β most reverse proxies (NGINX, HAProxy) can do load balancing, and most load balancers proxy. The distinction is mostly historical.
Debugging proxies such as Charles and Burp, and a hosted filter such as Zscaler, are forward proxies too. To the origin, every user is the proxy. Without a second instance that hop is a single point of failure.
A reverse proxy can also compress responses, hide backend addresses, and write one access log for the whole front door. Every byte passes through it, so an undersized proxy caps the application behind it.
AWS splits the managed balancer into ALB for Layer 7 HTTP, NLB for Layer 4 at high packet rates, and Classic Load Balancer, which new designs should leave. Kubernetes uses a Service for balance inside the cluster and an Ingress controller for external HTTP, often provisioning the cloud load balancer from the manifest.
CDN (Content Delivery Networks)
A CDN is a globally distributed network of servers that cache content close to users. Foundational for any application with a global user base.
Caching strategies
- Cache-Control headers drive everything.
max-age,s-maxage,stale-while-revalidate,stale-if-error. - Cache keys β be explicit. Include relevant headers (Accept, Accept-Language, Authorization). Donβt include irrelevant ones (User-Agent unless you really need to vary by it).
- Purge / invalidation β push-based or TTL-based. Most production systems combine both: short TTL as a safety net, explicit purge on writes.
For SaaS apps, the practical answer is: serve all static assets through a CDN, cache aggressively, and use short cache lifetimes (or signed URLs) for tenant-specific assets.
A Tokyo client fetching an image from a New York origin adds hundreds of milliseconds of fiber. An edge in Japan serves the object or pulls it from a regional cache, typically a 50 to 80 percent latency cut on media-heavy pages. Static files can stay cached a long time; personalized responses get a short lifetime or none. The CDN bill grows with traffic, and the origin still has to absorb a burst of simultaneous misses.
Auxiliary Infrastructure
A few other components that round out the networking story:
Putting It Together
A typical SaaS request flow:
[ User ]
β
β DNS lookup (Route 53)
βΌ
[ CDN edge (Cloudflare) ]
β TLS termination, edge cache, WAF
βΌ
[ Cloud Load Balancer (ALB) ]
β Layer 7 routing, health checks
βΌ
[ API Gateway (Kong) ]
β Auth, rate limiting, request transformation
βΌ
[ Service Mesh (Istio) ]
β mTLS, retries, circuit breaker
βΌ
[ Microservice ]
Each component has a job. Each job exists because moving it to the next-most-natural location either costs more or gives less control.
Recap
- Load balancers spread traffic across identical backends. Pick Layer 4 for raw performance, Layer 7 for content-aware routing.
- API gateways add the layer above: routing by service, auth, rate limiting, transformation.
- CDNs serve content from the edge β fundamental for global apps; doubles as DDoS absorption.
- WAFs, DNS providers, and service meshes round out the picture.
- The whole stack is a series of filters, each at the level where itβs cheapest and most precise.