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 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
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:
Nevertheless, it has several drawbacks:
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.
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
On the other hand, the L7 load balancer operates on the application level in OSI model
Smart decisions can be made based on URL path, headers, content
Caching
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.
L4 load balancer is much more secure and performant due to limitations of making smart decisions
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.