Horizontal scaling

Also known as: scaling out

On this page 7

Horizontal scaling, also called scaling out, is the practice of increasing a system’s capacity by adding more server instances and spreading work across them, rather than making a single machine more powerful. In the management of server resources, it is the main alternative to vertical scaling and the foundation of most large web platforms.

A horizontally scaled service runs several identical nodes behind a load balancer, so total throughput grows roughly with the number of nodes. The approach also improves fault tolerance, because losing one node removes only a fraction of capacity. Its price is architectural: the application must be designed so that any node can serve any request.

How horizontal scaling distributes load

Horizontal scaling works by placing a traffic distribution layer in front of a pool of equivalent servers. A load balancer, DNS round robin or a service mesh receives each request and forwards it to one healthy node according to an algorithm such as round robin, least connections or consistent hashing.

For this to work, nodes must be interchangeable. Session data, uploaded files and caches are moved out of local memory and disk into shared services such as a database, an object store or a distributed cache. A node that holds no unique state can be added, replaced or removed without users noticing.

The table below shows the building blocks that a scaled-out architecture typically needs and what each contributes.

Building blockPurposeTypical implementation
Load balancerSpreads requests across nodesHAProxy, Nginx, cloud balancer
Health checksRemoves failing nodes from rotationHTTP probe every few seconds
Shared session storeLets any node serve any userRedis, database-backed sessions
Shared file storageKeeps uploads consistentObject storage or network file system
Configuration managementKeeps nodes identicalImages, containers, automation tools
Autoscaling policyAdds or removes nodes on demandRules based on CPU or queue length
Building blocks of a horizontally scaled service

Horizontal scaling compared with vertical scaling

The difference is direction: vertical scaling adds resources to one server, while horizontal scaling adds more servers. Vertical scaling is simpler because the software does not change, but it hits a hardware ceiling and keeps a single point of failure.

CriterionHorizontal scalingVertical scaling
Capacity ceilingPractically very highLimited by largest available machine
Fault toleranceSurvives loss of individual nodesOne failure stops the service
Application changesOften required for statelessnessUsually none
Downtime to growNone when nodes join liveOften a restart or migration
Cost curveRoughly linear with commodity nodesRises steeply at high-end sizes
Operational complexityHigher: balancing, consistency, monitoringLower: one system to manage
Scaling out versus scaling up

In practice, teams combine both. A database server may be scaled up to a large instance while the stateless web and application tier is scaled out to dozens of nodes. Good capacity planning picks the cheaper direction for each tier separately.

What scales out easily and what does not

The ease of horizontal scaling depends on how much state a component holds and how often that state must be coordinated. Stateless request handlers scale almost linearly, while databases that require strong consistency scale out only with significant engineering effort.

ComponentDifficultyCommon technique
Stateless web or API tierLowAdd identical nodes behind a balancer
Background workersLowMore consumers on a shared queue
CachesModerateConsistent hashing across cache nodes
Relational database readsModerateRead replicas with replication lag
Relational database writesHighSharding by key or distributed SQL
File uploads on local diskHigh until redesignedMove to object storage
Scaling difficulty by component type

Amdahl’s law explains why gains flatten: if 10 percent of the work must happen in a serialized component, such as a single primary database or a global lock, no number of additional nodes can make the system more than about ten times faster.

Autoscaling and capacity planning

Autoscaling is horizontal scaling performed automatically: a controller watches metrics and adds or removes instances to keep them within a target range. Cloud instance groups and the Kubernetes Horizontal Pod Autoscaler are common implementations.

Choosing the right signal is critical. CPU utilization suits compute-bound services, but I/O-bound services are better scaled on request latency, queue depth or concurrent connections. Policies should keep headroom of roughly 20 to 40 percent, because new nodes need time to boot, warm caches and pass health checks.

WorkloadBest scaling signalReason
CPU-heavy APIAverage CPU utilizationLoad correlates directly with CPU
Queue-driven workersMessages waiting per workerReflects backlog, not current effort
Latency-sensitive frontend95th percentile response timeProtects user experience directly
WebSocket serviceOpen connections per nodeMemory scales with connections
Predictable daily peaksScheduled scalingCapacity is ready before demand
Choosing an autoscaling signal

A cooldown period between scaling actions prevents flapping, where instances are added and removed repeatedly as metrics oscillate around a threshold.

Pitfalls and trade-offs of scaling out

Horizontal scaling moves complexity from hardware to architecture. The following problems appear repeatedly when teams scale out before the application is ready for it.

  • Sticky sessions as a shortcut pin users to nodes and cause uneven load and lost sessions when a node fails.
  • Database connection exhaustion occurs when every new node opens its own pool against a fixed connection limit.
  • Cache stampedes follow scale-out events, because fresh nodes start with empty local caches.
  • Configuration drift makes supposedly identical nodes behave differently.
  • Distributed debugging becomes harder without centralized logs and request tracing.
  • Noisy neighbor effects on shared cloud hosts make individual nodes slower than expected.

Scaling out also does not fix inefficient code. An unindexed query that takes two seconds still takes two seconds on every node, and adding instances only multiplies the database load it creates.

Stripped to the essentials

Imagine a busy supermarket with one cashier and a long line. You could hire a faster cashier, or you could open more checkout lanes. Opening more lanes is horizontal scaling.

With computers, instead of buying one bigger and more expensive server, you run several ordinary servers side by side and share the visitors among them. If one breaks, the others keep working. The main idea: grow by adding more machines, and design the system so it does not matter which machine helps which visitor.

Where it is applied

A ticketing platform for concerts normally serves its API from four application nodes, each with 2 CPU cores, behind a cloud load balancer. Sessions live in a shared Redis cluster, and event images are stored in object storage, so every node is fully interchangeable.

When a popular tour goes on sale, traffic jumps about tenfold within minutes. The team configures scheduled scaling to 20 nodes thirty minutes before the sale opens, with an autoscaling rule that adds more nodes when 95th percentile latency exceeds 400 milliseconds. A connection pooler in front of the database limits total connections to 300 regardless of node count.

During the sale, the platform peaks at 32 nodes and keeps median response time under 250 milliseconds. Two nodes fail health checks and are replaced automatically without visible errors. After the rush, autoscaling returns the pool to four nodes, so the extra capacity is paid for only for a few hours.