How To Achieve High Availability(HA) In AWS

Introduction

The primary motive of the customer to move to the cloud is the high availability. Nowadays every customer wants their products and services available at any time from anywhere on any device. In this article, we are going to see how we can achieve High Availability(HA) so that the system can continuously scale up and down to accommodate customer demand without any loss.

How we can achieve HA?

We can achieve high availability for the web server by using Load Balancer, In the below example we created 3 public EC2 instances one is unhealthy means this instance is not up and running and the other two instances are healthy i.e up and running, and then create a load balancer and add all of the EC2 instances to the target groups of the load balancer and when load balance is created we get the automatic DNS name through which we can make our requests to the load balancer and load balancer automatically lands to the healthy instances and one whose state is unhealthy will not responds to the request and according to the load it automatic redirects to the particular instance which is healthy, with this we get the high availability of our web servers. so let's start with the tutorial.

First, we need to create EC2 instances and I already explained in my last article how to create EC2 instances different for both Private and Public subnets, you can check the article.

Step 1 - EC2 instances

This time I created 3 EC2 instances in different availability zones.

So why do I create 3 EC2 instances just to show how the load balancer is working, here I would make one EC2 instance unhealthy so that it does not receive the request from the load balancer and requests are coming only to the healthy EC2 instances.

Step 2 - Create Load Balancer 

Configure Basic Configuration and select the availability zone.

How To Achieve High Availability(HA) in AWS

This step is used to make the load balancer more secured, so as of this we continue with the default setting for this.

How To Achieve High Availability(HA) in AWS

I'm using the existing security group or you can create the new security group as per your requirements.

How To Achieve High Availability(HA) in AWS

Define your routings where requests route the targets to the target group with defined protocol and port.

How To Achieve High Availability(HA) in AWS

Register your Targets where the request lands, Load balancer starts routing the requests to these targets, these targets are basically the EC2 instances.

How To Achieve High Availability(HA) in AWS

Review your configuration and your load balancer is ready.

How To Achieve High Availability(HA) in AWS

So as of now I added only healthy instances to the Targets so let's add one more unhealthy instance so that you better understand how load balancer works.

You just need to edit the load balancer and in the target tabs, you can register and unregister your targets just like shown below.

How To Achieve High Availability(HA) in AWS

Now just hit your targets multiple times and you see your request never lands on the unhealthy target and the target reaches to other 2 instances.

When I hit request first time,

How To Achieve High Availability(HA) in AWS

When refreshed multiple times, Target changes automatically according to the availability 

How To Achieve High Availability(HA) in AWS

Summary

Hence by using the Load Balancer, you can achieve the High Availability (HA). Your request finds the healthy instance automatically if one of the instances is unhealthy for a particular period of time, then that instance is not available to fulfill the requests for that period of time.

I hope you like this article. Stay safe and learn more! 


Recommended Ebook

Printing in C# Made Easy

Download Now!
Similar Articles