• Backend Weekly
  • Posts
  • Part 4: Understanding System Design - Load Balancers

Part 4: Understanding System Design - Load Balancers

You will learn everything you need about load balancers, their Benefits, Load Balancing Algorithms, Load balancing Balancers vs. Reverse Proxy, and more.

Hello “👋”

Welcome to another week, another opportunity to become a Great Backend Engineer.

Today’s issue is brought to you by GetBackendJobs, a platform that helps you unlock your Backend Career by providing tailored Backend Jobs and the Perfect Backend Talent to companies.

Before we get down to the business of today. Part 4 of Understanding System Design.

I have a gift for you: You will love this one.

If you’re looking for the perfect backend jobs or your company wants to hire the best backend engineers.

Then GetBackendJobs is the platform to find tailored backend jobs posted by real companies.

Start applying to backend roles at GetBackendJobs now.

If you want to hire backend engineers, click “Hire Backend” to post your job at a 100% discount.

Now, back to the business of today.

In the previous edition, I will discuss one of the system's components, starting with Proxies. I explored Proxies, forward and reverse proxies. I shared comprehensive differences and benefits of each type of proxy. Check it out here if you haven’t.

In this episode, I will further elucidate another system component to help you understand System Design.

We will look at Load Balancers.

You will learn everything you need about load balancers, their Benefits, Load Balancing Algorithms, Load balancing Balancers vs. Reverse Proxy, and more.

What is a Load Balancer?

When the number of requests in an application increases, it can overload a server, affecting system performance.

A single server has limited throughput and resources.

For example, an online marketplace like Amazon. During Black Fridays or the Christmas season, it experiences an unusual surge in traffic. It’s only a matter of seconds before the server gets overloaded. Therefore, scale is needed to handle the increased demand effectively.

Scaling can be done vertically or horizontally. A load balancer is needed to scale horizontally.

A load balancer is a device used to distribute application traffic across several servers. It improves the overall performance of a system by distributing the traffic to different servers, decreasing the burden on a single server.

A load balancer sits between clients and servers. It routes clients’ requests between servers, ensuring that no single server is overworked, which could make an application unavailable and unreliable.

Load Balancers

Hardware vs Software Load Balancing

Load balancers typically come in two flavors: software-based or hardware-based. Hardware-based load balancers are physical devices, often with specialized processors and proprietary software customized for load balancing.

On the other hand, software-based load balancers run on commodity hardware, and you can install any type of software load balancer, which makes them less expensive and more flexible.

Benefits of load balancers

  1. Scalability—It enables an application to handle a traffic spike effectively, maintain smooth operation, and respond quickly to clients. This makes the application highly available and reliable.

  2. Fault Tolerance—Having multiple servers in your infrastructure can eliminate a single point of failure. A load balancer will route traffic to an available server when one server fails, achieving redundancy.

  3. Avoiding Downtime—A load balancer will enable you to perform server maintenance without downtime by automatically routing traffic to other available servers. This will reduce application downtime and improve system availability.

  4. Improved Security—A load balancer can mitigate DDoS attacks. It routes traffic across the servers in case of a traffic surge. This will protect your application availability, giving the load balancer time to determine whether a spike in traffic is legitimate or not. It also offers a traffic scrubbing effect by blocking malicious requests.

  5. SSL Decryption - A load balancer can handle incoming HTTPS connections, decrypting and passing the unencrypted requests onto the web servers. This eliminates the need to install SSL certificates in different back-end web servers by providing a single configuration point. It also takes the processing load of encryption and decryption away from the web servers.

Load Balancers vs Reverse Proxy

Both components sit between clients and servers, accepting requests and delivering responses from the former. The two are mostly similar. However, a load balancer is commonly deployed when an application needs multiple servers for scalability. A reverse proxy can also be used even in cases where a single server is in place.

Load Balancers are key components in improving a system's performance. They ensure high application availability and reliability by distributing traffic so that no single server gets overloaded, giving users a good user experience.

Load Balancing Algorithms

Load Balancing Algorithms

Effective load balancers will intelligently determine which server should process a user request in a server pool using different algorithms. A load-balancing algorithm is a load balancer's logic that distributes incoming traffic between servers.

The following are examples of load-balancing algorithms:

Round Robin

The load balancers queue and direct client requests in a round-robin fashion. The first request goes to the first server, the second to the second server, and so on.

When the load balancer reaches the end of the list, it directs a request back to the first server. The round-robin approach is easy to implement and evenly distributes the traffic across all servers.

However, there is a risk that a server with low capacity receives many requests and becomes overloaded because the algorithm does not consider the server’s capacity. The algorithms work well in a server pool with the same processing power.

Weighted Round Robin

This algorithm is an advanced version of the round-robin Algorithm. It distributes the traffic based on the servers' weight scores. For instance, if server one is twice as powerful as servers two and three, it is provisioned with a higher weight than servers two and three.

When there are 5 sequential client requests, the load balancer routes 2 requests to server A, 1 to server B, and 3 each, and the last request is routed to server A again.

The bigger the server, the more requests there are to handle.

IP Hash Algorithm

The client and destination IP addresses generate a unique hash key to allocate users to a specific server. If a session is broken, the key can be regenerated, and the user will be redirected back to the server. It has the advantage of caching, as the server caches data for that specific user.

This algorithm is appropriate in scenarios where a client needs to return to the same server for each successive connection.

Least Connection

This algorithm checks which server has the fewest current connections opened and sends traffic to that server. Like the round-robin approach, it assumes all the servers have equal processing power.

Weighted Least Connection

This algorithm is an advanced least connection method that assigns different server weights depending on the processing power. The algorithm will decide where to route the traffic depending on active connections and the weights of servers. If two servers have the least number of connections, the server with the highest weight is chosen.

Weighted Response Time

It averages the response times for all the servers with the number of active connections each server has to determine where to route the request. The algorithm ensures faster service for the user by determining the server with the quickest response time.

Random Algorithm

This algorithm uses a random number generator to distribute client requests to the servers randomly. The algorithms assume the servers have similar configurations.

That’s all

Today, I discussed Load Balancers. I introduced you to everything you need to know about them, including their Benefits, Load Balancing Algorithms, Load balancing Balancers vs. Reverse Proxy, and more.

Next week, I will cover a very important topic in System Design: Distributed Caching.

DON’T LEARN ALONE. SHARE THIS NEWSLETTER WITH YOUR FRIENDS

I hope this guide gives you perspective on Load Balancers.

That will be all for this one. See you on Saturday.

Don’t forget to get the Larafast Boilerplate. It comes with unmatched benefits for building products in days.

Top 5 Remote Backend Jobs this week

Here are the top 5 Backend Jobs you can apply to now.

👨‍💻 SMG Swiss Marketplace Group
✍️ Backend Engineer (PHP/Symfony)
📍Remote, Serbia
💰 Click on Apply for salary details
Click here to Apply for this role.

👨‍💻 Shift Technology
✍️ Backend Engineer: Hybrid
📍Remote, Paris, France
💰 Click on Apply for salary details
Click here to Apply for this role.

👨‍💻 Scalable GmbH
✍️ Backend Engineer - Product Foundation (m/f/x)
📍Remote, Germany, Austria
💰 Click on Apply for salary details
Click here to Apply for this role.

👨‍💻 SmartBear
✍️ Backend Engineer- ReadyAPI
📍Remote, Poland
💰 Click on Apply for salary details
Click here to Apply for this role.

Want more Remote Backend Jobs? Visit GetBackendJobs.com

Backend Engineering Resources

Whenever you're ready

There are 4 ways I can help you become a great backend engineer:

1. The MB Platform: Join 1000+ backend engineers learning backend engineering on the MB platform. Build real-world backend projects, track your learnings and set schedules, learn from expert-vetted courses and roadmaps, and solve backend engineering tasks, exercises, and challenges.

2. The MB Academy:​ The “MB Academy” is a 6-month intensive Advanced Backend Engineering BootCamp to produce great backend engineers.

3. MB Video-Based Courses: Join 1000+ backend engineers who learn from our meticulously crafted courses designed to empower you with the knowledge and skills you need to excel in backend development.

4. GetBackendJobs: Access 1000+ tailored backend engineering jobs, manage and track all your job applications, create a job streak, and never miss applying. Lastly, you can hire backend engineers anywhere in the world.

LAST WORD 👋 

How am I doing?

I love hearing from readers, and I'm always looking for feedback. How am I doing with The Backend Weekly? Is there anything you'd like to see more or less of? Which aspects of the newsletter do you enjoy the most?

Hit reply and say hello - I'd love to hear from you!

Stay awesome,
Solomon

I moved my newsletter from Substack to Beehiiv, and it's been an amazing journey. Start yours here.

Join the conversation

or to participate.