DEV Community

Vincent Tommi
Vincent Tommi

Posted on • Edited on

Day Two of Learning System Design: Horizontal vs. Vertical Scaling

As part of my journey learning system design, on day two, I explored the concepts of horizontal scaling and vertical scaling. These are fundamental approaches to handling increased demand on a system, such as more users or requests. This article organizes my notes into a clear explanation of both strategies, their differences, and their real-world applications, reflecting my growing understanding of system design.

What is Scaling?

Imagine you’ve written an algorithm or code that runs on your computer. This code takes inputs, processes them, and produces outputs. As its usefulness grows, people are willing to pay to use it. However, you can’t share your personal computer with everyone. Instead, you expose your code to the internet through an API (Application Programming Interface). Users send a request to your API, your code processes it, and it sends back a response. To ensure reliability—especially for paying users—you host your service on the cloud rather than a local desktop.

The cloud is a collection of computers provided by services like AWS, offering computational power for a fee. Hosting on the cloud provides better configuration, reliability, and power management. As demand grows and more users access your service, your system may struggle to handle the load. This is where scalability comes in—the ability to handle increased requests by adding resources.

There are two primary ways to achieve scalability:

  • Horizontal Scaling: Adding more machines to distribute the workload.
  • Vertical Scaling: Upgrading existing machines to more powerful ones.

Let’s explore each approach and compare their characteristics.


Horizontal Scaling: Adding More Machines

Horizontal scaling involves adding more machines (or servers) to your system to handle increased demand. These machines work in parallel, distributing incoming requests across them to improve performance and user experience. For example, if your system is overwhelmed, adding more servers allows requests to be processed simultaneously.

Key Characteristics of Horizontal Scaling

  • Load Balancing Required: A load balancer is needed to distribute requests evenly across multiple machines, ensuring no single machine is overwhelmed.
  • Resilience: With multiple machines, if one fails, requests can be redirected to others, reducing downtime risk. This makes horizontal scaling highly resilient.
  • Network Calls: Communication between machines (e.g., between services or databases) involves remote procedure calls (RPCs), which can introduce latency.
  • Data Consistency Challenges: Since data may be distributed across machines, ensuring data consistency is complex due to loose transactional guarantees.
  • Scales Well: Horizontal scaling is nearly linear—you can add more servers as users grow, making it flexible for large-scale systems.

Vertical Scaling: Upgrading to Bigger Machines

Vertical scaling involves upgrading the existing machine to a more powerful one with better hardware (e.g., more CPU, RAM, or storage). This increases throughput and reduces response times without adding more machines.

Key Characteristics of Vertical Scaling

  • No Load Balancing Needed: With only one machine, there’s no need for a load balancer.
  • Single Point of Failure: If the machine fails, the entire system goes down, making vertical scaling less resilient.
  • Inter-Process Communication: Communication within a single machine is faster than network calls, avoiding remote communication latency.
  • Data Consistency: With data on one machine, maintaining consistency is straightforward, as there’s no need to synchronize across systems.
  • Hardware Limitations: Vertical scaling is limited by hardware constraints—you can only upgrade a machine so much before hitting its maximum capacity.

Horizontal vs. Vertical Scaling: A Comparison

Aspect Horizontal Scaling Vertical Scaling
Load Balancing Required to distribute requests across machines Not applicable
Resilience Highly resilient due to multiple machines Single point of failure
Communication Slower due to network calls (RPCs) Faster due to inter-process communication
Data Consistency Challenging due to distributed data Easier as data resides on one machine
Scalability Scales linearly with more machines Limited by hardware constraints

Real-World Application: The Hybrid Approach

In real-world systems, a hybrid approach combining horizontal and vertical scaling is often used to balance cost, performance, and reliability. For example, you might use horizontal scaling to add machines for resilience and load distribution, while ensuring each machine is as powerful as feasible (vertical scaling) within budget constraints. This hybrid strategy supports large-scale demand while optimizing performance and cost.

Why a Hybrid Approach?

  • Cost Efficiency: Bigger machines (vertical scaling) can be expensive but reduce the need for complex load balancing and data synchronization.
  • Reliability: Multiple machines (horizontal scaling) ensure the system remains operational if one fails.
  • Scalability and Consistency: Horizontal scaling supports growth, while vertical scaling simplifies data consistency for critical components.

Conclusion (Day Two Reflections)

On day two of learning system design, I’ve grasped that horizontal and vertical scaling are essential strategies for building scalable systems. Horizontal scaling excels in resilience and scalability but introduces challenges like load balancing and data consistency. Vertical scaling offers simplicity and faster communication but is limited by hardware and has a single point of failure. Real-world systems often combine both in a hybrid approach to balance trade-offs. As I continue learning, I’m excited to explore how these concepts apply to designing reliable, scalable, and cost-effective systems that meet user needs.

Top comments (0)