AWS - Elastic Load Balancer (ELB) And Auto Scaling Group (ASG)

Its a managed service

  • AWS guarantees that it will be working
  • AWS takes care of upgrades, maintenance, and high-availability
  • AWS provides only a few configuration knobs
  • ELB supports health checks
  • It distributes traffic across EC2 in multiple AZ.

It costs less to setup your own load balancer, but it will be a lot more effort on your end to maintain and integrate

3 Kinds of load balancers:

  • Application Load Balancer (HTTP/HTTPS only) - layer 7 - HTTP, HTTPS, Websocket
  • Network Load Balancer (ultra high performance, allows tcp) - Layer 4 - TCP, TLS, UDP
  • Classic Load Balancer V1 (slowly retiring) - Layer 4 and 7 : HTTP, HTTPS, TCP, Fixed host name : xxx.region.elb.amazonaws.com

Health Checks:

  • The health checks are done on a port and a route (/health is common)
  • If the response is not 200 OK then the instance is unhealthy
Classic load balancer health check
  • You can either have internal (private) or external (public - user facing).

Load Balancer Security Group

You can have only traffic coming from the loadbalancer to the EC2 instances by adding the inbound rules with load-balancer's security group

Load Balancer Errors:

  • 4xx errors are client induced errors
  • 5xx errors are application induced errors
  • Load balancer error 503 means at capacity or no registered target

Monitoring Load Balancer:

  • The ELB access logs will log all the access requests (you can debug every single request)
  • CloudWatch metric will give you aggregated statistics (eg. connection counts etc)

Auto Scaling Group

In real-life, the load on your websites and application can change over time. The goal of an auto scaling group is to:

  • Scale out (add EC2 instances) to match an increased load.
  • Scale in (remove EC2 instances) to match a decreased load
  • Ensure we have a minimum and a maximum number of machines running
  • Automatically register new instances to a load balancer
  • Replace unhealthy instances
  • Cost Savings: only run at an optimal capacity.