Load balancing distributes incoming client traffic across multiple servers to prevent any single server from becoming overwhelmed, while also enabling high availability by rerouting connections when a server goes offline. Balancing methods range from static assignment and round-robin to dynamic approaches that factor in real-time resource utilization.
Load Balancing
We set up redundancy amongst our servers and services to make sure we maintain high availability. One of the things that can help facilitate that is load balancing.
If we have a web application and users are connecting into our servers, we want to maintain high availability, so we're going to create redundancy amongst our servers. But how do we connect our client machine to those servers? What I mean by that is that they're usually connecting into one of those servers, and it goes by IP address. So it's connecting into an IP address and making a connection to that IP address. What happens when the IP address of that server goes down and it needs to fail over or connect to a different server? That becomes problematic.
A load balancer helps solve this problem. A load balancer is what makes a connection between a computer, a client machine, and the servers. What it's going to do is connect this user into one of the options for the servers.
In my mind, the primary purpose for a load balancer is not for high availability, although it can do that and we'll talk about that. The primary reason for a load balancer is to distribute the load. What does that look like? Here we have multiple servers that are running right here. These could be geographically distributed, or it could be in one location; there are lots of setups with this. But this load balancer is designed to distribute the load amongst these different servers.
What do I mean by that? Let's say we have 90 customers that are connecting into our servers. If we were to just connect all 90 customers to one server, then that could possibly overwhelm that server. So what we do is we turn up many servers here, and now what this helps us do is set up 30 of those users to go to one server, and then another 30 is going to go to another server, and another 30 is going to go to another server. We're balancing the load of how many clients we have amongst the resources we have, and in this case it's these servers.
Now, as a repercussion, we can implement high availability. If this is load balancing amongst three servers and we've got 30 clients going to each of these servers, and then let's say one of those servers goes offline, now we can redistribute these clients to the new servers. So now, instead of 30 being at each of these servers, maybe we have 50 being at each one of these servers, 50 clients each. We've redistributed it because something went offline, and now we can create high availability with it. So it might be the purpose for some of us to implement load balancing for high availability, but I don't see that as necessarily being the primary purpose for load balancers.
How is a client going to make a connection into the server? What it's going to do is maybe some sort of DNS resolution, and it's going to get an IP address back. That IP address is the IP address of the load balancer. It's going to make a connection into that load balancer, and then from that load balancer it's going to be redirected to the proper server.
This connection could happen in one of two ways. Number one, the load balancer could tell the client, yeah, this is the server you're connecting to; there are some technologies that work that way. A lot of the load balancers that I've worked with have just made the connection directly into the server and then grabbed the information and sent it back to the client. That's what it's doing a lot of times: it's just acting as — I guess you can make the analogy of a router — kind of routing the information between this server and this client.
A load balancer is going to have to make a decision on which server it's going to connect a client to. The client is going to reach out to the load balancer, and the load balancer has to decide, okay, what server am I going to connect you to? There are several methods that it can use to do this. It could statically set this up, it could use round robin, or it can do dynamic load balancing.
One way you could do this is statically. You choose something that you're going to base this information off of. Maybe it's an IP address, maybe a MAC address, perhaps it's a certain client. That was one of the ways I thought about engineering something: when a client makes a connection, they are going to get routed to a specific server and use a specific server, and then a different client might use a different server. But this is not typical, because, as the name states, it's static and so it's not dynamic, and that can be problematic.
Round robin, from my experience, has been the most prevalent, the most used, but it does have a problem. It's simple, so that's great. But the problem exists when you have users that are connecting. What they're doing is using resources: maybe it's some sort of bandwidth, maybe it's CPU power, whatever the case may be. Each client is going to use a different set of resources, different amounts of CPU and bandwidth and so on and so forth. Because of that, if you are just doing this round robin, what's going to happen is that there is going to be an unequal distribution over time, and one of your servers is going to be more used than the other servers. This could be problematic or not problematic, and it's going to go by time depending on the duration that your users are connecting to it and some other variables. But essentially, you're going to not have an even distribution of it, so it can be problematic.
That's where dynamic load balancing comes in. It's more complex. This load balancer might be understanding how many connections are coming into the server, or maybe it's understanding what the CPU processing power is or what the bandwidth is. It's understanding some sort of variables about these clients and how each one of these servers is being worked. Based off of that information, it's making an educated decision on where it should send the next client to. There can still be some little inequalities that can happen between these servers at that point, but it's going to be less likely, because it's dynamically balancing this load based off of the usage of the resources of these different servers.
Load balancing actually comes in many different forms. We see it from a hardware perspective, a software perspective. There are application load balancers, there are DNS load balancers. There are many different load balancers that are out there, so just realize that there are different types of load balancers.
How does a load balancer implement high availability? What's going to happen with this load balancer is it's going to monitor these different servers and see what is available and what isn't available. If one of them goes down, then it's just going to send any additional traffic to one of these other servers. Clients that are already connected in are going to have to be distributed amongst these servers that are still up. So that's how high availability works.
But then the question is, how is it going to monitor these servers? Somehow it needs to make a connection and monitor to see if the server is even up and running. I'll mention one of the ways that I've done this in the past. I've hosted out websites — usually these are application servers, that's mainly what I'm talking about right here — and so these are application servers that are hosting some sort of websites. Then I will have a page that marks if the service is healthy or not healthy. It's a simple web page that says either healthy or unhealthy. This load balancer is then going to ask that web page, hey, are you still up? If it gets a healthy back, then it's going to assume that that server is up and running and is healthy. But if it reports that it's unhealthy, or doesn't come up at all, then it's going to take it out of this load balancing, so it's no longer going to be an option for load balancing. So it's got to monitor this web page to see if it's up and running or not.
TechKnowSurge builds IT and cybersecurity professionals through hands-on, concept-first training built around real understanding — not memorization. Free interactive tools, structured programs, and 25+ years of real-world experience, all in one place.
Explore free tools and programs →