What is Scalability?
The ability to handle more requests by buying a bigger machine or buying more machines is called scalability.
Vertical Scaling
Vertical scaling refers to using a bigger machine and adding more power (like CPU, RAM, network bandwidth or storage) to handle requests much faster.
For example, let’s say your current system has an 8-core server capacity limit. You can upgrade it to a 32-core server with faster SSD storage.
Pros
- It is easier to implement.
- Upgrading hardware is easier than setting up brand-new servers.
- Easier maintenance.
- No load balancer is required because there is only a single machine.
- Data consistency is easier to maintain.
- Communication is inter-process, which is faster.
Cons
- We cannot keep making the machine bigger and bigger. Hardware limits come into the picture.
- Single point of failure - if one machine goes down, the entire website/app goes down.
Horizontal Scaling
Horizontal scaling means buying more machines. Requests can be sent to any of these machines, and the workload can be distributed across them.
Here, you can add four 8-core servers instead of one 32-core server.
A load balancer is required here.
Pros
- If one server/machine fails, requests can be redirected to another machine.
- We can add as many machines as needed, so it scales very well.
- Better for unknown or peak workloads.
- More resilient and fault tolerant.
- Can be more cost-effective in the long term.
Cons
- Maintenance is difficult because setting up and managing a distributed system is more complex than managing a single server.
- Maintaining data consistency across multiple servers is harder.
- Servers communicate with one another over the network, and that communication is comparatively slower.
- Inconsistency can arise when multiple servers try to handle and update the same data.
Which One Should You Choose?
It depends on your use case.
Choose vertical scaling if you want:
- better data consistency
- faster inter-process communication
- simpler setup and maintenance
Choose horizontal scaling if you want:
- better scalability
- resilience and fault tolerance
- support for unknown or peak workloads
In the real world, we mostly use both and try to get the best of both worlds.
Vertical scaling is usually cheaper in the short term, while horizontal scaling can be more cost-effective in the long term.
“Scaling is a journey, not a destination.” - Sahn Lam
Got any doubt or wanna chat? Reach out to me on linkedIn
Top comments (0)