How do you scale a component? - rnakidi/dsa GitHub Wiki
How do you scale a component?
There are three points that I consider:
✅ Vertical Scaling vs Horizontal Scaling
The easiest way to scale a component is vertical scaling.
Think bigger RAM. A larger disk or CPU.
It's cost-effective in the short term. Plus, you avoid dealing with distributed stuff.
But it becomes expensive in the long run and doesn't help you get rid of single points of failure.
This brings us to Horizontal scaling i.e. scaling a component by adding more machines.
✅ Horizontally Scaling Stateless Apps
A stateless component doesn't save the client data from one session for use in the next session.
This makes it easier to scale horizontally.
You can use a load balancer to distribute requests between multiple stateless components.
Of course, it becomes important to build the services in a stateless manner.
✅ Horizontally Scaling Stateful Components
A stateful component saves data from one session to the next one.
For example, a web application that stores the session info. Or a database/key-value store.
For scaling out stateful components, we've to adopt techniques like replication, sharding, and so on.
👉 TL;DR
-
Vertical scaling is less complex and you should stay with it for as long as possible. It can also be sufficient for a majority of the apps.
-
Think horizontal scaling when vertical is no longer cost-effective.
-
Try to build your application layer in a stateless manner so that it's easy to scale out.
-
For stateful components like databases, choose modern options designed for horizontal scalability. It will make your life easier.