Data Science Cloud Computing

Path-Based Routing on AWS Application Load Balancer

Path-Based Routing on AWS Application Load Balancer
Path-Based routing on AWS ALB

When it comes to your HTTP and HTTPS-based application infrastructure, the load balancer is one of the significant components.

Application Load Balancer launched in 2016 supports content-based routing and works well for serverless & container-based applications, and it is highly scalable.

Often it is confusing for a novice learner to distinguish between the type of load balancers. Depending on one's use case/requirement use of load balancers can differ.

To summarize, there are three different types of load balancers in AWS Elastic Load Balancer. Classic load balancer(CLB), Network load balancer(NLB), and Application load balancer(ALB).

CLB is also known as a Classic load balancer that works on Layer 4.

ALB is also known as an Application load balancer that works on Layer 7.

NLB is also known as a Network load balancer that works on Layer 4.

In this article, we will discuss the working of an Application Load balancer with the practical demo.

1. What is a Load Balancer?

Before we discuss whatnot about the Application Load Balancer, it is crucial to understand load balancers. Without beating around the bush, the load balancer is an algorithm that balances the incoming traffic on your application.

Load balancing works on the concept of a round-robin algorithm. By this method, clients requests are routed to the available backend servers on a periodic or cyclical basis.

So a load balancer is a piece of hardware (or virtual hardware) that acts as a reverse proxy to distribute network and/or application traffic across different servers.

2. What is Path-Based Routing?

Path-based routing as the name suggests is related to some kind of path. It is nothing but the request from the ALB to different destinations.

  • Path-based routing is one of the unique features offered by Application Load Balancer.
  • Path-based routing is also referred to as URL-based routing.
  • The Application load balancer will forward the requests to the specific targets based on the Rules configured in the load balancer.

3. How does Application Load Balancer Work?

Application load balancer works at the application layer that is at the 7th layer of the OSI model.

Application Load Balancer cannot take any decisions based on port numbers, It has to check the 7th layer. After the load balancer receives a request from a client, it validates the listener rule and selects the target group.

To make it lucid, let us consider one example:

In the below architecture visualization, we can see that the request from the client contains the ( /product) inside the URL.

How does Application Load Balancer work?

So the request from the Application Load Balancer is directed to the server/pod/EC2 instance where all the product-based services of applications are running.

If the URL contains (/services) then the request would be forwarded to the EC2 instance by ALB to the Server/Instance where the services-related stuff of the application is running.

4. Configuration of Application Load Balancer

For this demo, we will launch two private EC2 instances with the apache web server in them.

Before configuring ALB we need to create a target group, To set up path-based routing we need at least two target groups.

  • Under LOAD BALANCING Click Target Groups, Select Create target group, Choose target type as Instances.
Configuration of Application Load Balancer
  • Now, specify a name for the target group, and the Protocol to be HTTP and port 80. Protocol version would be the default(HTTP1). After that, we have to mention the health check path and register the instances to it.
Application Load Balancer
  • As you can see, we have created two target groups here, one of the target groups Chat Service is registered with /chat instance, and the other SearchService is registered with /search instance.
chat service
  • Under Application Load balancer, click on create and name your load balancer and add the port that ALB would be listening on.
step 1: configure load balancer
  • Configure the routing, select the existing target group which we have created already. Finally, our ALB is configured.
step 4: configure routing
  • But we need to create a policy/rule for our application load balancer to perform the reverse proxy.
  • Click on the Application Load Balancer we created and select the listener tab. click on view/edit rules and add the rule for forwarding click on the insert rule to add the new rule.
Select the rule type as a path
  • Select the rule type as a path and enter /chat/* in the is under forward to select the target group as ChatService.
Insert one more rule having rule type as a path in the is enter /search/*
  • Insert one more rule having rule type as a path in the is enter /search/* and for the target group select SearchService.

Conclusion

After following this hodge-podge of steps, if you want to test if it works or not, copy the DNS name of the ALB, and paste it in the browser with /chat/ or /service/ at the end of the URL.

Enroll in the AWS Solution Architect Training Certification Course to learn directly from AWS Industry Experts & Get certified. Gain in-depth knowledge of all the topics covered in the real AWS Exam.