At its core, a load balancer is like a traffic guard who lays down traffic cones, waves flags, and puts up warning signs to redirect the flow of traffic when there’s congestion or trouble ahead. Instead of directing vehicular traffic on the road, however, it directs web traffic in a network. A load balancer’s primary duty is to share the burden of servers carrying heavy loads with less occupied servers so that no single server gets overloaded.
We recently added layer 4 and layer 7 load balancers to our Bare Metal Cloud service . Read on to see how they compare and how they work.
Layer 4 load balancers
A layer 4 load balancer, also called NLB (network load balancer), works at the transport layer (or 4 in the OSI model). This layer handles device-to-device communications. It breaks down messages into segments (small chunks of data), then sends those segments to be further broken down in layer 3 before delivery.
A layer 4 load balancer only cares about the delivery of the messages and not their content. In other words, it’s not context aware. It directs traffic using only network-relevant information like IP (internet protocol) addresses and port numbers. It looks at the first few packets in a stream and uses a load-balancing algorithm to calculate the best route for delivery. Layer 4 load balancers prioritize routing to servers that are the least loaded based on the number of active connections (how many requests the server is working on) or their response times (how busy the server is).
An example of an algorithm that’s often used in layer 4 load balancing is known as round robin. Round robin works by routing requests to destination servers in the order that they’re received. If a website is stored between three servers, round robin will direct the first request to server 1, the next to server 2, and the third to server 3. It then continues this process, cycling through the three servers to ensure that requests are split evenly among them to prevent an overload.
You can think of a layer 4 load balancer as the clerk who directs impatient shoppers (traffic) to empty, or the shortest available lines (best servers) near the checkout area of a department store (network). Because this clerk is not context aware, they can direct traffic very quickly as they only need to account for the lengths of the lines at the registers.
Layer 7 load balancers
A layer 7 load balancer, also called ALB (application load balancer), on the other hand, works at the application layer (OSI 7, the topmost layer). The application layer supports end-user applications to display words, numbers, and images so that it can be understood by people.
In contrast to a layer 4 load balancer, a layer 7 load balancer is context-aware and looks at the metadata that includes the host, HTTP header (information about the client browser, server, requested pages, etc.), and other relevant data within the messages. As a result, it balances using a much more involved process that includes pausing network traffic to read the contents, then making new connections or reusing existing ones, when applicable, to deliver messages to the most suitable servers.
You probably know that websites often contain static content (images and videos), and dynamic content (forms to fill out and real-time news feeds). What you might not know is that when you visit a website, the individual elements that make up the page you’re browsing are probably loading from different servers.
If you’re on a popular website that gets a ton of daily traffic, for example, a layer 7 load balancer helps keep your experience stable by routing content from the most suitable servers before they’re loaded onto your device. Images and videos might come from a storage server that’s most equipped to handle static content. Forms and news feeds might come from an application server that’s better suited for dynamic content - like processing your form submissions and updating those news feeds.
In the department store scenario above, you can think of a layer 7 load balancer as the clerk who directs confused shoppers (traffic) in the store (network) to the most suitable checkout line (best servers) according to what and how much the customer is buying, or if the customer is actually here to return products. Unlike the layer 4 clerk above, this layer 7 clerk is context aware and manages the lines according to multiple variables. Because this clerk has so much to account for, they take a bit longer to direct traffic.
Load balancers make Bare Metal Cloud even better
You can now add load balancers to your bare metal instances to improve the scalability, reliability, and flexibility of your network. To learn more about how they help reduce your operation and opportunity costs, check out this product update article!