Horizontal scaling vs Vertical Scaling in System Design
Tags: programming, systemdesign, microservices, development
Published: 2024-02-29 07:06:35

---
title: Horizontal scaling vs Vertical Scaling in System Design
published: true
description: Horizontal scaling is achieved by adding more servers while vertical scaling is achieved by adding more computing resources like CPU and memory in existing servers
tags: programming, systemdesign, microservices, development
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2024-02-29 06:45 +0000
---
*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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k8rzlzzxfubdxndnkcae.png)](https://bit.ly/3P3eqMN)
image_credit - [DesignGuru.io](https://bit.ly/3pMiO8g)

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](https://medium.com/javarevisited/50-microservices-interview-questions-for-java-programmers-70a4a68c4349), [*10 Microservice design principles*](https://medium.com/javarevisited/10-microservices-design-principles-every-developer-should-know-44f2f69e960f), and [*10 Microservice Patterns*](https://medium.com/javarevisited/top-10-microservice-design-patterns-for-experienced-developers-f4f5f782810e) which I shared earlier as well my article about [SAGA Design Pattern](https://medium.com/javarevisited/what-is-saga-pattern-in-microservice-architecture-which-problem-does-it-solve-de45d7d01d2b) and [Monolithic vs Microservices architecture.](https://medium.com/javarevisited/difference-between-microservices-and-monolithic-architecture-for-java-interviews-af525908c2d5)

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](https://medium.com/javarevisited/5-free-courses-to-learn-terraform-in-2023-best-of-lot-b5ae51147eee), [Ansible](https://medium.com/javarevisited/5-best-ansible-courses-for-devops-engineers-cc87692fdf52), and [Puppet](https://medium.com/javarevisited/7-best-puppet-online-courses-for-system-administrators-and-devops-engineers-889b5ab8aeca), 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**](https://bit.ly/3P3eqMN), [**Design Guru**](https://bit.ly/3pMiO8g), [**Exponent**](https://bit.ly/3cNF0vw), [**Educative** ](https://bit.ly/3Mnh6UR)and [**Udemy** ](https://bit.ly/3vFNPid)which have many great System design courses. 

You can also use system design cheat sheets like this one from [Exponent](https://bit.ly/3cNF0vw) for quick revision of key System design concepts for interviews. 



[![system design cheat sheet](https://miro.medium.com/v2/resize:fit:1100/format:webp/1*xVGZFSssAGB_KsraJAiEQA.png)](https://bit.ly/3cNF0vw)

------

## 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](https://miro.medium.com/v2/resize:fit:609/1*nCV6savg7lmS-iu79rzS4w.png)

------

### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i4ybzycs717bapr4o2r6.png)](https://medium.com/javarevisited/difference-between-api-gateway-and-load-balancer-in-microservices-8c8b552a024)


------


### 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 ](https://miro.medium.com/v2/resize:fit:609/1*ecD6CpB8b37WHTOVt0iayA.png)](https://javarevisited.blogspot.com/2022/08/top-7-websites-to-learn-system-design.html)

------

### 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](https://medium.com/javarevisited/what-is-database-sharding-scaling-your-data-horizontally-1dc12b33193f)** 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wygahrpdhpyboq7m6xvg.png)](https://medium.com/javarevisited/top-3-system-design-cheat-sheets-templates-and-roadmap-for-software-engineering-interviews-53012952db28)

-----


## 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](https://miro.medium.com/v2/resize:fit:609/1*ecD6CpB8b37WHTOVt0iayA.png)](https://medium.com/javarevisited/7-free-microservices-courses-for-java-programmers-c9b2f3a2ea7d)

------

### 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**](https://bit.ly/3P3eqMN), [**Design Guru**](https://bit.ly/3pMiO8g), [**Exponent**](https://bit.ly/3cNF0vw), [**Educative** ](https://bit.ly/3Mnh6UR)and [**Udemy** ](https://bit.ly/3vFNPid) 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](https://medium.com/javarevisited/hello-guys-if-you-are-preparing-for-system-design-interview-or-just-want-to-improve-your-software-7bc0034ac015). 

[![system design template](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d4xodzii0gfk357zaqv8.jpg)](https://bit.ly/3pMiO8g)
image_credit - [DesignGuru.io](https://bit.ly/3pMiO8g)

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.