To understand vertical scaling and horizontal scaling better, let’s try to take a real-world example first, then we will go into the detail of these two types of scaling.
Imagine we have written some code inside our computer. It does the following things:
- Accepts the request from the client
- Processes it and
- Sends response back to the client
Now, the client is really impressed with our code so they decided to use it and are ready to pay us for it.
Now, let’s consider a scenario.
This application is running on our computer. We can’t give our computer to all the customers that they are wanting to use our code/application.
This is not possible and obviously, we don’t want to do this.
So, the alternate solution would be to expose our application/code running on the internet as an API and give access to all of our customers. That way the customer can send a request to our API. Our code processes it and sends a response back to the customer. This is fine.
What happens when there is a power cut or internet connection loss? In this case, the computer is not going to be accessible to the customers. Isn’t it?
And the important part is that we can’t afford to our service go down. Because our customers are paying money to us for the code/application we have written.
To solve this problem, we will go for the cloud.
The cloud is a set of computers that somebody/company provides us and we have to pay when we use it.
We don’t have to worry about the power cut or internet connection, security issues and etc when we are using the cloud.
Cloud providers like AWS will provide the set of computers that we can use to run our services. They will be taking care of the reliability of the server.
There could be a scenario when we have many customers using the application that we have built and this application is unable to handle all the requests coming from the clients.
Now we have two options:
- Buy a bigger machine or
- Buy multiple machines
The ability to handle more requests either by buying multiple machines or by buying a bigger machine is called scalability.
ScalabilityThe ability to handle more request either by buying multiple machines or by buying a bigger machine is called a scalability.
So the conclusion is we can handle more requests by spending more money. This is because we have to spend more money whether to buy bigger machines or to buy multiple machines.
Vertical scaling and horizontal scaling
When we buy a bigger machine it will have more processing and memory power so that it can process the request faster. This is called Vertical Scaling.
When we are buying more machines the request can go to any machine so the distributed request can reduce the request load to a single computer and process fast. This is called Horizontal Scaling.
This is called the scalability of the system. Which means being able to handle more requests.
Pros and Cons of Vertical and Horizontal Scaling
- If one server crashes some other will come up to solve the problem
- Scales well as the user increases
- Load balancing required
- More network calls
- Data inconsistency
- Inner process communication makes faster to process
- Hardware limit
- Single point of failure
- Because we only have a single machine if it crashes then the application will stop accepting the request.
Vertical scaling involves upgrading to a bigger machine with more processing power, while horizontal scaling requires adding multiple machines to distribute the request load. Horizontal scaling provides resilience and scales well with increasing users, but requires load balancing and may introduce data inconsistency. Vertical scaling offers faster processing and data consistency but is limited by hardware capacity and can become a single point of failure. Choosing between the two depends on specific system needs. Understanding these concepts helps make informed decisions for a scalable and reliable application.