AWS: What Is Load Balancing?

Siddhant Singh
The Startup
Published in
4 min readJul 23, 2020

Recently started reading a lot about AWS and doing some practical things to be in hand-on touch with the concept. After reading about IAM user and EC2 I got to this interesting topic which I can be really important when you’re building a highly distributed system.

So it comes down to two things. This will be some basic before we start with the main topic but it kind of relates to that. I’m talking about scalability and high availability.

Scalability means that an application can handle greater loads by adapting some techniques. There are two kinds of scalability:-

  1. Vertical Scalability

Vertical scalability means increasing the size of the instance. For example, your application runs on a t2.micro but scaling that means running it on a t2.large.

RDS, ElastiCache are services that can scale vertically. There’s usually a limit to how much you can vertically scale(hardware limit).

2. Horizontal Scalability

Horizontal Scalability means increasing the number of instances for your application. This is very common for web applications.

Horizontal scaling implies distributed systems.

High Availability

High availability means running your application in at least 2 data centers (Availability Zones). The goal of high availability is to survive a data center loss.

What is Load balancing?

Load balancers are servers that forward internet traffic to multiple servers (Ec2 instances) downstream.

Why should we use a load balancer?

So we can spread the load across multiple downstream instances. Also, we can expose a single point of access (DNS) to your application. Basically we don’t need to know about the whole backend for EC2 we only want to know about the hostname of the load balancer.

It will also do the regular health checks to your instances and it will know when to send the load on the instances. It can provide SSL termination (HTTPS) for your websites.

A load balancer can be highly available across zones.

Health Checks

Health checks are important for Load Balancers. They enable the load balancer to know if instances it forwards traffic to are available to reply to requests. It can be done on a port and a route. If the response is not 200, then the instance is unhealthy.

Load Balancer will check the port 4567 to check the EC2 instances. If it is healthy 200 (Ok). Then it will be able to send a request. The best thing is you can configure this to how many seconds you want to check the instance again. Let’s say if I have set it up for 5 sec then it will check the instance every 5 seconds.

All these benefits you get it with AWS and will cost much less.

Types of load balancer on AWS

AWS has 3 kinds of managed Load Balancers

  1. Classic Load Balanced 2009

HTTP, HTTPS, TCP

2. Application Load Balancer 2016

HTTP, HTTPS, WebSocket

3. Network Load Balancer 2017

TCP, TLS(secure TCP) & UDP

Types of Load Balancer

Overall, it is recommended to use the newer generation of load balancers as they provide more features. As you can see they are not even suggesting the CLB there.

Another thing is you can set up two types of load balancers internal(private) or external(public) ELBs. Internal means it will be from your account and you cannot access it from the public web. External will allow users to access your website through a load balancer.

Deep Dive into Load Balancer

So here as you can see how users are talking to load balancer through HTTPS/HTTP from anywhere. 0.0.0.0/0 means from anywhere. We have set both HTTP and HTTPS in our load balancer security group.

Now the interesting part is we have to see here is usually all the traffic from HTTPS and HTTP goes directly but now there is a load balancer is between them. So EC2 instance expects the traffic coming from load balancer only. That’s why we set the Application Security Group. So the source id which you’re looking at there is a reference to the load balancer which we have set above.

Troubleshooting

  1. 4xx errors are client induced errors.
  2. 5xx errors are application induced errors.
  3. Load Balancer 503 means at capacity or no registered target.
  4. If the LB can’t connect to your application, check your security group.

Thanks for reading. For the next part, I will go in detail about the CLB, ALB, and NLB.

--

--

Siddhant Singh
The Startup

Into Data Science, Machine Learning and Data-Driven Astronomy. If I’m not writing code, I might be reading some random stuff.