Skip to content
VirtualLP Virtual Learning Platform

Elastic Load Balancing and EC2 Auto Scaling

13 min read Topic 6 of 30 1 hands-on lab

A single server is a single point of failure and cannot grow with demand. Elastic Load Balancing (ELB) spreads traffic across many targets, and EC2 Auto Scaling adds or removes those targets automatically.

flowchart TB
    U((Users)) --> ALB["Application Load Balancer<br/>listener :443 · rules"]
    ALB --> TG["Target group web-tg<br/>health check GET /health"]
    TG --> E1[EC2 – AZ a] & E2[EC2 – AZ b] & E3[EC2 – AZ c]
    ASG["Auto Scaling group<br/>min 2 · desired 3 · max 6"] -. launches / replaces .-> E1 & E2 & E3
    CW[CloudWatch metric<br/>CPU / requests per target] --> ASG

Load balancer types

Type Layer Best for Highlights
Application LB (ALB) 7 – HTTP/HTTPS/gRPC Web apps, microservices, containers Path/host/header routing, redirects, Lambda targets, WAF
Network LB (NLB) 4 – TCP/UDP/TLS Extreme performance, static IPs Millions of req/s, preserves client IP
Gateway LB (GWLB) 3 Third-party firewalls/appliances GENEVE encapsulation

Listeners, rules and target groups

  • A listener checks for connections on a protocol/port (HTTPS 443 with an ACM certificate).
  • Rules route requests: /api/* → api-tg, host: admin.example.com → admin-tg.
  • A target group contains EC2 instances, IPs, containers or Lambda functions and runs health checks; unhealthy targets stop receiving traffic.

EC2 Auto Scaling

Component Purpose
Launch template AMI, instance type, key, security groups, user data, IAM role – how to create an instance
Auto Scaling group (ASG) Subnets (multiple AZs), min / desired / max capacity, attached target group
Health checks EC2 status or ELB health – unhealthy instances are terminated and replaced (self-healing)
Scaling policies How many instances, based on demand

Scaling policies

Policy How it works Example
Target tracking Keep a metric at a target – like a thermostat Average CPU = 50 %, or ALB requests per target = 1000
Step / simple Add/remove N instances when an alarm fires +2 when CPU > 80 % for 5 min
Scheduled Change capacity at known times 09:00 desired 10, 20:00 desired 2
Predictive ML forecast of daily/weekly patterns Pre-warm before the morning peak
Key point

High availability = instances in ≥ 2 AZs behind a load balancer. Elasticity = Auto Scaling. Fault tolerance = the ASG replaces failed instances automatically using ELB health checks.

Design tips

  • Make instances stateless (sessions in ElastiCache/DynamoDB, files in S3) so any instance can be replaced.
  • Use connection draining (deregistration delay) so in-flight requests finish.
  • Put instances in private subnets; only the load balancer is public.
  • Terminate HTTPS on the ALB with a free ACM certificate.

Practise it

Virtual lab · Amazon Web Services · 50 min

Highly available web tier: Application Load Balancer + Auto Scaling group

Build a self-healing, elastic web tier: layered security groups, a launch template with user data, a target group with health checks, an internet-facing ALB across two AZs and an Auto Scaling group with target tracking – then load-test it and kill an instance.

Open lab

Quick revision

  1. ALB = layer 7 routing; NLB = layer 4 performance; GWLB = appliances.
  2. Listener → rules → target groups with health checks.
  3. ASG = launch template + min/desired/max + subnets in many AZs.
  4. Target tracking is the simplest, most common scaling policy.
  5. Stateless instances in private subnets behind a public ALB.

Practise this topic

Hands-on virtual lab

Apply what you just read in a realistic, guided simulation. Free with a verified account.

Create a free account to track your progress and unlock virtual labs.