Application Load Balancer
Introduction:
An Application Load Balancer (ALB) is a component of Amazon Web Services (AWS) that distributes incoming traffic to multiple targets such as EC2 instances, Lambda functions, or container services, based on advanced routing rules.
ALB offers advanced load balancing capabilities for modern web applications that require high availability, scalability, and security. It supports content-based routing, which allows you to route traffic to different targets based on the content of the request, such as the URL path, HTTP headers, or query string parameters.
In addition, ALB provides built-in features to improve application security, such as SSL/TLS encryption, integration with AWS Web Application Firewall (WAF), and support for client authentication.
ALB is also highly available and scalable. It automatically scales to handle incoming traffic and distributes it across multiple targets, ensuring that your application stays up and running even if one or more targets become unavailable.
Overall, ALB is an essential component for building modern web applications that require high availability, scalability, and security.
The more clues a detective has, the easier it gets for him to solve the case. That’s exactly how a load balancer works. The more information a load balancer has, the better it works. In this blog, I’m going to talk about Application Load Balancer and how it distributes incoming traffic by getting greater access to packet headers, HTTPS and HTTPS details.
This article focuses on the following pointers:
- What is Application Load Balancer
- Working Of Application Load Balancer
- Features Which Make It Better Than Classic Load Balancer
- Demo: Create an Application Load Balancer And Demonstrate It’s Working
What is Application Load Balancer?
An Application Load Balancer (ALB) is a type of load balancer that distributes incoming traffic across multiple targets, such as EC2 instances, container services, or Lambda functions, based on advanced routing rules. ALB is a component of Amazon Web Services (AWS) and is designed to handle modern web applications that require high availability, scalability, and security.
Unlike a traditional load balancer, which only distributes traffic based on IP address and port number, ALB provides content-based routing, which allows you to route traffic to different targets based on the content of the request. For example, you can use ALB to route traffic based on the URL path, HTTP headers, or query string parameters.
ALB also provides built-in features to improve application security, such as SSL/TLS encryption, integration with AWS Web Application Firewall (WAF), and support for client authentication. It is highly available and scalable, automatically scaling to handle incoming traffic and distributing it across multiple targets, ensuring that your application stays up and running even if one or more targets become unavailable.
Overall, ALB is an essential component for building modern web applications that require high availability, scalability, and security.
Working Of Application Load Balancer
An Application Load Balancer (ALB) is a type of load balancer that distributes incoming traffic across multiple targets, such as EC2 instances, container services, or Lambda functions, based on advanced routing rules. ALB is a component of Amazon Web Services (AWS) and is designed to handle modern web applications that require high availability, scalability, and security.
Unlike a traditional load balancer, which only distributes traffic based on IP address and port number, ALB provides content-based routing, which allows you to route traffic to different targets based on the content of the request. For example, you can use ALB to route traffic based on the URL path, HTTP headers, or query string parameters.
ALB also provides built-in features to improve application security, such as SSL/TLS encryption, integration with AWS Web Application Firewall (WAF), and support for client authentication. It is highly available and scalable, automatically scaling to handle incoming traffic and distributing it across multiple targets, ensuring that your application stays up and running even if one or more targets become unavailable.
Overall, ALB is an essential component for building modern web applications that require high availability, scalability, and security.
Features Which Make It Better Than Classic Load Balancer
Content-Based Routing: Application Load Balancer has to access HTTP headers and hence routes the traffic based on it.
Support for Container-Based Application: With the powerful concept of containerization, most of the users are packing their microservices into containers and hosting them on EC2 instances. This allows a single EC2 instance to run multiple services. Application Load Balancer supports these container-based applications. One instance can host multiple containers and listen on multiple ports, behind the same target group. It also performs fine-grained, port-level health checks.
Better Metrics: Application Load Balancer performs health checks on a per-port basis and also generates a report. Health check specifies a range of acceptable HTTP responses. These health checks are also accompanied by detailed error codes.
Path-Based Routing: Application Load Balancer supports path-based and host-based routing which is not the case with Classic load balancer. You can route requests to multiple domains using a single load balancer.
Register IP Address and Lambda Functions: Besides registering EC2 instances, you can also register IP addresses and Lambda functions to your target. And hence you can also register targets that are outside the VPC.
Provides Additional Protocols and Workloads:
Application Load Balancer provides two additional protocols – HTTP/2 and WebSocket
HTTPS/2: This protocol supports multiplexed requests across a single connection. This reduces Network traffic.
WebSocket: This protocol allows you to set up a long-lasting TCP connection between the client and the server. This protocol is way more efficient compared to the older methods.
Demo: Create an Application Load Balancer And Demonstrate It’s Working
Let’s understand Application Load Balancer better by creating one and using it. In this demo, I’m going to create two EC2 instances, deploy Nginx web server on both of them with different HTML output(easy to differentiate between them), create an application load balancer, register these two instances to that load balancer and check if the web server deployed on the instances can be accessed from the load balancer DNS. Let’s get started.
Step 1: Create two EC2 instances and connect your instances to either Putty or cmder.
Step 2: Install Nginx web server on both the instances. Execute the following commands for installing Nginx:
12345 | $ sudo apt-get update $ sudo apt install nginx $ sudo ufw app list $ sudo ufw allow 'Nginx HTTP' $ sudo ufw status |
Copy the public IP of the instances and paste it on a browser like a URL, to check if Nginx has been installed successfully.
Step 3: Change the HTML output of the Nginx web server to avoid the confusion between the deployments on both instances.
12 | $ cd /var/www/html $ sudo vi index.nginx-debian.html |
Change the content of the H1 tag as “Welcome to Nginx! – SERVER 1”. Do the same on the other instance except, change it to “Welcome to Nginx! – SERVER 2”.
Step 4: Create an Application Load Balancer. In the navigation pane, under LOAD BALANCING, choose Load Balancers and click on Create under Application Load Balancer.
You’ll be navigated to another page, Choose Create Load Balancer there.
Let’s Configure the Load Balancer. For Name, type the name you would like your Load Balancer to have. For Scheme either select Internet-facing or Internal. In this case, I’ve chosen internet-facing. Internet-facing basically routes requests from clients to the target over the internet.
For Listeners, the default is to accept TCP traffic on port 80 and I’m continuing with the same default listener configuration. In case you want to add another listener, you can choose Add Listener.
For Availability Zone, select the VPC that you’ve used to create your EC2 instances. Select an Availability Zone and the subnet for that Availability Zone for each Availability Zone used to create an EC2 Instance.
You add tags to your load balancer as required. Tags are especially useful when you have multiple load balancers.
Click on Next: Configure Security Settings. You might see a warning but you can ignore it.
In this step, you can configure the security of your load balancer, You can either Create a New Security Group or Select an existing Security Group. In this case, I’ve chosen an existing security group.