{"id":1744,"date":"2021-08-12T09:59:06","date_gmt":"2021-08-12T01:59:06","guid":{"rendered":"https:\/\/www.layerstack.com\/blog\/?p=1744"},"modified":"2021-08-12T09:59:06","modified_gmt":"2021-08-12T01:59:06","slug":"load-balancers-algorithms-what-are-they-and-how-do-they-work","status":"publish","type":"post","link":"https:\/\/www.layerstack.com\/blog\/load-balancers-algorithms-what-are-they-and-how-do-they-work\/","title":{"rendered":"Load Balancers Algorithms: What are they and how do they work?"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.layerstack.com\/blog\/wp-content\/uploads\/2021\/08\/layestack-load-balancers-algorithm-02-1024x536.jpg\" alt=\"LayerStack Load Balancers Algorithm\" class=\"wp-image-1748\" title=\"LayerStack Load Balancers Algorithm\" \/><\/figure>\n\n\n\n<p>An essential triage to internet traffic with <a href=\"https:\/\/www.layerstack.com\/blog\/layerstack-load-balancers-support-global-private-networking-and-ddos-protection\/\">practical security features<\/a>, load balancers is the gatekeeper that directs web-based traffic to the best available servers for optimal application efficiency. This process involves different algorithms, all come with unique pluses. And in this post, you will read all about them so you can <a href=\"https:\/\/www.layerstack.com\/blog\/layerstack-load-balancers-use-cases\/\">make the most of our balancers<\/a>.<\/p>\n\n\n\n<p><strong>Round Robin<\/strong><\/p>\n\n\n\n<p>This is the most common algorithm where all available servers form a queue. When a new request comes in, the load balancers forward it to the first server in the queue. Upon the next request, the balancers distribute the traffic to the next server in the list.<\/p>\n\n\n\n<p>The below diagram gives you a picture of how this works. Say we have an environment with three available servers, the first client\u2019s request (1) received by the balancer is assigned to server 1. The next request (2) is then assigned to the next server in turn, namely server 2. When the balancer finishes routing the third request and reaches the bottom of the server list, it directs the next client (4) to the first on the list again, which is server 1. And the cycle continues.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a href=\"https:\/\/www.layerstack.com\/blog\/wp-content\/uploads\/2021\/08\/Round-Robin-1024x633.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.layerstack.com\/blog\/wp-content\/uploads\/2021\/08\/Round-Robin-1024x633.jpg\" alt=\"LayerStack Load Balancers Algorithm: how does round robin work\" class=\"wp-image-1749\" width=\"630\" height=\"389\" \/><\/a><\/figure>\n\n\n\n<p>It is the simplest and the easiest algorithm to be implemented where each server handles a similar amount of workload, making sure there is no overload or starvation of server resources.<\/p>\n\n\n\n<p><strong>Least Connections<\/strong><\/p>\n\n\n\n<p>The name says it all \u2013 the balancers monitor the current capacity of each available server, and assigns new requests to the one with the fewest active connections.<\/p>\n\n\n\n<p>In the diagram below, servers 1 and 2 are serving a higher demand of requests. Therefore, when client 1 comes in, their request is directed to server 4 as it is currently idle. The next client (2) is assigned to server 4 as it is now one of the two servers (3 and 4) with the least connections. Now, with server 4 having two connections while server 3 having just one, the third incoming client request is routed to server 3 \u2013 the one with the least active connections.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a href=\"https:\/\/www.layerstack.com\/blog\/wp-content\/uploads\/2021\/08\/least-connections_revised-1-1024x633.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.layerstack.com\/blog\/wp-content\/uploads\/2021\/08\/least-connections_revised-1-1024x633.jpg\" alt=\"LayerStack Load Balancers Algorithm: how does least connection work\" class=\"wp-image-1750\" width=\"630\" height=\"389\" \/><\/a><figcaption>les<\/figcaption><\/figure>\n\n\n\n<p>This intelligent mechanism ensures all requests are handled in the most effective manner possible, and is more resilient to heavy traffic and demanding sessions.<\/p>\n\n\n\n<p><strong>Source-based<\/strong><\/p>\n\n\n\n<p>In similar nature to least-connection, source-based algorithm pairs certain requests with the client\u2019s IP address. Once you set up the rules in the LayerPanel, our load balancers will route the workloads accordingly.<\/p>\n\n\n\n<p>For instance, the balancer recognizes the IP address that you have previously specified, and autonomously directs the requests from that specific client to a specific server \u2013 server 2 \u2013 in the diagram below. When the same client returns a few days later with a new request, the balancer recognizes its IP address and will distribute the request to the same server.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a href=\"https:\/\/www.layerstack.com\/blog\/wp-content\/uploads\/2021\/08\/layerstack-weighted-distribution-06-1-1024x632.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.layerstack.com\/blog\/wp-content\/uploads\/2021\/08\/layerstack-weighted-distribution-06-1-1024x632.jpg\" alt=\"LayerStack Load Balancers Algorithm: how does source work\" class=\"wp-image-1753\" width=\"630\" height=\"388\" \/><\/a><\/figure>\n\n\n\n<p>This algorithm provides you with the flexibility to group certain application-specific tasks together or slightly tailor the environment best to process specific requests. This allows your application to handle requests with desirable resources and reach desirable, more predictable results.<\/p>\n\n\n\n<p>Want more details on how to configure Load Balancers for LayerStack\u2019s cloud servers? Read our <a href=\"https:\/\/www.layerstack.com\/resources\/tutorials\/How-to-configure-Load%20Balancers-for-Cloud-Servers\">tutorials<\/a> and <a href=\"https:\/\/www.layerstack.com\/resources\/docs\/?cid=load_balancers\">product docs<\/a>.<\/p>\n\n\n\n<p><strong>Related Content:<\/strong><\/p>\n\n\n\n<div><ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.layerstack.com\/resources\/docs\/?cid=load_balancers\">Load Balancers Overview<\/a><\/li><li><a href=\"https:\/\/www.layerstack.com\/resources\/tutorials\/How-to-configure-Load%20Balancers-for-Cloud-Servers\">How to configure Load Balancers for Cloud Servers<\/a><\/li><li><a href=\"https:\/\/www.layerstack.com\/blog\/layerstack-load-balancers-use-cases\/\">Load Balancers Use Cases<\/a><\/li><li><a href=\"https:\/\/www.layerstack.com\/blog\/layerstack-load-balancers-support-global-private-networking-and-ddos-protection\/\">LayerStack Load Balancers support Global Private Networking and DDoS Protection<\/a><\/li><\/ul><\/div>\n\n\n\n<p>If you have any ideas for improving our products or want to vote on other ideas so they get prioritized, please submit your feedback on our <a href=\"https:\/\/community.layerstack.com\/\">Community platform<\/a>. Feel free to pop by our community.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An essential triage to internet traffic with practical security features, load balancers is the gatekeeper that directs web-based traffic to the best available servers for<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-1744","post","type-post","status-publish","format-standard","hentry","category-product-insight"],"_links":{"self":[{"href":"https:\/\/www.layerstack.com\/blog\/wp-json\/wp\/v2\/posts\/1744","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.layerstack.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.layerstack.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.layerstack.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.layerstack.com\/blog\/wp-json\/wp\/v2\/comments?post=1744"}],"version-history":[{"count":0,"href":"https:\/\/www.layerstack.com\/blog\/wp-json\/wp\/v2\/posts\/1744\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.layerstack.com\/blog\/wp-json\/wp\/v2\/media?parent=1744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.layerstack.com\/blog\/wp-json\/wp\/v2\/categories?post=1744"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.layerstack.com\/blog\/wp-json\/wp\/v2\/tags?post=1744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}