Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 85

Vertical vs. Horizontal Scaling

Recommended resources

Hello! Welcome to the final module of our course on Backend Engineering.

In our last lesson, we configured a Continuous Deployment (CD) pipeline step to automatically build a Docker image of our Django application and push it to a container registry. This act of "packaging" our application is a critical prerequisite for deploying it reliably. Now that our application is a portable, standardized unit, we need to think about how our system will handle growth.

This brings us to a foundational concept in system design: scalability. Today's lesson will focus on explaining the difference between the two primary scaling strategies: vertical and horizontal scaling. Understanding these approaches is essential for designing backend systems that are resilient, performant, and cost-effective as user demand increases. This knowledge directly informs why we use technologies like containers and will set the stage for our upcoming discussions on deployment architecture.

1. The Need for Scalability

Imagine your application, which started with a handful of users, suddenly goes viral. The single server that was once more than enough is now overwhelmed with requests. Users experience slow load times, errors, or can't access the service at all. This is the problem that scalability aims to solve.

Scalability is the capability of a system to handle a growing amount of work by adding resources. When faced with an overloaded server, you have two fundamental choices:

  1. Make your current server more powerful.
  2. Add more servers to share the load.

These two choices represent the core of vertical and horizontal scaling.

To get a better sense of this problem, let's watch a brief introduction.

System Design BASICS: Horizontal vs. Vertical Scaling

This clip from Gaurav Sen's channel clearly frames the scalability problem that arises when an application's user base grows beyond the capacity of its initial infrastructure.

Watch the segment from 02:33 to 03:22. Notice how he boils the problem down to a simple choice: buy a bigger machine or buy more machines.


2. Defining Vertical and Horizontal Scaling

Let's now formally define these two approaches. We'll use a simple visual and some helpful analogies to make the distinction clear.

Vertical vs. Horizontal Scaling Comparison
This diagram illustrates the two scaling strategies. **Vertical scaling** involves increasing the resources (CPU, RAM) of a single server. **Horizontal scaling** involves adding more individual servers to a system.

Vertical Scaling (Scaling Up)

Vertical scaling means increasing the capacity of a single server. This involves upgrading its hardware components:

  • Adding more CPU cores.
  • Increasing the amount of RAM.
  • Upgrading to faster storage (e.g., from HDD to SSD or NVMe).
  • Increasing network bandwidth.

Think of this as making your server "taller" or more powerful. An analogy from the DigitalOcean article "Horizontal scaling vs vertical scaling" is that it's like strengthening and widening a single bridge to handle more traffic.

Horizontal Scaling (Scaling Out)

Horizontal scaling means adding more servers to your infrastructure to act as a single pool of resources. Instead of making one server more powerful, you distribute the workload across multiple, often identical, servers.

This is like making your infrastructure "wider." The same DigitalOcean article uses the analogy of adding more lanes to a highway to accommodate more traffic. This is the approach that underpins the architecture of most large-scale web services today.

To see these definitions in action, with their key pros and cons, the following video provides a great summary.

Vertical Vs Horizontal Scaling: Key Differences You Should Know

This video from ByteByteGo provides an excellent visual overview of both vertical and horizontal scaling, along with their primary advantages and disadvantages.

Watch from 00:13 to 03:11. The first part (until 01:26) covers vertical scaling, and the second part covers horizontal scaling. Pay close attention to the simple examples and the key pros and cons listed for each strategy.


3. A Deeper Dive into the Trade-offs

You now have a solid high-level understanding of both strategies. As you've expressed an interest in the "under the hood" aspects of backend engineering, let's explore the technical trade-offs in greater detail. The choice between scaling up and scaling out has profound implications for your system's architecture, performance, and reliability.

The following video provides a more technical, point-by-point comparison.

System Design BASICS: Horizontal vs. Vertical Scaling

Let's deepen our understanding of the technical trade-offs. Gaurav Sen provides a concise comparison that touches on important system design concepts like resilience, communication latency, and data consistency.

Watch from 03:22 to 06:21. The first part gives clear definitions, and the second part (starting at 04:03) is a point-by-point comparison. Focus on his five key differences: load balancing, resilience, communication speed, data consistency, and hardware limits.

Let's summarize and expand upon these crucial differences in the table below.

Factor Vertical Scaling (Scale Up) Horizontal Scaling (Scale Out)
Method Add more resources (CPU, RAM, Storage) to an existing server. Add more servers to a resource pool.
Resilience Creates a single point of failure. If the server fails, the entire application goes down. Provides high availability. If one server fails, others can take over its load.
Complexity Simpler to implement and manage initially. No changes to application logic are typically needed. More complex. Requires a load balancer to distribute traffic, and careful application design (e.g., statelessness).
Performance Fast inter-process communication (IPC) since all processes run on one machine. Slower communication over the network between servers. Network latency becomes a factor.
Data Consistency Strong consistency is easier to maintain as all data resides on a single machine. Maintaining data consistency across multiple nodes is a major challenge (see CAP theorem).
Scalability Limit Limited by the maximum power of a single machine. There's a physical and cost ceiling. Theoretically "unlimited" scalability. You can always add another server.
Cost Can become very expensive at the high end. The cost of top-tier hardware grows non-linearly. Often more cost-effective in the long run. Can use cheaper, commodity hardware and pay-as-you-go cloud models.

To explore these trade-offs, particularly around performance and cost, in even greater detail, let's consult a comprehensive article.

Horizontal vs Vertical Scaling: A Developer's Guide

This article from DataCamp offers a deep look into the performance characteristics and cost dynamics of each scaling strategy, reinforcing the concepts from the video.

Please read the sections 'Performance Characteristics and Tradeoffs' and 'Cost Dynamics and Optimization Models'. Focus on how each scaling approach impacts computational throughput, latency, and costs—both initial capital expenditure (CapEx) and total cost of ownership (TCO).

Test your understanding!

You are designing a backend for a new AI-powered document analysis service. The core of the service is a very large, memory-intensive machine learning model that takes a long time to load. Once loaded, it processes documents quickly. The application cannot be easily broken into smaller, independent parts.

Which scaling strategy would you initially favor for the servers running this model, and why?

Show answer

Vertical scaling would be the more suitable initial strategy.

Here's why:

  1. Tightly Coupled Application: The description states the application "cannot be easily broken into smaller, independent parts." This makes it a poor candidate for horizontal scaling, which thrives on distributing independent tasks.
  2. Stateful Nature: The model is "large" and "takes a long time to load," implying it's held in memory (state). In a horizontally scaled system, every server would need to load this large model, leading to duplicated memory usage and slow startup times for new instances.
  3. Performance: Since all processing happens on one machine, you avoid the network latency that would occur if different parts of the analysis had to communicate between servers. A single, powerful machine with a lot of RAM would be most effective.

4. Making the Right Choice

As you can see, there is no single "best" strategy. The right choice depends entirely on your specific needs. Here are the key questions to ask when deciding:

  1. Application Architecture: Is your application stateless or stateful?

    • Stateless applications (like most web servers or REST APIs) don't store any client data between requests. This makes them perfect for horizontal scaling. Any server can handle any request. The containerized Django app we are building is designed to be stateless.
    • Stateful applications (like traditional relational databases or systems with in-memory caches) are often easier to scale vertically.
  2. Workload & Traffic Patterns:

    • For unpredictable or "bursty" traffic, horizontal scaling combined with auto-scaling (automatically adding/removing servers based on load) is ideal and cost-effective.
    • For steady, predictable growth, vertical scaling can be simpler to plan and manage.
  3. Resilience Requirements:

    • If high availability is critical, horizontal scaling is almost always necessary to eliminate single points of failure.
  4. Cost:

    • Do you prefer lower upfront costs and flexible operational spending? Horizontal scaling on the cloud is a great fit.
    • Are software licensing costs a major factor? Some software is licensed per-server or per-core, which can make vertical scaling cheaper.

In the real world, complex systems often use a hybrid approach. For example, a typical web application might:

  • Horizontally scale its stateless web servers to handle incoming user traffic.
  • Vertically scale its primary relational database server to handle complex queries with strong consistency.

Conclusion

You have now explored the fundamental differences between the two main strategies for ensuring your application can grow with its user base. This is a cornerstone of modern system design.

Key Takeaways:

  • Vertical Scaling (Scale Up): Making a single server more powerful. It's simple but has hard limits and creates a single point of failure.
  • Horizontal Scaling (Scale Out): Adding more servers to a pool. It's highly resilient and scalable but introduces architectural complexity.
  • The choice is a trade-off between simplicity, cost, performance, and resilience.
  • Modern, cloud-native applications are almost always designed for horizontal scaling, which is why technologies like Docker and stateless application design are so important.

Preview of the Next Lesson:
We've established that horizontal scaling is the dominant paradigm for modern web backends. However, it introduces a critical question: if you have multiple servers, how do you intelligently distribute incoming requests among them? The answer is a load balancer. In our next lesson, we will describe the role of a load balancer in distributing traffic for horizontal scaling.