avatarSoma

Summary

The article discusses the differences between horizontal and vertical scaling in system design, particularly in the context of microservices.

Abstract

The article begins by explaining that horizontal and vertical scaling are two approaches to scaling any system, including microservices, to handle increased load or meet performance requirements. Horizontal scaling, also known as scale-out, involves adding more nodes or servers to distribute the load, while vertical scaling, or scale-up, involves adding more resources to a single node or server. The author then provides a detailed comparison of the two scaling methods, highlighting their differences in terms of scale-up vs scale-out, load balancing, scalability, architecture preference, handling load, complexity, and examples. The article concludes by stating that horizontal scaling is generally better for microservices in the cloud due to its flexibility and cost-effectiveness.

Opinions

  • The author believes that reading blogs and articles can give developers an edge in interviews by allowing them to use buzzwords and demonstrate their understanding of new concepts and terms.
  • The author suggests that horizontal scaling is more suitable for handling unpredictable or varying loads, while vertical scaling is more suitable for handling predictable loads.
  • The author notes that horizontal scaling can achieve higher levels of scalability than vertical scaling, as the number of nodes can be increased almost indefinitely.
  • The author states that horizontal scaling is commonly associated with distributed systems, while vertical scaling is usually associated with monolithic systems.
  • The author suggests that horizontal scaling can be more complex to implement than vertical scaling, as it often requires more sophisticated load balancing and coordination mechanisms between nodes.
  • The author notes that vertical scaling may not always result in a linear increase in performance, since additional nodes may introduce more overhead or communication delays.
  • The author concludes that horizontal scaling is generally better for microservices in the cloud due to its flexibility and cost-effectiveness.

Difference between Horizontal Scalability vs Vertical Scaling in System Design and Microservices

Hello folks , one question which I have been asked repeatedly on many System design and Java Developer interviews are how do you scale your system? In particular how do you scale your Microservices?

This is a great question to ask any experienced developers because its open ended and its gives an opportunity to candidate to express themselves and also interviewers to know more about their knowledge, experience, and thought process.

Thanks to my habit of reading blogs and articles, I feel I am little bit more familiar with new concepts and terms compared to my competition.

So, when I was first asked this question on senior Java developer role and I mentioned that there are two ways to scale your application either horizontally or vertically then the interviewer was really impressed because he himself have never heard about the term, even though he may be familiar with the concept and process.

Now, you can say that I got lucky which is true but I was able to make an impression because I read blogs and articles and I can use buzz words and demonstrate that I understand them.

In this article, I will tell you the exact difference between horizontal and vertical scaling and when to use one over other so that you can impress your interviews.

Also, In past few articles I have been sharing my experience on Microservices like 50 Microservices Interview questions, 10 Microservice design principles, and 10 Microservice Patterns which I shared earlier as well my article about SAGA Design Pattern and Monolitihic vs Microservices architecture.

Now, coming back to the topic, Horizontal scalability and vertical scalability are two approaches to scale any system including Microservices to handle increased load or to meet performance requirements.

The main difference between them lies in how they achieve scaling.

Horizontal scalability, also known as scale-out, scale your system by adding more nodes or servers to distribute the load across them.

Horizontal scaling is achieved by adding more identical machines to the existing system, which allows for better distribution of load and improved redundancy.

This was tough say 5 to 10 years ago when you have to manually acquire server and install all the software, create new configuration and deploy your application but now in this age of Cloud Computing and tools like Terraform, Ansible, and Puppet, you can easily add more machine for your application without much fuss.

On the other hand, vertical scalability, also known as scale-up, involves adding more resources (such as CPU, RAM, or storage) to a single node or server to handle increased load.

This approach allows for an increase in the capacity of an existing node, which can handle more requests.

So, that was the basic difference, I will show you more difference in a while but if you are preparing for Microservice interview, this is one concept I like you to learn and learn better.

By the way, If you are preparing for System design interviews and want to learn System Design in depth then you can also checkout sites like ByteByteGo, Design Guru, Exponent, Educative and Udemy which have many great System design courses and if you need free system design courses you can also see the below article.

Difference between Horizontal and Vertical Scaling in Microservices

Here are some additional points that differentiate horizontal scalability from vertical scalability:

Earlier, I have also shared 25 Advanced Java questions, 25 Spring Framework questions, 20 SQL queries from Interviews, 50 Microservices questions, 60 Tree Data Structure Questions, 15 System Design Questions, and 35 Core Java Questions for Java developer interview and if you are preparing for interview you can see them.

1. Scale up vs Scale out

Vertical scaling means adding more resources to single server while horizontal scaling means adding more instances that’s why vertical scaling is now as scale up and horizontal scaling is known as scale out.

2. Load Balancer

Horizontal scalability requires the use of load balancers to distribute incoming requests across multiple servers, while vertical scalability does not, which is often a deciding factor. If your architecture doesn’t permit load balancing then you only have to scale vertically.

3. Higher Scalability

Horizontal scalability can achieve higher levels of scalability as the number of nodes can be increased almost indefinitely, while vertical scalability has limitations due to the maximum capacity of a single node or server.

4. Architecture Preference

Horizontal scalability is commonly associated with distributed systems, while vertical scalability is usually associated with monolithic systems.

5. Handling Load

Horizontal scalability is more suitable for handling unpredictable or varying loads, while vertical scalability is more suitable for handling predictable loads.

6. Complexity

Horizontal scalability involves adding more nodes or servers to a system in order to handle increased load or traffic. However, horizontal scalability can be more complex to implement than vertical scalability, as it often requires more sophisticated load balancing and coordination mechanisms between nodes.

Additionally, horizontal scalability may not always result in a linear increase in performance, since additional nodes may introduce more overhead or communication delays.

On the other hand, Vertical scalability involves increasing the resources (such as CPU, RAM, or storage) available to a single server or instance in order to handle increased load or traffic.

The main advantage of vertical scalability is that it is often easier and less complex to implement than horizontal scalability, since it involves simply adding more resources to an existing system.

However, vertical scalability may be limited by the physical capacity of the hardware running the system, and may not be able to scale indefinitely. Additionally, vertical scalability can be more expensive than horizontal scalability, since it often involves upgrading to more powerful or specialized hardware.

7. Example

An example of horizontal scalability is a web application that utilizes a load balancer to distribute incoming requests across multiple web servers. As traffic to the application increases, additional servers can be added to the cluster to handle the additional load.

Similarly, one example of vertical scalability is a database system that uses sharding to partition data across multiple disks or storage devices within a single server. As the size of the database grows, additional storage devices can be added to the server to accommodate the additional data.

Which one is better for Microservices in Cloud?

In general, horizontal scaling is considered better for microservices in the cloud because it allows you to add more instances of the service to handle increased load.

With horizontal scaling, you can distribute the workload across multiple instances, which helps to ensure that the service remains available even if one instance goes down.

Additionally, horizontal scaling is more cost-effective because it allows you to add resources on an as-needed basis, rather than requiring you to invest in more powerful hardware upfront.

Vertical scaling, on the other hand, can be more expensive and less flexible because it requires upgrading the resources on a single instance to handle increased load.

This approach can result in downtime if the instance needs to be taken offline for maintenance or upgrades, and it may not be sufficient to handle sudden spikes in traffic.

However, vertical scaling can be appropriate in certain situations where the workload is predictable and consistent, and it may be more straightforward to manage a single, more powerful instance than multiple smaller instances.

System Design Interview Preparation Resources

If you are preparing for System design interviews and want to learn System Design in depth then you can also checkout sites like ByteByteGo, Design Guru, Exponent, Educative and Udemy which have many great System design courses and if you need free system design courses you can also see the below article.

That’s all about difference between horizontal and vertical scalability in context of System design and Microservices. Overall, both horizontal and vertical scalability have their own advantages and disadvantages, and choosing the right one depends on the specific requirements and constraints of the system being developed.

It is often a good idea to start with horizontal scaling and add more instances as needed, while keeping an eye on performance and costs.

Other Microservices articles yo may like to explore:

Java
Programming
Microservices
Software Development
System Design Interview
Recommended from ReadMedium
avatarKevin Wong
Uber System Design

Draft Notes

2 min read