(2) Part 1-AWS Hands-on: High Availability and Scalability with ALB | Application Load Balancer|
Scalability
Scalability means that an application or system can handle greater loads by adapting There are two kinds of scalability
Vertical scalability
Horizontal scalability which is also called elasticity
scalability is linked but different to high availability
Vertical Scalability (Scale up/down)
Vertical scalability means increasing the size of the instance.
For example, The application runs on t2.micro, vertical scalability here means increasing it to t2.large.
vertical scalability is common for non-distributed systems such as database RDS, and Elastic Cache.
Horizontal Scalability (Scale out/in)
Horizontal scalability means increasing the number of instances/systems for your application. Horizontal scaling implies distributed systems this is very common for web applications and model applications.
High Availability
High Availability usually goes hand-in-hand with Horizontal Scaling. Horizontal Scaling means running the application in at least 2 availability zones (AZs).
The goal of high availability is to survive a data center loss.
Load Balancing
Load balancers are services that forward traffic to multiple servers example ec2 instances downstream.
Ex : If multiple users are trying to access the application then load balancers balance the traffic equally to the Ec2 servers
Advantages of LB
๐ Spread load across multiple downstream instances
๐ Expose a single point of access ( DNS) to the app
๐ Handles failures of downstream instances
๐ Does regular health checks to the instances
๐ High availability across zones
๐ Separate public traffic from private traffic
๐ It is integrated with many other services such as EC2, auto-scaling group, ECS ACM, cloud watch, route 53, AWS WAF, and AWS Global Accelerator.
Types of LB
๐ Classic Load Balancer ( Deprecated Now)
๐ Application Load Balancer ( 2016 onwards) -->HTTP, HTTPS, WebSocket
๐ Network Load Balancer (2017 onwards) --> TCP, TLS (Secure TCP), UDP
๐ Gateway Load Balancer (2020 onwards ) --> Operates at 3rd layer - IP Protocol.
Load Balancer Security Groups
Allows Users to access our load balancers from anywhere using HTTP/HTTPS. EC2 instances should allow only the traffic which is coming from load balancers.
Here there is an application security group where it will have the security group of the instance. We will link the security group of the ec2 instance with the security group of LB. It will only allow the traffic which is coming from LB.
Application Load Balancers
Target Groups
A target group is a logical grouping of targets, such as EC2 instances, IP addresses, or AWS Lambda functions, that receive traffic from the ALB.
When you create an ALB, you specify one or more target groups that the ALB routes incoming traffic to. Each target group is associated with a specific port on the ALB, and you can configure health checks to monitor the health of the targets in the group.
There are 2 microservices ( user and search ) that can route their HTTP traffic to 2 target groups by using ALB.
Application Load Balancer Hands-On
Let's launch 2 instances that act as a target group. I selected AWS linux AMI.
Paste this user data
cat install.sh #!/bin/bash sudo yum update -y sudo yum install -y httpd sudo systemctl start httpd sudo systemctl enable httpd sudo chown -R ec2-user:ec2-user /var/www/html/ sudo chmod -R 755 /var/www/html/ #echo"<h1> Hello Aasifa from $(hostname -f)</h1>">/var/www/html/index.html echo "<h1> Hello Aasifa from $(hostname -f)</h1>" > /var/www/html/index.html
You can see that my 2 instances are running but with different url/ip address. Now with load balancing we will run the 2 instances with same URL.
As we are dealing with HTTP traffic, we will use Application Load Balancer.
Create a new security group
Now we will route our HTTP traffic to target group. Here TG is Our instances created.
Wait until it becomes active
When you paste this DNS in the browser then you can see that 2 instances are running with the same URL with balance. When you stop the instance then it will run only the active instances.
-- ๐ Thank you for your time. In the next article, we will discuss about Network, Gateway and Elastic Load Balancer ๐ Follow for more on AWS --