← Learning Hub
Intermediate

Load Balancing and Auto Scaling

One server can fail, and it can get too busy on a sale day. The answer is several servers behind a load balancer, with auto scaling adding or removing servers as traffic changes.

A single server is a single point of failure: if it crashes, or a sale brings ten times the usual visitors, the site goes down. Putting several servers behind a load balancer spreads the traffic and routes around broken servers, and auto scaling adds servers when it's busy and removes them when it's quiet, so you pay only for what you need. This is how big sites stay up on their busiest days.

Elastic Load Balancing (ELB)

  • Application Load Balancer (ALB) - for websites and APIs (HTTP/HTTPS). It can send /api/* to one group of servers and /images/* to another.
  • Network Load Balancer (NLB) - for very fast TCP/UDP traffic, such as games or chat.
  • Gateway Load Balancer - for security appliances (firewalls).

The load balancer sends each request to a healthy server in a target group. It checks each server's health (for example GET /health every 30 seconds) and stops sending traffic to broken ones.

Auto Scaling groups

An Auto Scaling group (ASG) keeps a number of EC2 servers running from a launch template (which image, which size, which settings).

  • Minimum - never fewer than this (e.g. 2, in two Availability Zones)
  • Desired - how many to run right now
  • Maximum - a cap, so a traffic spike can't run up a huge bill
  • Target tracking policy - e.g. keep average CPU at 50%: add servers when busier, remove them when quieter
Example
Users
  │  https://shop.example.com
  ▼
Application Load Balancer  (public subnets, 2 AZs)
  │  health checks: GET /health
  ▼
Target group ← Auto Scaling group (min 2, desired 2, max 8)
  ├── EC2 in ap-south-1a
  └── EC2 in ap-south-1b
Servers in an Auto Scaling group come and go, so don't keep anything important on them. Store files in S3, data in RDS or DynamoDB, and logins in a shared store.
Key points
  • A load balancer spreads requests across healthy servers.
  • ALB for HTTP/HTTPS; health checks remove broken servers.
  • Auto Scaling groups keep a min/desired/max number of servers.
  • Don't store important data on the servers themselves.

📝 Test yourself

1. Which load balancer fits a normal website or REST API?
2. What does the Maximum size of an Auto Scaling group protect you from?
3. Fill in what the load balancer uses to find broken servers:
health