Skip to content

Stickiness, Cross zone balancing & Connection Draining

Links: 101 AWS SAA Index


Stickiness

  • It is achieved by using sticky sessions. It is also known as session affinity.
  • Works for ALB and CLB.
  • Idea is that a suppose client 1 makes a request to the ALB and ALB directs it to EC2 machine 1. Then all the subsequent requests from client 1 will go to EC2 machine 1.
  • A cookie is used for stickiness which has an expiration date that we set. When the cookie expires the client may or may not be redirected to the same EC2 instance.
  • Stickiness helps in preserving session data. Like login information when visiting subsequent pages
Enabling stickiness may bring imbalance to the load over the backend EC2 instances

Different types of cookies

  • There are 2 different types of cookies: Duration based and application based.

  • Application-based Cookies

    • Custom cookie

      • Generated by the target
      • Can include any custom attributes required by the application
      • Cookie name must be specified individually for each target group
      • Don't use AWSALB, AWSALBAPP, or AWSALBTG (reserved for use by the ELB)
    • Application cookie

      • Generated by the load balancer
      • Cookie name is AWSALBAPP
  • Duration-based Cookies

    • Cookie generated by the load balancer
    • Cookie name is AWSALB for ALB, AWSELB for CLB

Cross zone load balancing

  • Without cross zone load balancing the traffic is contained within the AZ. But if there is an imbalance in the number of EC2 instances between the AZs then some EC2 instances might be subjected to more load as compared to others.
    • attachments/Pasted image 20220420190629.jpg
  • For ALB cross zone load balancing is enabled by default. Cannot be disabled. No charges for inter AZ data transfer.
  • For NLB disabled by default. You pay for inter AZ data transfer.
  • For CLB disabled by default.

Connection Draining/Deregistration Delay

  • It can be defined as the time to complete in-flight requests while the instance is de-registering or unhealthy.
  • It is known as connection draining in CLBs and deregistration delay in ALB and NLB.
  • Our load balancer is smart enough to understand that if an EC2 instance is in its draining state then it won’t send it any new connections.
  • Draining period can be between 0 - 3600s. 0 means draining is disabled.
Set draining period to a low value if the requests are short
  • It allows already existing connections to close cleanly.
  • EC2 instance cannot be removed until draining is done.

Factors that could cause unequal distribution of traffic

  • Sticky sessions
  • Disabling cross zone load balancing. Enabled by default for ALB.
  • Long lived TCP connection
  • Instances of a specific capacity type aren't equally distributed across Availability Zones

Last updated: 2022-06-09