DEV Community


Posted on

Horizontal scaling vs Vertical Scaling in System Design

Disclosure: This post includes affiliate links; I may receive compensation if you purchase products or services from the different links provided in this article.

horizontal scaling vs vertical scaling
image_credit -

Hello friends, 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 Monolithic 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.

You can also use system design cheat sheets like this one from Exponent for quick revision of key System design concepts for interviews.

system design cheat sheet

Difference between Horizontal and Vertical Scaling in System Design

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

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.

horizontal scaling in microservices

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.

load balancer vs API Gateway

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.

software architecture

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.

Database shards using Vertical scaling

Horizontal or Vertical Scaling? 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.

microservice scaling

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 this article which is full of free system design courses.

system design template
image_credit -

That's all about difference between horizontal and vertical scaling 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.

Top comments (4)

rushi_sutar profile image

Very well explained!

somadevtoo profile image


shyju profile image
Shyju Kanaprath

Could you explain how to scale a database instance horizontally?

somadevtoo profile image

Hello Shyju, to horizontally scale a database instance, consider employing techniques such as sharding, replication, or partitioning, which involve distributing data across multiple servers based on a chosen key or strategy.

Sharding breaks the database into independent pieces (shards), replication creates copies of the database on multiple servers, and partitioning divides large tables into smaller partitions. Load balancing, achieved through a load balancer, helps distribute queries evenly among multiple database servers, suitable for read-heavy workloads.

Alternatively, utilizing distributed databases, containerization with orchestration tools, and implementing caching mechanisms are effective approaches. These methods collectively enable the efficient handling of increasing data, traffic, or request loads while ensuring optimal performance and resource utilization