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
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.
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.
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.