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

Main disadvantages of the L4 load balancer

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

Main advantages of L7 load balancer

Main disadvantages of L7 load balancer

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.