DEV Community

Discussion on: Explain Load Balancers Like I'm Five

Collapse
 
slavius profile image
Slavius • Edited

It's all about scaling. There are 2 types of scaling:

  • Vertical - you keep adding resources to your single system until you run out of space - e.g. until you have no more free memory slots to expand your RAM or ports free to connect another hard drive
  • Horizontal - you keep adding more small autonomous systems, each having it's own portion of resources that in sum give you the power you need. You can do this as long as you have physical space which is very efficient.

Load Balancers come in play when you scale horizontally. The individual systems are called nodes in load balancer terminology.

Generally you put load balancer in front of these nodes to handle all the work first. Then the load balancer decides how to spread the load across all nodes.

Features of the load balancer can be summed up as:

  • balancing the load across available nodes
  • keeping information about health of nodes (doing regular health checks) to prevent routing requests to dead nodes - this allows an awesome way to do maintenance because you can mark nodes as inactive while doing the maintenance and/or reboots and the application still works by serving requests from other active nodes
  • keeping information about the load on each node (CPU load, RAM usage, number of active connections, number of connections/second to each node) to prevent overloading already heavily used nodes
  • keeps track of sessions (based on source IP address+port or HTTP cookie) to route the same client always to the same node (necessary if the remaining nodes are not session aware - imagine you log in to an application and then your next request would be redirected to a different node that has no idea you were already authenticated - you would end up on login screen again ending in a loop)
  • offloading - load balancer can take over responsibility of compressing resources and sending them to end clients leaving more CPU power for application servers. The same way it can terminate and negotiate HTTPS sessions, which is also expensive because of SSL/TLS cryptography happening for each client. Similarly load balancer can also cache frequently used resources in memory or on a fast storage to prevent retrieving them from nodes all the time.

TL;DR
Load balancers [can] make your service more reliable, easily scalable, more performant and resilient to outages.