Auto-scaling and load balancing
Let’s work on configuring a highly available and fault tolerant web application. Before we can begin the same let’s try to understand the components in achieving the same.
Elastic Load Balancer:
- ELB is the EC2 service which automatically distributes the incoming traffic to all the instances associated with the ELB.
- Elastic load balancer shall be paired with auto-scaling so that high availability and fault tolerance can be increased. We will also update our self with the concept of high availability just few min later.
- An ELB has its own DNS record set which means it can be directly accessed from the open internet.
- Elastic load balancer, when used with VPC, can also act as an internal load balancer to the internal EC2 instances running on the private subnets.
- The elastic load balancer can check the health of associated EC2 instances and automatically stops sending the traffic to the same.
- If we bind SSL certificates to the load balancer then we can also reduce the load on backend ec2 instances which would have been generated due to SSL management.(encryption/decryption)
- Auto-scaling is the ec2 service provided by AWS using which you can automate the process of increasing and decreasing the number of provisioned EC2 instances running for your application.
- It can increase or decrease the instances based on some threshold chosen by you during configuration time.
- When configuring AWS there are two important components.
- Launch Configurations: This acts as a template for the auto scaling service to tell us what type of EC2 instance needs to be provisioned.
- Auto-scaling Group: Here you define all the rules and settings that will determine scale up and scale down of the environment. You define
- How many minimum and maximum instances are allowed
- You define VPC and AZ’s in which new instances shall be launched.
- You define that provisioned instances shall receive traffic from ELB or, not or it has to receive the traffic than from which ELB
- You can configure scaling policies and SNS notifications here.
Before we dig into the practical implementation, let’s also review two important types of ELBs
Classic Elastic Load Balancer:
Its designed for simple load balancing. It is desired to use when all of the EC2 instances are serving the same data as there is granular routing rules and traffic is routed to all the instances evenly.
Application Load Balancer:
For complex traffic routing, application ELB is the desired option. You can balance the traffic by using content-based rules. Also content-based rules can be configured using
- Path-Based Rules: Traffic is routed based on URL paths in the HTTP header.
- and Host-based Rules: Traffic is routed based on host field in the HTTP header
Application load balancer also supports ECS containers, HTTPS, HTTP/2, WebSockets, AccessLogs, Sticky Sessions and AWS WAF(Web application Firewall)