Vertical and Horizontal scaling
As your application grows and experiences more traffic, your original infrastructure might not handle the increased load. It’s in your business’s interest to scale your application to manage the higher traffic and ensure its availability.
Scaling is a fundamental part of modern system design. It involves increasing your resources to handle more traffic, which also helps maintain service health and high availability.
But when you were to scale your application, there are two different scaling mechanisms that you can use to scale your application.
Vertical Scaling
Horizontal Scaling
Vertical Scaling
It is a scaling method where we increase the size of the resources vertically, adding more computing power(CPU, RAM, Memory, etc) to the existing server or instance.
A simple upgrade of an EC2 instance from t2.micro
to m5.large
will come under Vertical Scaling.
Advantages of vertical scaling
Cost-effective — Adding more computing to the existing server can cost less compared to buying a new one.
Less maintenance — The maintenance can be very cheap as there are very less servers that you need to manage.
Disadvantages of vertical scaling
If you do not have a backup server that can handle traffic, you will face downtime if the server goes down or during a server upgrade.
Having all your traffic served on a single server increases the risk of losing all your data if a hardware or software failure was to occur.
Horizontal Scaling
It is a scaling method where we increase the number of servers horizontally by adding more servers to the existing application to distribute the load.
Like adding more EC2 instances behind an AWS Elastic Load Balancer to serve traffic can be considered as Horizontal Scaling.
Advantages of Horizontal Scaling:
Less downtime — As you are adding more instances for the application, there would be very little to zero chance of downtime. In case one instance goes off, there is already another instance ready to serve traffic.
Distributing the data and operation among multiple instances saves from losing the data, proving fault tolerance and high resilience.
As more nodes are available to server traffic, the traffic can be delegated to multiple instances and it increases application performance.
Disadvantages of Horizontal scaling
Adding more servers comes with more increased costs.
Also adding more servers results in high maintenance. Also, you have to manage Load Balancers for traffic distribution to instances.
What to choose?
Like for every engineering question, the answer is “IT DEPENDS”. There is no one size fit for your needs, each scaling method has its advantages and disadvantages. It is you and your business that can make the decision on which scaling method to use. Here are some factors that you can consider:
Cost: Horizontal scaling adds cost coz you are adding more servers for your application. If you are on a tight budget, adding more computing to your instance makes more sense.
Reliability and performance: Horizontal scaling gives a more robust and reliable solution. It decreases the risk of downtime and increases performance.
Maintenance: While Vertically scaled instances can be easier to maintain it can introduce downtime while doing software patches or system updates etc. With horizontal scaling, you should not worry about downtime but it adds more complexity to the overall infrastructure.
Future proof: Horizontal scaling is more future-proof compared to Vertically scaled ones coz there would be a limit on how much computing you can increase for a server.