What is a Load Balancer?

Imagine a salesman at a store helping customers. If only a few customers show up, the salesman can easily manage them. But if a big crowd comes in, the salesman will struggle to help everyone. This leads to long wait times, poor customer service, and ultimately unhappy customers.

Now, what if you could hire multiple salesmen and have a manager who distributes the customers evenly to each available salesman? This way, no single salesman gets overwhelmed, and all customers get help efficiently. That's exactly what a Load Balancer does in the tech world!

In the context of AWS, the Elastic Load Balancer (ELB) is like that manager. Instead of customers coming into a store, we have requests coming to your application or website. If your application (salesman) is overloaded, the ELB distributes the traffic to multiple servers (salesmen), ensuring everything runs smoothly.

Optimize Traffic with Load Balancers | Salesforce Trailhead


Key Concepts of AWS ELB

  • Elastic: Means it can automatically adjust (scale) based on the number of requests, so it can handle increasing traffic without breaking a sweat.

  • Load Balancer: Distributes incoming traffic across multiple servers (EC2 instances) to ensure no single server is overwhelmed.


Real-Life Example: Job Platform

You’re running a job platform where companies post job listings, and job seekers visit the site to search for and apply for jobs. Typically, your platform handles a manageable number of users, but every now and then, you host a large job fair event, or a high-profile company posts new positions, drawing thousands of job seekers to your site at the same time.

Without a Load Balancer, your single server (EC2 instance) might struggle to keep up with all these users, leading to slow load times or even a site crash, which could frustrate job seekers and harm your platform's reputation.

With AWS ELB:

Here’s how it works:

  1. You set up multiple EC2 instances (servers) to handle the website’s traffic.

  2. The AWS Elastic Load Balancer (ELB) is deployed in front of those instances to evenly distribute the incoming traffic among them.

So, during busy periods—such as when a popular company posts jobs or you host a career event—the ELB ensures that no single server is overwhelmed. This allows your platform to run smoothly, handling all the traffic efficiently. Even if one of your servers has issues, the ELB automatically directs users to the healthy ones, ensuring high availability.


How AWS ELB Works

  1. Client Traffic: Requests from clients (like browsers) come to the Load Balancer.

  2. Traffic Distribution: The Load Balancer intelligently distributes the traffic across multiple healthy EC2 instances (servers) behind it.

  3. Monitoring: It monitors the health of the EC2 instances to make sure traffic is only sent to healthy, working instances.

  4. Auto-Scaling: As traffic increases, you can configure it to automatically launch more EC2 instances to handle the load (like hiring more salesmen during a sale). When traffic decreases, it scales down to save costs.


Types of AWS Load Balancers

AWS provides different types of ELBs, each suited for different use cases:

  1. Application Load Balancer (ALB):

    • Best for web applications that use HTTP/HTTPS.

    • Can route traffic based on content, such as different URLs or API calls.

    • Example: Let’s say your online store has a shop section and an admin section. The ALB can route all customer traffic to one set of servers, while admin traffic goes to another.

  2. Network Load Balancer (NLB):

    • Best for high-performance applications with low latency and high throughput.

    • Ideal for applications using TCP/UDP.

    • Example: In cases where you’re running a real-time financial app where performance is key and downtime is not acceptable.

  3. Classic Load Balancer (CLB):

    • The older type of load balancer.

    • Operates at both the request (HTTP/HTTPS) and connection levels (TCP).

    • Example: If you’re running an older application that doesn’t need the advanced features of ALB or NLB.


How ELB Solves Real-Life Problems

Let’s go back to the salesman example:

  1. Avoid Overload: Just like how one salesman can’t handle 100 customers, one server can’t handle thousands of users. ELB makes sure no server gets overwhelmed.

  2. Ensure Uptime: Imagine one of your salesmen is on a break. The manager (ELB) will stop sending customers to him and will direct them to the other available salesmen (healthy servers). This is like monitoring in ELB, where traffic is only sent to healthy instances.

  3. Efficient Resource Use: With ELB, you don’t need to keep all your servers running 24/7. During quieter hours, the load balancer ensures that traffic is distributed to fewer servers (saving costs), and when there’s a lot of traffic (like a sale), it will automatically scale up and use more servers.


Benefits for Your Job Platform:

  • No Downtime During Peak Traffic: Your job platform stays up and running even during peak traffic, ensuring job seekers can search for and apply to jobs without interruption.

  • Better User Experience: Faster load times and fewer errors mean users will have a smoother experience, which is especially important for job seekers during critical application periods.

  • Scalability: As your platform grows, the ELB can automatically scale up by launching additional servers to handle increasing traffic.

By leveraging AWS ELB, your job platform can serve thousands of users during busy times, without you having to worry about crashing servers or poor user experience.


Step-by-Step: How to Set Up an AWS ELB

Step 1: Launch EC2 Instances

Before you can load balance traffic, you need servers (EC2 instances). For simplicity, let’s assume you’ve already launched a couple of EC2 instances running a web server like Node.js or Apache.

Step 2: Create a Load Balancer

  1. Open the EC2 Dashboard in AWS Management Console.

  2. On the left panel, click Load Balancers under Load Balancing.

  3. Click Create Load Balancer.

  4. Choose the type of load balancer (let’s go with Application Load Balancer here).

    New – Application Load Balancer Simplifies Deployment with Weighted Target  Groups | AWS News Blog

    • Name: Give it a name like my-app-lb.

    • Scheme: Choose Internet-facing if your application is public.

    • Listeners: Select HTTP or HTTPS based on your app.

Step 3: Configure Load Balancer

  1. Availability Zones: Select the VPC and availability zones where your EC2 instances are running. This ensures redundancy, meaning if one zone fails, your app is still accessible from another.

Step 4: Configure Security Groups

  1. Assign a security group to the load balancer that allows HTTP/HTTPS traffic (Port 80/443).

    • This is like saying "Allow customer traffic into the store."

Step 5: Register Targets (EC2 Instances)

  1. Select the EC2 instances you want to load balance and register them as targets.

    • This step is like telling the load balancer (manager), "Here are the servers (salesmen) that will handle traffic."

Step 6: Review and Create

  1. Review all settings and click Create.

Now, your ELB is live! All traffic to your application will now be distributed across your selected EC2 instances.


Real-Life Examples in Action

Online Store Example

During a holiday sale, your website gets 100,000 visitors. Without a load balancer, your single server (EC2 instance) crashes because it can’t handle the load. With an ELB, traffic is distributed across multiple EC2 instances, and more instances are spun up automatically as traffic increases. As a result, your site runs smoothly, and you avoid downtime.

Corporate Example

Your company has a web-based HR system. Different departments use the system, but there are peak times (e.g., end-of-month payroll). The ELB can automatically adjust to handle this increased traffic, ensuring employees don’t experience delays.


When to Use AWS ELB?

  1. Handling High Traffic: If you expect a large number of users visiting your website or app.

  2. Ensuring Redundancy: If you want to make sure your app doesn’t go down if one server crashes.

  3. Auto-Scaling: When you need to scale your application seamlessly based on demand.

  4. Disaster Recovery: To prevent system failures from affecting your application’s availability.


Conclusion

AWS Elastic Load Balancer (ELB) is like having a traffic manager for your application. It ensures that no single server is overwhelmed, traffic is distributed efficiently, and your application remains available and scalable no matter how many requests come in.

So, whenever you're building a highly available system or app, AWS ELB is the go-to solution to keep your users happy and your system running smoothly! 😊