Lesson 3 of 4 Designing for High Availability and Resilience

Load Balancing Across Availability Zones and Recovering from Backend Failure

Elastic Load Balancing distributes traffic across healthy targets in multiple Availability Zones and stops sending traffic to targets that fail. This lesson explains the load balancer types, how cross-zone load balancing works, how health checks detect backend failure, how load balancers integrate with Auto Scaling to replace failed targets, and the settings that make recovery smooth.

Learning outcomes

After completing this lesson, you will be able to:

  • Compare Application, Network and Gateway Load Balancers and the scenarios each suits.
  • Explain cross-zone load balancing and its default behaviour for each load balancer type.
  • Explain how health checks, thresholds and fail-open behaviour detect and isolate failed targets.
  • Describe how ELB health checks in Auto Scaling, deregistration delay, slow start and automatic target weights support recovery.

Load Balancer Types

Elastic Load Balancing offers three load balancer types, each operating at a different layer. Choosing the type is usually the first decision in a scenario.

Application Load Balancer (ALB)

Operates at layer 7 for HTTP, HTTPS and gRPC. It routes requests by host name, path, headers, query strings and source IP to target groups of instances, IP addresses, Lambda functions or containers; terminates TLS with certificates from AWS Certificate Manager; supports weighted target groups, authentication with Amazon Cognito or OIDC, and AWS WAF.

Network Load Balancer (NLB)

Operates at layer 4 for TCP, UDP and TLS. It handles millions of requests per second with very low latency, preserves client source IP addresses and provides one static IP address per AZ, optionally Elastic IP addresses. It suits non-HTTP protocols, extreme performance and clients that need fixed IP addresses for firewall allow lists. It is also used to expose services through AWS PrivateLink.

Gateway Load Balancer (GWLB)

Operates at layer 3 to distribute traffic to fleets of virtual appliances, such as firewalls and intrusion detection systems, using GENEVE encapsulation, with traffic steered to it through GWLB endpoints in route tables.

ALB
Layer7 (HTTP, HTTPS, gRPC)
Routing featuresPath, host, header, weighted routing
Static IP per AZNo
Cross-zone defaultEnabled
Choose when Web applications and microservices needing content-based routing.
NLB
Layer4 (TCP, UDP, TLS)
Routing featuresPort-based
Static IP per AZYes, optionally Elastic IP
Cross-zone defaultDisabled
Choose when Non-HTTP protocols, fixed IPs, extreme throughput or PrivateLink.
GWLB
Layer3 (IP packets)
Routing featuresFlow-based to appliances
Static IP per AZNo
Cross-zone defaultDisabled
Choose when Inserting third-party network appliances.
Sort into groups

Choose the load balancer

Exam skills 3.1.4

Choose the load balancer type for each requirement.

Log in to try this activity Interactive activities are free with an account.

Availability Zones and Cross-Zone Load Balancing

A load balancer is enabled in a set of subnets, one per AZ, and creates a load balancer node in each. An ALB requires at least two AZs. DNS for the load balancer returns the nodes' addresses, and each node receives a share of client traffic. With cross-zone load balancing enabled, each node distributes requests across healthy targets in all enabled AZs; with it disabled, each node sends traffic only to targets in its own AZ.

Cross-zone load balancing matters when target counts differ between AZs. Suppose AZ a has two targets and AZ b has eight. Without cross-zone, each AZ's node receives half the traffic, so each target in AZ a receives 25% while each target in AZ b receives 6.25%. With cross-zone, each target receives 10%. For ALBs, cross-zone is always enabled at the load balancer level and can be turned off per target group; data transfer between AZs is not charged for ALB. For NLBs and GWLBs, it is disabled by default, and enabling it incurs inter-AZ data transfer charges. Disabling cross-zone isolates AZs from each other, which supports zonal shift and AZ-independent architectures, but requires balanced target counts.

The following diagram shows the traffic per target with cross-zone load balancing off and on.

Why cross-zone load balancing matters when target counts differ. AZ a has two targets and AZ b has eight, and each AZ's load balancer node receives half the traffic. Without cross-zone load balancing, each node sends traffic only to its own AZ, so each target in AZ a receives 25% and each in AZ b 6.25%. With cross-zone load balancing, each node spreads requests across all targets, so each receives 10%.
Percentages are from the two-and-eight-target example.

Health Checks and Detecting Backend Failure

Each target group performs health checks on its targets: a protocol, port and path (for HTTP), an interval, a timeout, a healthy threshold (consecutive successes before an unhealthy target is marked healthy) and an unhealthy threshold (consecutive failures before a healthy target is marked unhealthy), and for HTTP a success code matcher such as 200 or 200-299. The load balancer stops sending new requests to unhealthy targets and resumes when they pass again. With a 10-second interval and an unhealthy threshold of 2, a failed target stops receiving traffic in about 20 seconds.

The health check path should reflect the target's real ability to serve, for example an endpoint that checks local dependencies, but it should not fail because of a shared downstream dependency: if every target's health check fails when the database is slow, the load balancer marks all targets unhealthy. When all targets in a target group are unhealthy, the ALB and NLB fail open and route to all targets, on the assumption that the health check is wrong. ALB and NLB target groups can also set target group health thresholds and DNS failover thresholds, so that an AZ with too few healthy targets is removed from DNS and its traffic goes to other AZs.

Deep health checks

A health check that queries the database makes every target unhealthy at once during a database slowdown, turning a partial degradation into a full outage or a fail-open condition. Check local health in the load balancer health check and monitor dependencies separately.

True or false

Health checks and failover

Exam skills 3.3.3 · 4.3.7

Check four facts about load balancer health checks and AZ behaviour.

Log in to try this activity Interactive activities are free with an account.

Replacing Failed Targets with Auto Scaling

A load balancer only stops sending traffic to a failed target; it does not repair it. An Auto Scaling group replaces unhealthy instances, but by default it considers only EC2 status checks, so an instance whose application has crashed but whose operating system is running stays in service. Setting the group's health check type to ELB makes Auto Scaling also treat instances that fail the load balancer health check as unhealthy and replace them. The health check grace period prevents new instances from being replaced before the application has started.

Several further settings make recovery smooth. The deregistration delay (connection draining, default 300 seconds) lets in-flight requests complete before a target is removed; shorter values speed deployments for short requests. Slow start on ALB target groups ramps up the share of requests sent to a newly healthy target over a period, so caches can warm. Automatic target weights, used with the weighted random routing algorithm on ALB, detect targets with anomalous error rates (such as a host with a bad disk that still passes health checks) and reduce the traffic sent to them, which mitigates grey failures that health checks miss.

SettingWhereEffect on recovery
Health check interval and thresholdsTarget groupHow quickly failed targets stop receiving traffic
Health check type ELBAuto Scaling groupReplaces instances that fail load balancer checks
Health check grace periodAuto Scaling groupAvoids replacing instances that are still starting
Deregistration delayTarget groupLets in-flight requests finish when targets are removed
Slow startALB target groupRamps traffic to new targets gradually
Automatic target weightsALB target group with weighted randomReduces traffic to anomalous targets
DNS failover thresholdTarget group healthRemoves an unhealthy AZ from the load balancer's DNS
Worked example

Instances that Stay Broken

An application occasionally hangs because of a memory leak. The ALB marks the instance unhealthy and stops sending it traffic, but the instance remains in the Auto Scaling group for days, reducing capacity, until someone terminates it.

The Auto Scaling group uses the default EC2 health checks, which pass because the operating system is running. Changing the group's health check type to ELB, with a grace period of 300 seconds to cover start-up, makes Auto Scaling terminate and replace instances that the ALB considers unhealthy. Capacity now recovers automatically within minutes, and an alarm on the UnHealthyHostCount metric alerts the team so that the leak can be fixed.

Check yourself

An NLB has two targets in AZ a and six in AZ b, with cross-zone load balancing at its default setting. What share of traffic does each target in AZ a receive?

Show answer

Cross-zone is disabled by default on NLB, so each AZ node receives about half the traffic and each of the two targets in AZ a receives about 25%. Enabling cross-zone (with inter-AZ data charges) or balancing targets across AZs evens it out.

Exam Tips

Remember for the exam

  • ALB for HTTP routing; NLB for TCP/UDP, static IPs and extreme performance; GWLB for appliance fleets.
  • Cross-zone load balancing is always on for ALB (configurable per target group) and off by default for NLB and GWLB, where enabling it adds inter-AZ charges.
  • Set the Auto Scaling health check type to ELB so instances failing load balancer health checks are replaced.
  • When all targets are unhealthy, ALB and NLB fail open; avoid health checks that depend on shared downstream services.
  • Deregistration delay drains connections (default 300 seconds); slow start ramps new targets; automatic target weights reduce traffic to anomalous targets.