Horizontal And Vertical Scaling

Why is Scaling needed?

When a System is incapable of performing well with the rapid increase in the queries to a system. A system can face downtime. That is when scaling is needed. We can use Horizontal or vertical scaling depending on the needs and specifications of our system.

A scalable system is one that can handle an increase in user requests and demand. Scalability is one of the important pillars of System Design.

So, one can scale the system to handle the increase in load. Either by scaling up(vertically) or by scaling out(horizontally).

Horizontal and vertical scaling
Horizontal vs Vertical Scaling

Horizontal Scaling

In horizontal scaling, the performance of a system is enhanced by adding one or more resources of the same type to the system. In other words, more machines are added to the existing pool of resources.
You might think how do they coordinate and distribute the work? The Load Balancer helps to distribute the requests(workload) evenly to the different servers based on their availability.

In horizontal scaling logic(or a task) is broken down into simpler sequential tasks so that they can be executed parallelly across multiple servers(machines).

A common way to implement horizontal scaling is database Sharding, in which large data is split across multiple database servers (or machines).

Vertical Scaling

Vertical scaling, also known as scaling up, is a method of increasing the capacity of a system by adding more resources, such as memory, CPU, or storage, to a single machine.

Vertical scaling is often used when a system is experiencing performance issues due to limitations in its current resources. For example, if a web application is struggling to handle an increasing number of user requests, increasing the amount of memory or CPU on the server may help to alleviate the performance issues.

Difference between Horizontal and Vertical Scaling

Horizontal Scaling
(scaling out)
Vertical Scaling
(scaling up)
Data LocationData is distributed across the nodes in a cluster. Data is stored on a single machine. An additional hard disk is added if more space is needed.
DowntimeYou don’t need to shut down the system while adding an additional machine to the existing system. So, zero downtime.Shut down might be required while upgrading the server/machine.
ConcurrencyWork can be distributed across the nodes, thereby reducing the load on a single machine.The system might need to rely upon multithreading for incoming requests.
Message PassingAs the data is distributed across the nodes, data sharing becomes complex.Data can be accessed easily as it is stored on a single machine.
ExamplesCassandraMongoDBGoogle Cloud SpannerMySQLAmazon RDS

Which scaling technique is better?

How do we decide which scaling technique to go with?

Well, it will depend on various factors. The decision between horizontal and vertical scaling should be based on a number of factors, including the specific needs and constraints of the system being designed, as well as the resources available to implement it. Some factors to consider include:

  1. Performance requirements: Horizontal scaling is generally more effective for improving performance in distributed systems, while vertical scaling is more effective for improving performance in single machines.

    Generally, horizontal scaling is more suitable for distributed systems that require the processing of large volumes of data or handle a high number of user requests. Vertical scaling is more suitable for systems that require high processing power or memory resources. Depending on the type of workload that the system is expected to handle, determine better suited scaling technique.
  2. Scalability requirements: Horizontal scaling typically provides better scalability, as it can be easier to add more machines to a system than to continually increase the resources of a single machine. So, depending on the expected growth of the system, determine whether horizontal scaling is likely to be needed in the future.
  3. Resource availability: Vertical scaling can be more expensive, as adding more resources to a single machine can be costly. Consider the resources available to implement the system, and determine whether the cost of vertical scaling is feasible given the budget constraints.
  4. Maintenance and management: Horizontal scaling can be more complex to manage, as there are more machines involved. Vertical scaling, on the other hand, can be simpler to manage, as there are fewer machines to maintain.
  5. Architecture and design: The architecture and design of the system may also influence the decision between horizontal and vertical scaling. For example, if the system is designed to be distributed from the ground up, horizontal scaling may be a better fit. On the other hand, if the system is designed to be centralized, vertical scaling may be a better fit.

Ultimately, the decision between horizontal and vertical scaling will depend on the specific needs of the system and the resources available to implement it. Careful consideration should be given to factors such as performance, scalability, resource availability, maintenance, and architecture when making this decision.