DEV Community

Cover image for Vertical vs horizontal scaling: one server or eight?
System Design Simple
System Design Simple

Posted on Originally published at systemdesignsimple.com

Vertical vs horizontal scaling: one server or eight?

Vertical scaling gives one machine more resources. Horizontal scaling adds service instances across machines. In our simulation, one 8-core server and eight 1-core servers nearly tied when the costs were matched, 1,617 vs 1,579 requests per second, both near the 1,600 per second ceiling of 8 cores at 5 ms per request. But killing the only server failed 30.23% of requests in a 10 second test, while killing 1 of 8 failed 0.54%. Throughput was a tie. Failure was not.

What caps one bigger server

A shared lock and contention cap one bigger machine. In the baseline, the 8-core server completed 1,198 requests per second and the eight 1-core servers behind round robin completed 1,413. Changing only the assumed contention penalty, 0%, 1.5%, 3%, 6% per extra core, gave 1,398, 1,289, 1,198 and 1,027 requests per second, a wider range than the 215 requests per second baseline gap.

One shared queue or eight

One shared queue lowers waiting in the M/M/8 model, because a request takes the first free core instead of waiting behind a slow queue. Even so, with matched costs the simulation still came out close to a tie. Queueing shape matters less than the contention and store costs underneath it.

What happens when an instance dies

We ran a 10 second kill test at 839 requests per second, killed at 4 seconds, 3 second restart, no retries. Killing the only server failed 2,543 of 8,413 requests, 30.23%. Killing 1 of 8 small servers failed 45 of 8,387 requests, 0.54%. Health checks ran every 250 ms and ejected the dead instance after 2 misses, 375 ms after the kill.

The crash arithmetic holds up better than the throughput numbers: one instance out of N costs about 1/N of traffic for the detection time, provided the survivors have headroom, while the only server costs everything until it restarts.

What scaling out asks of your app

Interchangeable replicas need sessions and uploads accessible after an instance fails. Scheduled work needs coordination to prevent duplicate execution. And the shared database has to handle the added load, or the new instances just queue at the same store.

Our take

Our model could not pick a throughput winner. The result followed the costs we assumed, so measure contention and store costs on your own service before trusting either design. For a typical web product we would scale the stateless tier out with spread replicas and N minus 1 headroom, and scale the database up with replicas until it needs partitioning. A single machine is still a fair choice when the load fits with room to spare and a few seconds of downtime is acceptable.

These numbers come from our discrete-event queueing simulation with assumed costs, one seed, 1818, run on one Apple M2 Pro under Node v22.13.1. It is not a benchmark of any machine, cloud or server.

Read the full article with the queueing math and the lab: https://systemdesignsimple.com/vertical-vs-horizontal-scaling/

Top comments (0)