Scalability Basics: Vertical vs. Horizontal Scaling

Scalability Basics: Vertical vs. Horizontal Scaling

Part 3 of 12 · System Design in Practice

Imagine your application is running smoothly. Users can log in, browse products, and complete transactions without any problems.

Then your application starts growing. More users visit your website. Requests increase. Your server begins using more CPU and memory. Pages become slower, and eventually, some requests start failing.

What should you do? You could upgrade your existing server. Or you could run multiple servers and distribute traffic between them.

These are two fundamental approaches to scalability: vertical scaling and horizontal scaling.

In this article, we'll understand both approaches, explore their differences, and see how multiple Node.js instances can help an application handle more traffic.

What Is Scalability?

Scalability is a system's ability to handle increasing workloads without significantly affecting its performance, reliability, or availability.

A scalable application should be able to support growth as more users access it, more requests arrive at the same time, more data needs to be stored and processed, and more background jobs need to be executed.

For example, an application that handles 100 requests per second today might eventually need to handle 10,000 requests per second. Scalability is about preparing the system to handle that growth.

1. Vertical Scaling (Scaling Up)

Vertical scaling means increasing the resources of an existing server. Instead of adding more servers, you upgrade the machine your application already runs on.

For example, imagine your application currently runs on a server with 2 CPU cores and 4 GB RAM. As traffic increases, you upgrade it to 8 CPU cores and 16 GB RAM. Your application still runs on one server, but that server now has more computing power.

How Vertical Scaling Works

Think of it like upgrading your laptop. If your laptop becomes slow when running multiple applications, you might increase its RAM or use a faster processor. Vertical scaling follows the same idea, but for application servers.

Advantages

  • Simple to implement.
  • No need to manage multiple application instances.
  • Less infrastructure complexity.
  • Can improve performance quickly.

Disadvantages

  • Hardware upgrades have limits.
  • Powerful servers can become expensive.
  • The server remains a single point of failure.
  • Upgrading may require downtime, depending on the infrastructure.

Vertical scaling is often a reasonable starting point for small applications. However, it may become limiting as traffic grows.

2. Horizontal Scaling (Scaling Out)

Horizontal scaling means adding more servers or application instances instead of upgrading one machine. Instead of running your application on one powerful server, you could run it on three smaller servers. A load balancer distributes incoming requests between them.

How Horizontal Scaling Works

Imagine 3,000 users access your application at the same time. If one server cannot handle all those requests efficiently, you can add more application instances.

              Users
                |
                v
         Load Balancer
                |
       +--------+--------+
       |        |        |
       v        v        v
    Server 1 Server 2 Server 3
       |        |        |
       +--------+--------+
                |
             Database

The load balancer distributes requests across the available servers. If one server becomes unavailable, the load balancer can stop sending traffic to it, provided health checks and failure handling are configured.

Advantages

  • More capacity by adding instances.
  • Can improve availability when designed correctly.
  • Easier to expand gradually.
  • Supports distributing workloads across multiple machines.

Disadvantages

  • More infrastructure to manage.
  • Requires traffic distribution.
  • Application state must be handled carefully.
  • Shared resources such as databases can still become bottlenecks.

Horizontal scaling is especially useful when an application needs to handle substantial or unpredictable traffic.

3. Vertical vs. Horizontal Scaling

FeatureVertical ScalingHorizontal Scaling
ApproachUpgrade one serverAdd more servers
ComplexityLowerHigher
CapacityLimited by machine sizeCan grow by adding instances
CostPowerful machines can be expensiveDepends on number and size of instances
AvailabilityOne server can be a single point of failureCan improve availability with redundancy
InfrastructureSimplerRequires coordination between instances

Neither approach is automatically better. The right choice depends on your workload, infrastructure, budget, and availability requirements. Many production systems combine both approaches.

4. A Practical Example: Scaling a Node.js Application

Let's see how horizontal scaling works with a simple Express application. First, create a project:

mkdir node-scaling-demo
cd node-scaling-demo
npm init -y
npm install express

Create a file named server.js:

const express = require("express");

const app = express();

const PORT = process.env.PORT || 3000;
const INSTANCE = process.env.INSTANCE || "unknown";

app.get("/", (req, res) => {
  res.json({
    message: "Hello from Node.js",
    instance: INSTANCE,
    port: PORT
  });
});

app.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
});

This application returns the instance name so we can identify which server handled the request.

Run Multiple Instances

Open three terminal windows and run:

Terminal 1:

PORT=3001 INSTANCE=server-1 node server.js

Terminal 2:

PORT=3002 INSTANCE=server-2 node server.js

Terminal 3:

PORT=3003 INSTANCE=server-3 node server.js

You now have three application instances running on the same machine, each using a different port. For a real production deployment, these instances would typically run in separate containers, virtual machines, or hosts.

Test Each Instance

Open these URLs:

http://localhost:3001
http://localhost:3002
http://localhost:3003

Each response identifies the instance that handled the request. You have now created a basic example of horizontal scaling at the application-instance level.

Important: Running multiple instances on one machine demonstrates the concept, but it does not provide the fault isolation or machine-level capacity of running instances across separate servers.

5. An Important Concept: Stateless vs. Stateful Servers

Before scaling horizontally in a real application, we need to understand one important concept: application state.

Imagine a user logs in to your application. Your server stores the user's login information in its local memory. Now suppose the user's next request reaches another server. That second server does not know about the session stored in the first server's memory. The user may unexpectedly appear logged out.

This is one reason horizontal scaling requires careful state management.

What Is a Stateful Server?

A stateful server stores information about a user's session or activity locally. For example:

const sessions = {};

sessions["user-123"] = {
  loggedIn: true
};

This information exists only inside that particular server's memory. If another instance receives the next request, it may not have access to the same session.

What Is a Stateless Server?

A stateless server does not depend on local memory to remember information between requests. Instead, shared state can be stored in an external system, such as Redis for session storage, a database for persistent user data, or a shared object-storage service for uploaded files.

For example, multiple application instances can access the same Redis session store:

             Users
               |
               v
         Load Balancer
               |
        +------+------+
        |             |
        v             v
     Server 1      Server 2
        |             |
        +------+------+
               |
               v
             Redis

Now both servers can access the same session information. This makes it easier to distribute requests between application instances.

Stateless application servers are generally easier to scale horizontally because requests do not depend on which instance handled the previous request.

6. Does Horizontal Scaling Solve Every Problem?

No. Adding more application servers increases application-processing capacity, but it does not automatically solve every bottleneck.

  • Database bottleneck: More servers may generate even more database requests.
  • Shared storage: Files stored on one server may not be accessible to other instances.
  • Session management: Locally stored sessions can cause inconsistent user experiences.
  • Network limitations: Network bandwidth can become a bottleneck.
  • External services: Third-party APIs may have rate limits.

Scaling one component can expose limitations in another component. That is why system design requires looking at the entire architecture rather than focusing only on the application server.

7. When Should You Use Each Approach?

Consider vertical scaling when:

  • Your application is relatively small.
  • You want a simple deployment.
  • A server upgrade can provide enough capacity.
  • Infrastructure complexity needs to remain low.

Consider horizontal scaling when:

  • Traffic is growing significantly.
  • You need additional application capacity.
  • You want redundancy across multiple instances.
  • You need to scale different application workloads independently.

In many systems, a combination works best: use appropriately sized machines and run multiple application instances.

Common Beginner Mistakes

  • Assuming that adding more servers automatically makes an application scalable.
  • Keeping sessions only in local server memory.
  • Forgetting that the database can become the next bottleneck.
  • Storing uploaded files on one application server without shared access.
  • Confusing running multiple processes on one machine with distributing instances across multiple machines.

System Design Interview Questions

1. What is the difference between vertical and horizontal scaling?

Vertical scaling increases the resources of an existing server. Horizontal scaling adds more servers or instances to distribute the workload.

2. Why are stateless servers useful for horizontal scaling?

Because requests can be handled by different application instances without depending on local session state from a previous request.

3. Does adding more application servers always improve performance?

No. Shared resources such as databases, storage, networks, and external services can become bottlenecks.

Conclusion

Scalability is not simply about adding more servers. It is about understanding how your system behaves as demand increases and choosing the right way to handle that growth.

Vertical scaling gives an existing server more resources, while horizontal scaling distributes workloads across multiple instances.

As applications grow, stateless application servers and shared state management become important parts of a scalable architecture.

In the next part of System Design in Practice, we will explore Load Balancing—how incoming traffic is distributed across multiple servers, how different algorithms work, and how to handle unhealthy instances.

Have you used vertical or horizontal scaling in a real project? Share your experience in the comments.


System Design in Practice — 12-Part Series

Part 1: What Is System Design? A Simple Introduction for Developers

Part 2: How to Approach a System Design Problem

Part 3: Scalability Basics — Vertical vs. Horizontal Scaling

Part 4: Load Balancing — How Traffic Is Distributed Across Servers

Enjoyed this article?

If this article helped you learn something or solve a problem, you can support Mintrovia and help us continue creating free programming content.

Support Mintrovia