paint-brush
Decoding Load Balancing Primitivesby@fairday
39,946 reads
39,946 reads

Decoding Load Balancing Primitives

by AlekseiFebruary 26th, 2024
Read on Terminal Reader
Read this story w/o Javascript

Too Long; Didn't Read

When scaling your system to accommodate increased traffic and users, you can choose between vertical scaling, which boosts server power, and horizontal scaling, which involves duplicating servers. While vertical scaling is simpler, it has limitations like hardware constraints. Horizontal scaling with load balancers offers flexibility but requires managing statelessness and deploying strategies. Understanding L4 and L7 load balancers is essential, with L4 being more secure and performant, while L7 offers intelligent routing at the expense of efficiency. Choosing the right approach depends on system requirements and balancing security and performance considerations.

People Mentioned

Mention Thumbnail
featured image - Decoding Load Balancing Primitives
Aleksei HackerNoon profile picture


Whenever your system grows, traffic increases, more and more users use your products, servers begin to respond slower, downtime forces your business to suffer then you start to think about scaling.


There are two primary strategies for scaling - vertical and horizontal.


Vertical scaling intends to increase the system’s power by adding usually more CPU, and RAM to your servers.


In contrast, horizontal scaling focuses on duplicating (or cloning) your servers in the pool of resources.


More on these:


Vertical scaling

Vertical scaling is the best option for a low-traffic system because it’s the most accessible approach for handling growth without introducing additional complexity. You don’t need to care about deploying strategies for a group of resources, the elasticity of the resources pool, the statelessness of your server, the distributed cache, and so on.


However, vertical scaling has serious drawbacks

  1. Hardware limit since it’s impossible infinitely to add resources
  2. Lack of failover and redundancy raises the risk of having prolonged downtime and loss of data


Horizontal scaling

Horizontal scaling eliminates these problems by cloning your application servers and embedding a component such as a Load balancer.


A load balancer distributes traffic on your servers using specific algorithms such as:


  1. Round-robin
  2. Weighted round-robin
  3. IP hash-based approaches
  4. Least connection method
  5. Weighted least connection method
  6. Least response method, and many others.


Nevertheless, it has several drawbacks:


  1. Servers have to be stateless
  2. Sessions have to be persisted in a centralized data store
  3. More complicated deploying strategies may be required
  4. A load balancer can become a performance bottleneck if it’s misconfigured and resources are not enough
  5. It introduces additional complexity to the system and stands as a potential single point of failure, which requires applying failover strategies


L4 / L7 Load balancers

For two devices on the internet to communicate with each other, underlying systems have to follow specific protocols. Everyone heard about the OSI model, which describes seven layers that computer systems use to communicate over a network. Although the modern internet is based on a simpler TCP/IP protocol stack model, the OSI model is widely used, as it helps visualize and communicate how networks operate and helps isolate and troubleshoot networking problems.


Most industry load balancing solutions use the terms L4 and L7 where L4 refers to the transport layer in OSI model and L7 refers to the application layer.


The L4 load balancer is still L2/L3 since it uses data from the bottom layers such as IP address and port number.


Main advantages of L4 load balancer

  • It is more secure and performant since data content is not taken into making routing decisions

  • The same TCP connection holds between client and server, which helps to prevent exceeding the limit of available TCP connections on a load balancer


Main disadvantages of the L4 load balancer

  • Intelligent routing is impossible since the content is not decrypting
  • Stateful protocol brings additional complexity
  • Mapping between public and private addresses
  • No caching since the content is unavailable on this level
  • Not possible to use for microservices architecture since traffic redirection is not available based on url path


On the other hand, the L7 load balancer operates on the application level in OSI model


Main advantages of L7 load balancer

  • Smart decisions can be made based on URL path, headers, content

  • Caching


Main disadvantages of L7 load balancer

  • Additional overhead due to the maintaining of two TCP connections, one between client and load balancer, the second one between the load balancer and server. Also, the load balancer TCP connection limit needs to be considered
  • Less secure since the load balancer must know certificates to be able to decrypt data and make routing decisions


Conclusion

Load balancer is a vital component when horizontal scaling is applied to handle high-traffic systems. There are two main types of load balancers L4 and L7.


  1. L4 load balancer is much more secure and performant due to limitations of making smart decisions

  2. L7 load balancer operates in a way to provides intelligent routing decisions due to the cost of efficiency and security


Choosing the appropriate type depends on the system requirements and should be considered carefully with a reasonable balance of applying security principles and eliminating performance bottlenecks.


Also published here.