Lesson 4 of 4 Elastic Load Balancing

Configuring Target Groups, Health Checks and Sticky Sessions

This lesson explains how target groups and their settings control where, and how, traffic is delivered behind each load balancer.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain how health check design affects a fleet.
  • Explain cross-zone load balancing and routing algorithms.
  • Explain sticky sessions, deregistration delay, slow start and weighted target groups.

Health checks

Elastic Load Balancing sends traffic only to targets that pass their health checks. Each target group defines its health check: the protocol and path to request, the interval between checks, and the number of consecutive successes and failures that mark a target healthy or unhealthy. Unhealthy targets receive no traffic, and an Auto Scaling group configured to use ELB health checks replaces them.

The design of the health check endpoint matters. A shallow check, which confirms only that the web server responds, avoids removing every target at once when a shared dependency, such as the database, fails. A deep check, which also confirms that dependencies are reachable, catches more problems but can take the whole fleet out of service at once. A dedicated health endpoint that reflects the instance's own health is usually the best compromise.

The following diagram compares the two kinds of check when the database fails.

Shallow and deep health checks when a shared dependency fails. A shallow check confirms only that each web server responds, so the targets stay in service and can return errors for some requests. A deep check also tests the database, so when the database fails every target fails its check at once and the whole fleet is removed.
A dedicated endpoint that reports the instance's own health avoids both extremes.
Scenario questions

Designing health checks

Exam skills 2.2.3 · 2.2.4

Choose a health check design that avoids taking the fleet down.

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

Distributing traffic

Two settings decide how a load balancer spreads traffic. With cross-zone load balancing, each load balancer node sends traffic to targets in every enabled Availability Zone, rather than only to those in its own zone, so targets receive equal shares even when zones have different numbers of targets. It is on by default for ALBs at no charge, where it can be turned off per target group, and off by default for NLBs and GWLBs, where turning it on incurs data transfer charges between zones.

The algorithm chooses a target for each request. An ALB uses round robin by default, or least outstanding requests, which sends each request to the target with the fewest requests in progress and suits requests whose processing times vary widely. NLBs and GWLBs use flow hashing, so every packet of a connection goes to the same target. The following table summarises the settings.

ALB
Cross-zone load balancingOn by default, free
AlgorithmRound robin, or least outstanding requests for uneven request durations
NLB / GWLB
Cross-zone load balancingOff by default; inter-AZ charges when on
AlgorithmFlow hashing (a connection stays on one target)

Sessions and target changes

Several target group settings decide how the load balancer treats client sessions and targets that are added or removed. Sticky sessions send a client's requests to the same target, using a cookie that the load balancer generates for a set duration, or a cookie that the application sets. They help applications that keep session state in memory, but they spread load unevenly and lose the session if the target is removed, so storing session state outside the instances, for example in ElastiCache or DynamoDB, is the better design.

The deregistration delay, also called connection draining, keeps a target that is being removed, during scale-in or a deployment, serving its in-flight requests for up to 300 seconds by default while it receives no new ones. Slow start gives a newly registered target a gradually increasing share of requests, which protects applications that need time to warm their caches. Weighted target groups in an ALB rule split traffic between, for example, the current and a new version of an application, for blue/green and canary deployments. The following table summarises these features.

FeatureEffect
Sticky sessionsBind a client to a target with duration- or application-based cookies; can unbalance load, so prefer external session state
Deregistration delayLets in-flight requests finish before removal (300 s default)
Slow startRamps traffic to new targets gradually
Weighted target groupsBlue/green and canary deployments in ALB rules
Match the pairs

Target group settings

Exam skills 3.4.4 · 2.1.1

Match each requirement with the target group setting that meets it.

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

Users logged out at random

Users of a web application are logged out unpredictably. The application keeps session data in the memory of each instance, and the ALB spreads requests across six instances.

FixTrade-off
Enable sticky sessions on the target groupQuick fix; uneven load, and sessions are lost when an instance is replaced
Store sessions in ElastiCache or DynamoDBInstances become stateless; any instance can serve any user

The team enables stickiness immediately and moves sessions to ElastiCache as the lasting fix, which lets Auto Scaling add and remove instances freely. A deregistration delay lets in-flight requests finish when instances leave the target group.

Check yourself

What does the deregistration delay do when a target is removed?

Show answer

It stops new requests to the target but lets in-flight requests complete, for up to the configured time.

Exam Tips

Remember for the exam

  • If load is uneven across Availability Zones on an NLB, enable cross-zone load balancing.
  • If users lose their sessions when instances scale in, store sessions externally in ElastiCache or DynamoDB, or use stickiness.
  • To let in-flight requests finish during scale-in, set a deregistration delay.
  • When requests of very different durations overload some targets, use the least outstanding requests algorithm.
  • Avoid health checks that fail every target when a shared dependency is down.