AWS Architect Certification Training (87 Blogs) Become a Certified Professional
AWS Global Infrastructure

Cloud Computing

Topics Covered
  • AWS Architect Certification Training (78 Blogs)
  • AWS Development (7 Blogs)
  • SFDC Administration Foundation (1 Blogs)
  • Salesforce Admin and Dev Foundation (22 Blogs)
SEE MORE

Elastic Load Balancer Tutorial – One Step Solution For The Uncertain

Last updated on Nov 19,2024 11.4K Views

Priyaj Kumar is an AWS aspirant working as a Research Analyst at... Priyaj Kumar is an AWS aspirant working as a Research Analyst at Edureka. He is working on different AWS services and has good knowledge...
9 / 11 Blog from AWS Compute Services

In fiction, we find the predictable boring. In real life, we find the unpredictable terrifying. The best possible option is to be prepared for the uncertain. In this Elastic Load Balancer Tutorial, I’ll talk about how Load Balancer comes to the rescue in such vulnerable and uncertain situations.

Also, take a look at the AWS Training and Certification for an in-depth understanding of the concepts.

What Is Load Balancing?

Amazon provides its own service for load balancing known as “Elastic Load Balancer“. Let’s first talk about what is load balancing before digging into Elastic Load Balancer Tutorial.

Suppose you have an application deployed on an EC2 instance which is getting limited traffic and hence you’ve allocated only limited resources to it.

Traffic-routing - Elastic load Balancer Tutorial - Edureka

Fig 1 – Elastic Load Balancer Tutorial

But, what if you wake up one day and realize the tables have turned. What if, your application starts getting a lot of unexpected traffic? This is amazing, isn’t it? But is your application ready for it? Can it handle so much traffic?

Without-loadbalancer - Elastic Load Balancer Tutoarial - Edureka

Fig 2 – Elastic Load Balancer Tutorial

With the load balancing mechanism, yes!

life after load balancer - elastic load balancer tutorial - edureka

Fig 3 – Elastic Load Balancer Tutorial

The Load Balancer realized that there’s too much traffic on that one service and the application might end up crashing. AWS has the feature of scaling up or scaling down the resources. Load balancer automatically scales up your resource which is sufficient enough to handle the large incoming traffic. 

Load Balancing refers to efficiently distributing incoming network traffic across a group of backend servers in a manner that increases speed and performance.

The Elastic Load Balancer is similar to all the other load balancers. It basically serves the purpose of a single point of contact for the client. To make it simple, the client sends a request to the load balancer and it then distributes them to the targets like EC2, lambda function, etc in different Availability Zones.

There are three types of Elastic Load Balancers available. You can use the one best suited for your work. 

Classic Load Balancer(CLB)

This is the most basic form of the load balancer, that was used initially for classic EC2 instances. It is operated on connection level as well as request level. The main drawback of this type of load balancer is, it does not support features like host-based routing or path-based routing. Once the load balancer is configured, it balances load across the servers regardless of what is present on the server which might end up reducing the efficiency and performance in certain situations. 

Application Load Balancer

This type of Load Balancer is used when there are HTTP and HTTPS traffic routing. I’m sure you guys are aware of the OSI Model. This load balancer works at the Application layer of the OSI Model. It provides advanced routing features such as host-based and path-based routing. It also works well with containers and microservices. I’m going to show a demo on how to create an application load Balancer and demonstrate how the traffic is routed amongst the available servers further in this Elastic Load Balancer Tutorial.

Network Load Balancer

Network Load Balancer works at layer 4 of the OSI Model(connection level). Its mainly used for load balancing TCP traffic. This Load Balancer can handle millions of traffic and is best suited for maintaining low latencies. It’s capable of handling uncertain traffic while maintaining a static IP address. 

Now that you know what is a load balancer, let’s get to know why do we need it.

Need For Load Balancing

The main use for an Elastic Load Balancer is to make your resources highly available. There are four types of forwarding rules that a user can assign to a load balancer, and they can be broken down as follows:

  • HTTP
    It is the standard balancing request based on HTTP mechanism. It directs the traffic to the backend information for the original request.
  • HTTPS
    It is the same as the HTTP forwarding rule with an additional feature of encryption. Encryption here is handled in one of the two ways: SSL Passthrough (encryption is all the way to backend) and SSL termination (encryption is done by the load balancer). In SSL termination, the traffic is sent to backend unencrypted.
  • UDP
    A UDP Load Balancer uses User Datagram protocol which provides low latency for applications.
  • TCP
    TCP is used for Load Balancing all the applications that do not use protocols like HTTP and HTTPScing.

Now that you understand the working of a load balancer, let’s learn the algorithms that govern load balancing. Let me guide you through each of the algorithms used for load balancing.

Algorithms Used For Load Balancing

  • Round Robin
    It is the simplest algorithm used to distribute the client’s request across a group of servers. Round Robin will first traverse the list of server in the group and then forward the client request to each server one by one and once it reaches the end of the list, it will again start from the top of the list. There are two variations of the Round Robin algorithm:
    • Weighted Round Robin: Weight is assigned to each server based on some criteria and servers are chosen accordingly.
    • Dynamic Round Robin: Weight is assigned dynamically based on real-time data like current load and idle capacity.
  • Least Connections
    When a load balancer is configured to use the least connection algorithm, it selects a server with the least number of connections to serve the request. This way it ensures that the load is balanced equally among the servers.
  • Source
    This algorithm basically selects a server based on a hash of source IP requests e.g. Client’s IP address. This way Source Algorithm makes sure that the request from a particular IP is served by a particular server only.

Interesting, isn’t it? These are the different algorithms that work on the backend to make your service available.

Let’s move further and create a Web page and use a load balancer to make it highly available.

Demo: Create An Application Load Balancer

It this demo, I will create 2 EC2 instances and will make them work like servers. I will then host a Web page on each of them. By using a load balancer, I will handle the request to my web page. So, let’s dig deep into this load balancer tutorial and find out how to implement the above-said scenario.

Step 1: Create an EC2 Instance.

Choose EC2 in AWS Console like shown below.

Create ec2 - Elastic Load Balancer Tutorial - Edureka

Click on “Launch Instance” to launch an instance.

Create EC2 Instance -Elastic Load Balancer Tutorial - Edureka

Select the “Amazon Machine Image” best suited for you. For this demo, I’ve used the Amazon Linux 2 image, as highlighted in the image below.

Create EC2 Instance - Elastic Load Balancer Tutorial - Edureka

Choose the “Type of Instance“. In this case, I’ve used t2.micro.

Create EC2 Instance - Elastic Load Balancer Tutorial - Edureka

Configure the “Instance Details“. Add the number of instances you wish to create and choose the network and the subnet you wish to use.

Create EC2 Instance - Elastic Load Balancer Tutorial - Edureka

Now “Add Storage“. You will not require more than 8GB for this Demo. 

Create EC2 Instance - Elastic Load Balancer Tutorial - Edureka

You can “Add Tags” to identify your instances. This step is optional. 

Create EC2 Instance - Elastic Load Balancer Tutorial - Edureka

You have to “Configure Security Group” and make sure you have permissions for SSH, TCP & HTTP.

Create EC2 Instance - Elastic Load Balancer Tutorial - Edureka

Click on “Review Instance Launch” to launch the instance.

Create EC2 Instance - Elastic Load Balancer Tutorial - Edureka

The final step “Choose a Key Pair or create a new key pair“. You can either choose from an existing key pair or create a new key pair which is required to create an instance.

Create EC2 Instance - Elastic Load Balancer Tutorial - Edureka

Step 2: Access your Instance.

See how to access your EC2 instance using Putty here.

Step 3: Install “HTTPD” in your instance. Here are the commands you need to run.

$ sudo yum install httpd
$ sudo service httpd start
$ sudo chkconfig httpd on
$ sudo service httpd status

Step 4: Create an HTML file named “index.html”

Here is the code I used.

<html>
<head>
<h1>Hello Community!</h1>
<h2>This is our First Server</h2></head>
<body bgcolor="#98fb98">
<a href="https://www.edureka.co/community/"&amp;gt;Visit Edureka | Community /a>
</body>
</html>
<html>
<head>
<h1>Hello Community!</h1>
<h2>This is our Second Server</h2></head>
<body bgcolor="#5DBCD2">
<a href="https://www.edureka.co/community/" Visit Edureka | Community /a>
</body>
</html>

Use the same file just change the server’s number so that you can understand how is your request served.

Step 5: Create a “Load Balancer“.

Navigate to “Load Balancing” and click on “Create Load Balancer“.

Create Load Balancer - Elastic Load Balancer - Edureka

Select the “Load balancer type“. In this case, I’ve used the HTTP/HTTPS.

Create Load Balancer - Elastic Load Balancer - Edureka

You have to “Configure your load balancer“. Add name, Schema and IP address type(which is IPV4) in this case.

Create Load Balancer - Elastic Load Balancer - Edureka

Select your VPC for “Configure Load Balancer“. Add your VPC and Availability Zones.

Create Load Balancer - Elastic Load Balancer - Edureka

Now you have to “Configure Security Settings“. You’ll be prompted a warning as displayed in the picture below. This warning is just to let you know that you should use HTTPS instead of HTTP.

Create Load Balancer - Elastic Load Balancer - Edureka

To configure Security Groups, start by assigning a security group.

Create Load Balancer - Elastic Load Balancer - Edureka

Now the main part, “Configure Routing“. Configure the routing as shown below in the image.

Create Load Balancer - Elastic Load Balancer - Edureka

Now, just add your instance, i.e. “Register Targets“.

Create Load Balancer - Elastic Load Balancer - Edureka

The final step “Review” all the settings if they’re fine.

Create Load Balancer - Elastic Load Balancer - Edureka

Now, wait for 3-5 mins for the load balancer to configure.

Step 6: Select the DNS from the description. Paste it as a URL in your browser.

Web Page - Elastic Load Balancer - Edureka

And you should see something similar to the above image. It says “This is our First server”, indicating the web page got deployed on the first server. Hit “Refresh” and you’ll find another page(shown in the image below) being displayed which shows that the web page got deployed on the second server. 

Web Page - Elastic Load Balancer - Edureka

You can see how Load balancer diverts the traffic to different servers to service the request from users. I hope you liked this blog about “Elastic Load Balancer Tutorial“. For more such blogs, visit “Edureka Blog“.

If you wish to learn more about Cloud Computing and build a career in Cloud Computing, then check out our Cloud Computing Courses which comes with instructor-led live training and real-life project experience. This training will help you understand Cloud Computing in depth and help you achieve mastery over the subject.

Got a question for us? Please mention it in the comments section and we will get back to you or post your question at Edureka Community. At Edureka Community we have more than 1,00,000+ tech-fanatics ready to help.

Upcoming Batches For AWS Certification Training
Course NameDateDetails
AWS Certification Training

Class Starts on 21st December,2024

21st December

SAT&SUN (Weekend Batch)
View Details
AWS Certification Training

Class Starts on 4th January,2025

4th January

SAT&SUN (Weekend Batch)
View Details
AWS Certification Training

Class Starts on 13th January,2025

13th January

MON-FRI (Weekday Batch)
View Details
Comments
0 Comments

Join the discussion

Browse Categories

webinar REGISTER FOR FREE WEBINAR
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.

image not found!
image not found!

Elastic Load Balancer Tutorial – One Step Solution For The Uncertain

edureka.co