Load balancing and health checks
One address, several backends
A load balancer accepts traffic at a stable frontend and selects a backend, such as a VM running a web application. A listener defines the protocol and port on which traffic arrives. A backend pool (also called a target group in some products) identifies the destinations. A health check periodically tests whether a destination appears able to serve traffic.
Imagine a bookstore at shop.example.com with three copies of its application: A, B and C. Clients connect to a frontend on HTTPS port 443. The balancer can route requests to healthy copies instead of requiring customers to know each VM address. This is a fictional architecture, not a deployment recipe. The public frontend does not imply public backend addresses.
Choose a transport or application-level balancer
A layer 4 (L4) balancer makes forwarding decisions using transport information such as addresses and TCP or UDP ports. A layer 7 (L7) HTTP balancer can inspect HTTP information, such as host and path, after any necessary TLS termination. For example, /catalog may go to a catalog pool and /checkout to a checkout pool. An L4 balancer cannot choose by encrypted HTTP path merely by observing TCP headers.
An L4 flow is not necessarily a single request: many requests may travel on one connection. A balancer may hash connection fields, use round robin, choose a backend based on outstanding work, or maintain affinity (keeping a client with a backend). Actual choices depend on the product. Affinity can cause uneven load and is not durable session storage.
A TLS-terminating proxy presents a certificate to the client and may start a separate encrypted connection to the backend. Protect both legs according to the trust model from Chapter 18. Verify certificate identity, protocol compatibility and backend access; do not assume that TLS at the frontend protects the backend leg.
Follow a small traffic trace
Use an offline teaching rule: for each request select the next healthy backend in cyclic order A, B, C; skip unhealthy backends. Assume no sticky sessions, identical request costs and instant visibility of health state. B is unhealthy throughout. Six independent requests go to A, C, A, C, A, C. Each healthy backend receives three requests. If each can handle 100 requests per second, the two healthy backends can offer 200 requests per second, provided no other dependency is slower.
If demand is 250 requests per second, the modeled capacity shortfall is 50 requests per second. It is not necessarily 50 errors: real requests may queue, time out, be rejected or trigger backpressure. When every backend is unhealthy, this fixture selects none. Real services can use different all-unhealthy policies. In particular AWS Application Load Balancer documents fail-open behavior when all registered targets in enabled zones are unhealthy. Do not treat the toy algorithm as a cloud service guarantee.
Health, readiness and connection draining
A TCP probe can establish a connection without proving that an HTTP application works. An HTTP probe can request a small readiness endpoint and examine the response. Set a meaningful timeout, interval and success/failure threshold; health status lags actual conditions. A readiness test should be cheap and reflect whether that backend can accept new work. A separate end-to-end synthetic checkout can detect business failures missed by a simple readiness response. Avoid making every backend fail readiness because of an optional shared dependency.
When removing a backend for maintenance, first stop assigning new work and allow existing work to finish within a bounded drain period. If a toy request has 8 seconds left and the drain budget is 10 seconds, it can finish; if it has 12 seconds left, graceful completion is not guaranteed. Coordinate the balancer's deregistration behavior with application shutdown and timeouts. Existing TCP sessions, streaming requests and long-lived connections need special attention. Never assume a probe failure or removal instantly terminates every existing connection.
Compare cloud service families
AWS Elastic Load Balancing includes Application Load Balancer for HTTP-aware routing and Network Load Balancer for transport-level use cases. Azure Standard Load Balancer serves transport-level scenarios; Azure Application Gateway handles regional HTTP delivery. Google Cloud distinguishes Application Load Balancers from Network Load Balancers, including proxy and passthrough variants. These are service families, not exact equivalents.
Choose internal or external reachability, regional or global scope, protocols, TLS termination, private backend connectivity, health probes and failure behavior independently. Global frontend reach does not imply replicated backend data or automatic disaster recovery. Verify product mode, region, supported protocols, health check source rules and SKU before any real design. Health check routing and automatic VM repair are separate decisions: a bad backend can be excluded from new traffic without being replaced.
Troubleshoot before scaling
For a fictional 503 response, check frontend reachability, listener and TLS, routing rule, target registration, health probe configuration, backend network rules, and application logs in that order. Compare actual request errors and latency against health probe results. A healthy /ready response is not proof that /checkout works. Do not solve failed checks by opening all backend ports or disabling certificate validation.
Practice: route six requests with one unhealthy backend, then explain how you would verify the real product's all-unhealthy policy. Continue to bounded autoscaling to learn when adding copies helps and when a shared service prevents improvement.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Load balancing and health checks — knowledge check
Choose the best answer for each offline scenario.
Which information enables routing `/checkout` to a separate backend pool?
In the toy cycle A, B, C with B unhealthy, which destinations receive the first four requests?
A TCP health probe succeeds. What does that establish?
Why check the actual all-unhealthy policy?
What is connection draining intended to do during planned removal?