Scaling infrastructure horizontally

While both vertical and horizontal scaling options help us deal with increased load on the system, in this post, we will explore scenarios where horizontal scaling is the better choice.

Vertical and Horizontal scaling are two approaches to deal with increased load on the system. While Vertical scaling involves adding more resources such as CPU, RAM, or storage to an existing machine, horizontal scaling involves adding more devices to the overall platform.

While both approaches have their advantages, there are situations where vertical scaling is not a suitable option. In the last couple of years, I had this discussion multiple times with my colleagues and clients where they are not in favor of increasing infrastructure footprint and are more inclined towards expanding the overall system capacity by adding more resources like CPU, memory, etc.

Vertical Scaling

Vertical scaling aims to make the existing machine more powerful and capable of handling more workload.

One of the main advantages of vertical scaling is its simplicity. It requires minimal changes to the existing infrastructure and no additional configuration or management. Additionally, vertical scaling is often the cheaper option for small-scale systems.

However, there are limitations to vertical scaling. The most significant limitation is that there is a physical limit to how much a single machine can be scaled. In addition, once you’ve maxed out a machine’s resources, you can no longer add any more capacity, which can be a problem for systems that need to handle large workloads or have a high degree of variability in their traffic (unpredictable spikes in traffic).

Another limitation of vertical scaling is that it can result in a single point of failure. If the single machine that has been vertically scaled fails, the entire system will go down.

Horizontal Scaling

In contrast, horizontal scaling involves adding more machines to the system to increase its capacity. It can include adding more servers, virtual machines, or containers to the system. The goal of horizontal scaling is to distribute the workload across multiple machines, making the system more resilient and scalable.

One of the most significant advantages of horizontal scaling is that it provides almost unlimited scalability. As long as resources are available, you can continue adding more machines to the system and increase its capacity. Additionally, horizontal scaling provides redundancy, meaning that the system can continue to function even if one machine fails.

However, horizontal scaling can be more complex and expansive than vertical scaling. It requires additional configuration and management to ensure the workload is evenly distributed across all machines.

When is Horizontal Scaling Better?

Consider a scenario where your application is supposed to handle 1200 queries per second. To address this load, you have two machines that can handle 1000 queries per second.

Suppose one of those machines went down, forcing the other to handle the entire workload. This additional workload of 600 QPS is beyond its capacity (by 200 qps) and hence will be rejected. Additionally, this can overwhelm the remaining machine, which can also crash under this additional load.

Two node setup

Let’s consider another setup with four nodes, each capable of handling 500 queries per second. Again, the load balancer in front is responsible for evenly distributing the traffic (i.e., 300 QPS to each node).

Four node setup

Now, even if one of these nodes goes down, the system can continue to work as the remaining nodes still have sufficient resources to handle the additional traffic evenly distributed by the load balancer.

Four node setup with node failure

Conclusion

Vertical and horizontal scaling have their advantages, and the choice between them depends on the system’s specific requirements. While vertical scaling is simple and inexpensive, it has limitations in terms of scalability and redundancy. Horizontal scaling, on the other hand, provides virtually unlimited scalability and redundancy but comes with higher maintenance costs.


That is all for this post. If you want to share any feedback, please drop me an email, or contact me on any social platforms. I’ll try to respond at the earliest. Also, please consider subscribing feed for regular updates.

Be notified of new posts. Subscribe to the RSS feed.