In our work as testers or performance engineers, we encounter the concept of load balancing at almost every turn. Most people are familiar with the basic definition, but when detailed discussions about the operation of the load balancer itself begin, misunderstandings arise. Therefore, I decided to delve into the topic by analyzing the types of load balancers to the algorithms that work differently for each of them.
But before we begin, let's talk about what load balancing is.
What is load balancing?
Load balancing is a bit like having several waiters in a restaurant and wanting all guests to be served equally quickly and efficiently. If too many guests come to one waiter, he will be overwhelmed and won't be able to serve them all in time. To prevent this, the "manager" (in this case, the load balancer) allocates guests to different waiters in such a way that each of them has roughly the same amount of work. In the computer world, the "guests" are requests from users, the "waiters" are servers, and the "manager" is the load balancer, ensuring that no server is overloaded. That's what load balancing is all about.
Types of Load Balancing
Depending on the technology we work with or the project we are in, we encounter different types of load balancing. Load balancer types are distinguished based on their application in the network.
For instance, load balancing can be used at the DNS level. In this case, the Domain Name System directs traffic to different servers by assigning various IP addresses to a domain name. This method is often used to direct traffic to servers in different geographic locations.
Another case is load balancing at the application level. Traffic is distributed between different application servers based on various factors such as server load, user sessions, or the type of request. This is particularly popular in environments where different servers are optimized to handle different types of tasks.
Yet another instance is load balancing at the transport layer level (often referred to as layer 4 in the OSI model). The most popular protocols used at this level are TCP and UDP. The load balancer in this case makes decisions based on information such as the source IP address and the destination port.
The main idea is to understand that load balancing is not limited to just redirecting traffic through an application. Of course, this case is often talked about the most, as developers and testers are most closely associated with it.
Load Balancing Methods (Algorithms)
Load balancers have different algorithms, making them function differently. Their use depends on the requirements of the project. Let's look at a few of them.
The first one is the Round Robin Algorithm. With it, traffic assignment to servers happens in sequence. The request goes to the first available server, and then that server moves to the end of the queue.
The Least Connections algorithm, on the other hand, directs traffic to the server with the least load. It works well during peak hours, as it evenly distributes traffic.
The Least Response Time algorithm checks two things: which server is less busy and which responds the fastest. The quickest server gets the job first.
Meanwhile, the IP Hash algorithm works in such a way that a user's computer address is assigned to a single server to ensure smooth operation.
Session Persistence
There's another aspect worth mentioning when discussing load balancing. Session persistence (sometimes also called sticky session) refers to the practice of routing a user's requests to the same backend server throughout the duration of a session. When users interact with a load balancer, it redirects traffic (individual requests) to a specific server. Standard algorithms of load balancers direct traffic to different servers each time, thus generating considerable traffic that can negatively impact performance.
Some load balancers, however, can maintain a persistent session (session persistence). This entails directing traffic (all requests) consistently to the same server. This server might already have cached information, enabling faster responses to be sent back to the user. This approach fosters greater efficiency.
The connection to a specific server is established through methods such as cookies or by recognizing users' IP addresses, among other mechanisms.
Summary
I hope that all the discussed information regarding load balancing will be useful to you. My intention was for you to expand your theoretical knowledge so that you can apply it in your work.
Top comments (0)