AWS Learning Journey

Survive Traffic Spikes Automatically: Load Balancers and Auto Scaling on AWS

ALB vs. NLB vs. Gateway Load Balancer, listeners, target groups, health checks, launch templates, and scaling policies — the machinery that keeps apps up when traffic goes wild.

7 min read · 1345 words
AWSLoad BalancingAuto ScalingCloud ArchitectureDevOps
Survive Traffic Spikes Automatically: Load Balancers and Auto Scaling on AWS cover image

AWS from Zero to Production — Phase 4, Part 2 of 6 · See the full series roadmap


Your product gets mentioned on a popular podcast. Traffic jumps tenfold in five minutes.

With one server, you’re down. With three servers you sized by hand, you’re down a little later. With a load balancer and Auto Scaling, new servers appear on their own, join the pool, and start taking traffic — and when the spike is over, they disappear so you stop paying for them.

That’s the promise of elasticity from Phase 1. This article is how it actually works.

What you’ll walk away with


Elastic Load Balancing

Elastic Load Balancing (ELB) distributes incoming traffic across multiple targets — EC2 instances, containers, IP addresses, or Lambda functions — in multiple Availability Zones.

AWS offers three types.

Application Load Balancer (ALB)

Network Load Balancer (NLB)

Gateway Load Balancer (GWLB)

Rule of thumb: If it speaks HTTP, start with an ALB. If you need static IPs, non-HTTP protocols, or PrivateLink, use an NLB. If you’re deploying firewall appliances, that’s what GWLB is for.


Listeners, rules, and target groups

Three pieces make a load balancer work:

Load balancer
   |
   +-- Listener (HTTPS : 443)
   |      |
   |      +-- Rule: path /api/*        -> target group "api"
   |      +-- Rule: host admin.example -> target group "admin"
   |      +-- Default                  -> target group "web"
   |
   +-- Listener (HTTP : 80)
          +-- Default: redirect to HTTPS

Target types


Path-based and host-based routing

One ALB can serve many services:

That means one load balancer, one certificate setup, and one DNS entry point for a whole set of microservices.


TLS termination

The load balancer can handle HTTPS so your app doesn’t have to:

  1. Request a certificate in AWS Certificate Manager — free for use with ELB.
  2. Add an HTTPS:443 listener with that certificate.
  3. Choose a security policy that controls the allowed TLS versions and ciphers. Prefer the recommended modern policies.
  4. Add an HTTP:80 listener that redirects to HTTPS.

Traffic between the load balancer and targets can stay HTTP inside the VPC, or be re-encrypted if compliance requires end-to-end TLS.


Health checks

A health check is how the load balancer decides whether a target should get traffic.

Protocol:            HTTP
Path:                /health
Healthy threshold:   3 consecutive successes
Unhealthy threshold: 2 consecutive failures
Interval:            15 seconds
Success codes:       200

What makes a good health check

Watch out: A health check on / that renders a heavy home page can fail under load — exactly when you need the capacity. And a health check that always returns 200, even when the app is broken, hides real failures.


Auto Scaling groups

An Auto Scaling group (ASG) keeps a fleet of EC2 instances at the right size.

You set three numbers:

The ASG spreads instances across the AZs you choose, replaces unhealthy ones, and registers new ones with your target groups automatically.

Important: Set the ASG’s health check type to ELB, not just EC2. Then an instance that’s running but failing the load balancer’s health check gets replaced, not just ignored.

Launch templates

A launch template defines what each new instance looks like: AMI, instance type, security groups, IAM instance profile, user data, and metadata options.


Scaling policies

aws autoscaling put-scaling-policy \
  --auto-scaling-group-name web-asg \
  --policy-name cpu-50 \
  --policy-type TargetTrackingScaling \
  --target-tracking-configuration '{
    "PredefinedMetricSpecification": {
      "PredefinedMetricType": "ASGAverageCPUUtilization"
    },
    "TargetValue": 50.0
  }'

Engineer’s note: New instances need time to boot and warm up. Faster startup — a prebuilt AMI instead of a long user data script — means faster, more accurate scaling. Warm pools can keep pre-initialized instances ready.


The full picture

Users
  |
  v
Route 53 -> ALB (public subnets, HTTPS with ACM)
             |
             v
           Target group (health check /health)
             |
             v
           Auto Scaling group (private subnets, 2 AZs)
             min 2   desired 2-10   max 10
             launch template v7: AMI + instance profile + IMDSv2
             policy: target tracking, 50% CPU

Common mistakes


Key takeaways


Quick self-check

Test yourself before moving on:

  1. A partner needs to allow-list fixed IP addresses for your API. Which load balancer?
  2. Which target type do Fargate tasks need?
  3. An instance is running, but failing the ALB health check. Why isn’t the ASG replacing it?
  4. Which scaling policy should you try first?

Answers

  1. Network Load Balancer — it offers static IPs per AZ.
  2. ip.
  3. The ASG’s health check type is probably EC2 instead of ELB.
  4. Target tracking.

What’s next

In Part 3, we package apps into containers: Dockerfiles, Amazon ECR, and Amazon ECS on Fargate — task definitions, services, roles, deployments, and logging.

What’s the biggest traffic spike you’ve had to survive? Share the story in the comments.


Share this article

LinkedIn post draft