TOUSEEF
Horizontal vs Vertical Scaling

Horizontal vs Vertical Scaling

October 23, 2023
|
System Design

Introduction

Horizontal scaling and vertical scaling are two methods that comes into picture, when there is a need to enhance the performance or capacity of a computer system due to increased demand, larger data handling, or more complex tasks.

Lets take a real-world example:

Imagine your computer is like a chef in a kitchen, cooking up different dishes (tasks) for customers (users). Sometimes, the chef needs help to handle more orders efficiently. That's where scaling methods come in - it is like adding more chefs to the kitchen, but in different ways.

Horizontal Scaling: Think of this like adding more chefs to the kitchen team. When there are too many orders (tasks), you hire more chefs (servers). Each chef handles a specific part of the workload. It's like teamwork, where everyone does a little bit, making the kitchen (system) faster and more efficient. If one chef needs a break (fails), others can still cook, so the customers (users) don't have to wait too long.

Vertical Scaling: In this case, you're making your chef (computer) stronger and more efficient. You might give the chef a bigger stove (more processing power), a larger chopping board (extra memory), or a bigger pantry (additional storage). This way, the chef can handle more ingredients (data) and cook more complicated dishes (tasks) all by himself. It's like making one chef super skilled and powerful to manage bigger cooking challenges.

So, horizontal scaling is like hiring more chefs for teamwork, while vertical scaling is like making your chef super skilled and equipped.

Lets get deep dive into technicalities!

Vertical Scaling

Vertical scaling simply means increasing the capacity of a single server or resource. This is typically done by adding more processing power (CPU), memory (RAM), or storage capacity to an existing server.

Vertical scaling is also known as scaling up.

vertical scaling

In vertical scaling we upgrade our existing computer or resource by

Use Case Of Vertical Scaling

Advantages of Vertical Scaling

  1. Simplicity: It is straightforward and easy to implement, as it involves upgrading individual components within an existing server.

  2. Cost-Effective for Incremental Growth: It is more cost-effective for moderate upgrades, especially to the cost of purchasing & setting up entirely new servers.

  3. Minimal Changes to Infrastructure: It requires minimal changes to the existing system architecture, making it a convenient option for systems that are already in place.

  4. Resource Optimization: It maximizes the use of existing resources, especially when a specific component (like CPU or RAM) is the bottleneck rather than the entire system.

  5. Reduced Complexity in Management: Upgrading a single server is simpler to manage than dealing with a cluster of multiple servers.

Limitations of Vertical Scaling

  1. Finite Capacity: There is a limit to how much a single server can be upgraded. Eventually, the server reaches its maximum capacity, making further vertical scaling impossible.

  2. Downtime during Upgrades: In some scenarios, the system might needs to be taken offline temporarily, causing downtime for users during the upgrading process.

  3. Limited Scalability for Rapid Growth: It might not be suitable for handling rapidly growing workloads, especially if the server's capacity cannot keep up with the increasing demands.

  4. Single Point of Failure: It focuses on upgrading a single server, so, if that server experiences a hardware or software failure, then entire system can be disrupted, leading to downtime and potential data loss.

Horizontal Scaling

Horizontal scaling simply means, adding more servers to your network to distribute the workload and handle increasing demands. In this approach, we add new servers to the existing infrastructure where each server has its own processing power (CPU), memory (RAM), and storage (SSD).

It provides a way to increase capacity by connecting multiple hardware or software entities so that they work as a single logical unit.

It is also known as scaling out.

horizontal scaling

Think of horizontal scaling like teamwork. When a system needs to handle more tasks, instead of making one computer do all the extra work, you add more computers to help out. Each new computer shares a part of the workload. It's similar to a group of people working together on a project. If one computer fails, the others can continue working, ensuring that your tasks get done without interruptions.

NOTE: Implementing horizontal scaling involves strategic planning and requires additional configurations in both software and hardware. The most common requirement is a ”load balancer”, to evenly distribute incoming traffic across multiple servers. Load balancing algorithms ensure that no single server is overwhelmed, proper resource utilization and improves system performance.

Use Case of Horizontal Scaling

Advantages of Horizontal Scaling

  1. High Scalability: Horizontal scaling allows applications to handle growing workloads by adding more servers as demand increases. This scalability ensures that the system can accommodate a larger number of users, transactions, or requests without sacrificing performance.

  2. High Availability and Fault Tolerance: Horizontal scaling distributes the workload across multiple servers. If one server fails, the system can continue operating using the remaining servers. This redundancy ensures high availability and fault tolerance, minimizing the impact of hardware failures.

  3. Cost-Effectiveness: At some level, adding new servers as needed is often more cost-effective than investing in a very high-end, vertically scaled servers. Businesses can start with a minimal setup and add servers incrementally based on demand, optimizing costs and resources.

  4. Improved Performance: Distributing the workload across multiple servers can improve overall system performance. Tasks can be parallelized and processed concurrently, leading to faster response times and better throughput, especially for applications that can benefit from parallel processing.

  5. Geographic Load Balancing: Horizontal scaling enables organizations to deploy servers in different geographic locations. This geographic load balancing reduces latency and ensures a better user experience by serving content from servers that are physically closer to the users.

  6. Redundancy and Disaster Recovery: Horizontal scaling allows for redundancy setups where data is replicated across multiple servers. In the event of a disaster or data loss, redundant servers can be used to recover the lost data, ensuring data integrity and business continuity.

Cons of Horizontal Scaling

  1. Complex Data Management: Distributing and managing data across multiple servers can be complex, especially when ensuring data consistency, synchronization, and integrity. Implementing effective strategies for data sharding, replication, and distributed transactions can be challenging.

  2. Software Design Challenges: Applications must be designed to be distributed and stateless, which can be challenging for certain types of software. Not all applications are naturally suited for horizontal scaling, requiring significant architectural changes to adapt.

  3. Dependency on Network: Horizontal scaling heavily relies on a robust and high-bandwidth network. Network failures or congestion can disrupt communication between servers, affecting the overall system performance.

  4. Increased Complexity: Managing a cluster of servers and ensuring their seamless coordination demands more sophisticated tools and expertise. Configuration, monitoring, and troubleshooting becomes more complex as the number of servers grows.

  5. Cost of Infrastructure: While horizontal scaling can be cost-effective for moderate growth, scaling to handle massive loads might require a significant investment in infrastructure, including servers, networking equipment, and load balancers.

  6. Operational Overheads: Managing a large number of servers involves considerable operational overhead, including maintenance, monitoring, patching, and ensuring consistent configurations, which can strain IT resources.

Horizontal vs Vertical Scaling (Comparison Table)

AspectHorizontal ScalingVertical Scaling
DefinitionAdding more machines or servers to distribute load.Enhancing the power of existing machines by upgrading them.
ScalabilityEasily scalable by adding more servers.Limited scalability, as it relies on the capacity of a single server.
Cost-EffectivenessCost-effective for handling large workloads by using extra servers.Cheaper for small server, but can be expensive for high-end servers.
FlexibilityOffers flexibility by allowing the addition or removal of servers based on demand.Less flexible; requires significant changes for upgrades.
DowntimeMinimal downtime, as new servers can be added without affecting existing ones.Downtime may be required during server upgrades or maintenance.
ScalabilityCan scale both vertically (upgrading server components) and horizontally (adding more servers).Less scalable because of limited hardware upgradation.
Resource UtilizationEfficiently utilizes resources across multiple servers.Resource utilization is concentrated within a single server.
Load BalancingA load balancer is required to distribute the load to multiple servers efficiently.Load balancing is not required.

horizontal vs vertical scaling

Conclusion

The choice between horizontal and vertical scaling depends on the specific requirements, workload patterns, and goals of a particular system.

More frankly, it is not on you to decide when to scale your system horizontally or vertically in initial phase. You just have to keep track of your application and when you have enough data about something that is becoming a bottleneck, then is the time to decide how to deal with it (like either upgrading CPU, RAM or SDD is enough or you need to add more machines or to move to a distributed system).