Skip to content

NotesLoad Balancing & Auto Scaling

Load Balancing & Auto Scaling

ALB / NLB / GWLB routing, cross-zone math, connection draining, ASG policies, and the termination / health-check.

Updated Sep 26, 2026

ELB & Auto Scaling Quick Notes




Load Balancer Types

LB, Layer, Fit

ALB: 7 (HTTP/HTTPS), Path/host/header routing, content-based

NLB: 4 (TCP/UDP/TLS), Extreme performance, static IP, non-HTTP

GWLB: 3/4 gateway, Scale firewall / appliance fleets

CLB: Legacy, Prefer ALB/NLB

ALB Routing

  • Path-based: /orders vs /products
  • Host-based: test.example.com Host header
  • Also: headers, query string, source IP
  • SNI: Many TLS certs on one listener (multi-site behind one ALB)

Cross-Zone Load Balancing

Assume 1 instance in AZ-A and 4 in AZ-B:

Mode: Distribution

Enabled: Equal per instance → 20% each

Disabled: Equal per AZ → AZ-A 50%; each of AZ-B’s four gets 12.5%

Connection Draining

  • Keep in-flight requests alive when a target deregisters / goes unhealthy.
  • ALB/NLB name: deregistration delay.
  • Sticky sessions / idle timeout / cross-zone do not solve dropped in-flight requests.

Health Check Failures (targets look fine)

  1. Instance SG does not allow traffic from the load balancer SG
  2. Health-check path/port misconfigured

NLB Targeting

  • Routes to the instance’s primary private IP on the primary ENI.

Auto Scaling Groups

  • ASG: When/where (min / desired / max, AZs).
  • Launch template: What (AMI, type, user data, …).
  • Mixed On-Demand + Spot across instance types: Requires a launch template (not launch configuration).

Scaling Policies

Policy: Idea

Manual: Change desired by hand

Scheduled: Known peaks — set desired before the spike

Simple / Step: Alarm-driven adds/removes (bands for step)

Target tracking: “Keep CPU at 50%”

Predictive: Learns daily/weekly patterns; scales before the surge

  • Steady baseline: ASG min ≥ 2 across AZs + cover baseline with RIs / Savings Plans.

Maintenance Without Replacement

  • Put instance in Standby, patch, exit Standby — or suspend ReplaceUnhealthy, patch, mark healthy, resume.

Health Checks

  • EC2 status (default) vs ELB/ALB checks (app-aware).
  • ASG and ALB health are independent — point ASG at ELB checks when ALB is source of truth.
  • Grace period: Wait for boot before judging unhealthy.

Default Termination Policy

  • When balancing an AZ: prefer the instance with the oldest launch configuration (classic exam answer).

Capacity Math

  • Need ≥4 instances after losing one AZ → e.g. 3 AZs × 2 (not 2 AZs × 2).