CLOUD CONCEPT

Load Balancing

Load balancing distributes incoming requests or network connections across multiple targets to improve availability and use capacity efficiently.

Cloud Concepts Hub →

What is Load Balancing

A load balancer provides an entry point that directs traffic to a pool of application instances, containers, or other endpoints according to routing rules and health information. It helps applications handle demand and continue serving users when individual targets fail, but it does not create additional application capacity by itself.

Load balancing separates the address clients use to reach an application from the individual resources that process its traffic. Instead of connecting directly to one server, clients connect to a load-balancing endpoint. The load balancer selects an eligible target using a configured algorithm or routing policy. Depending on the implementation, it can distribute individual requests, connections, or network flows. Its main purposes are to spread demand, improve resource utilization, and support application availability.

For example, an online store might run its application on several virtual machines across two availability zones. A load balancer directs customer traffic across those machines. If one machine fails its health checks, the load balancer normally stops selecting it for new traffic while other healthy machines continue serving requests. This reduces dependence on any single application instance. However, an existing connection to a failed machine can still break, and users may need to retry their requests.

Load balancers operate at different protocol layers. A transport-layer load balancer commonly routes TCP or UDP flows using connection information without interpreting application URLs. An application-layer load balancer understands protocols such as HTTP and can route requests according to the hostname, URL path, or other request attributes. For example, requests for /images can go to an image service while requests for /checkout go to a separate application pool. The correct choice depends on protocol support, routing requirements, connection behavior, and performance needs.

In cloud environments, load balancing commonly works with automatic scaling. A scaling system adds or removes application resources, while the load balancer distributes traffic among the registered, eligible targets. These are separate responsibilities: a load balancer does not launch more servers merely because existing servers are overloaded. Similarly, adding servers will not help unless they become reachable, pass appropriate health checks, and are registered to receive traffic.

Health checks must reflect whether a target can serve useful requests. A successful network connection may prove that a process is listening without proving that its application is working. Conversely, an unnecessarily broad health check can remove every target when a shared dependency experiences a brief problem. Failure handling also varies by implementation; some load balancers can route to unhealthy targets when every target is unhealthy. Health checks therefore support resilience but do not guarantee uninterrupted service.

Application design affects how effectively traffic can be distributed. Keeping session data in a shared store allows successive requests to reach different instances. Session affinity, sometimes called sticky sessions, can keep a user associated with one target, but may produce uneven utilization and does not preserve that target's local state after failure. Connection draining allows in-flight work time to finish before a target is removed during maintenance or scaling.

Load balancing adds cost, configuration, and another network component to troubleshoot. TLS termination can centralize certificate handling, but encryption from the load balancer to backend targets requires separate configuration. Balanced traffic also does not necessarily mean equal traffic: target weights, long-lived connections, and differences in request duration can produce unequal workloads. Monitor application latency, errors, connection counts, and target utilization rather than assuming equal request counts indicate success.

For foundational certification questions, associate load balancers with distributing incoming traffic and improving availability across multiple targets. Distinguish that purpose from automatic scaling, which changes capacity, and DNS resolution, which maps names to endpoints. A highly available design also needs redundant load-balancing infrastructure, sufficient healthy backend capacity, and resilient application dependencies; placing one server behind a load balancer does not make the entire application highly available.

Key aspects of Load Balancing

Effective load balancing combines traffic distribution, meaningful health checks, appropriate protocol handling, and coordination with resilient application capacity.

Traffic distribution

Traffic is assigned to eligible targets using algorithms such as round robin, connection-based selection, or weighted distribution. The goal is effective capacity use, not necessarily identical request counts on every target.

Health-aware routing

Health checks help identify targets that should not receive new traffic. Configure checks to represent application readiness and understand the implementation's behavior when no targets are healthy.

Protocol-aware selection

Transport-layer balancing distributes connections or flows, while application-layer balancing can make decisions using HTTP attributes such as hostnames and paths. Choose the layer based on application protocols and required routing behavior.

Availability across failure boundaries

Distributing targets across availability zones reduces dependence on one location. The load-balancing tier and backend dependencies must also be resilient for the application to remain available.

Integration with scaling

Load balancing spreads traffic across existing capacity, while automatic scaling changes that capacity. Registration, health checks, and graceful deregistration connect these two mechanisms.

Session and connection handling

Session affinity and connection draining influence how traffic behaves during normal operation and target removal. Shared session storage generally makes it easier to distribute requests and tolerate individual target failures.

Cloud services for Load Balancing

Amazon Route 53 can resolve an application name to an Elastic Load Balancing endpoint. The load balancer then distributes incoming requests or connections across registered targets. Amazon EC2 Auto Scaling adjusts virtual-machine capacity and coordinates target registration, while Amazon ECS integrates load balancing with container task lifecycles. Together, these services connect a stable client-facing name to changing application resources. DNS routing, traffic distribution, and capacity scaling remain distinct functions, and each requires appropriate health checks, network access, and failure-handling configuration.

Amazon EC2 Auto Scaling image Amazon EC2 Auto Scaling

Amazon EC2 Auto Scaling adjusts the number of EC2 instances and can register or deregister them with an attached load balancer. Scaling supplies capacity; load balancing directs traffic to the instances that are ready to serve it.

Open Amazon EC2 Auto Scaling →
Amazon Route 53 image Amazon Route 53

Amazon Route 53 can direct a domain name to a load balancer and use DNS routing policies to steer clients among endpoints. DNS-based distribution complements request or connection balancing, but cached DNS answers mean it does not make an independent routing decision for every application request.

Open Amazon Route 53 →