Skip to content

Scaling up and scaling out

The scalability lesson ended on the two ways to add capacity. This lesson takes them in turn.

Scaling up, or vertical scaling, gives one machine more resources: more CPU, more memory, a faster disk. In the words of the Azure Architecture Center, it means changing the capacity of a resource, for example by moving an application to a larger virtual machine size.

Scaling out, or horizontal scaling, adds machines that share the work. The Azure guide calls it adding or removing instances of a resource.

Mental model. Scaling up makes one machine bigger. Scaling out makes more machines. Up is simple and runs out. Out does not run out, but it only works for work that can be split.

Scaling up Scaling out
What changes in the design Nothing: the same software on a larger machine The work must be split across machines, so state must not be tied to one of them
Where it stops At the largest machine there is At what the machines share, such as a database
Changing the size Often a redeploy, which can make the system briefly unavailable New instances can start while the others keep serving
When one machine fails All the capacity goes Only a share goes
Queues (in the model) One queue shared by all the slots One queue per machine

The first rows come from the sources. The Twelve-Factor App says that an individual machine can only grow so large, so an application must also be able to span several. The Azure guide says that vertical scaling often requires the system to be redeployed and is therefore less often automated, while horizontal scaling lets the application keep running as instances are added. AWS’s reliability guidance recommends replacing one large resource with several small ones, to reduce the impact of a single failure. The last row is the model’s, and the next section computes it.

Eight statements, each describing one way of scaling. Put each under the one it describes, then check, and read why.

Challenge

Scale up or scale out?

There are two ways to add capacity: make the machine bigger (scaling up, or vertical scaling) or add more machines (scaling out, or horizontal scaling). Put each statement under the way of scaling it describes.

Sorting needs JavaScript.

Categories

A bigger machine
One machine with more CPU, memory or disk.
More machines
More machines sharing the work.
  1. Line 1 of 8Move the database from a machine with 8 cores to one with 32 cores.
  2. Line 2 of 8Add five more API instances behind the load balancer.
  3. Line 3 of 8Capacity stops growing when you reach the largest machine that exists.
  4. Line 4 of 8When one machine fails, only a share of the capacity is lost: one tenth, with ten instances.
  5. Line 5 of 8Changing the size usually means redeploying onto the new machine, which can make the system briefly unavailable, so it is rarely automated.
  6. Line 6 of 8A user's next request can reach a different machine, so nothing the user needs may live only in one machine's memory.
  7. Line 7 of 8All the slots are on one machine, so they share one queue: a request waits only if every slot is busy.
  8. Line 8 of 8Each machine keeps its own queue, so a request can wait at a busy machine while another one is idle.

Check your answers at least once before looking at the answers.

The queueing lesson found that a queue shared by many servers waits less than the same servers split into separate queues. That is the whole difference between the two ways of scaling, as far as waiting goes.

Take 8 slots of 20 ms each, which can serve 400 requests per second, at 80% utilisation. In one machine, the 8 slots share one queue, and a request waits only if all 8 are busy. In the queueing model, the mean time in the system is 25.7 ms and the 99th percentile is 103.0 ms.

Split the same 8 slots over two machines of 4 slots, with requests spread evenly between them. Each machine has its own queue, and a request can wait at one machine while the other has a free slot. Each machine is at 80% too, and the mean is 34.9 ms and the 99th percentile 137.9 ms: about a third longer.

So at equal capacity and equal utilisation, scaling up waits less. This is a result of the model, which assumes an even split and a queue per machine. The load balancing module returns to how a real balancer spreads requests.

Waiting is not why people scale out. They do it for the two things scaling up cannot give: capacity beyond the largest machine, and a failure that costs a share instead of everything.

Scaling out also lets a group be sized in small steps. A peak of 1,500 requests per second, with instances that each serve 200 and a target of 60% at the peak, needs 1,500 ÷ (200 × 0.6) = 12.5, which is 13 instances. A machine that is 13 times as big is a purchase, whereas 13 instances can be added, and removed again, one at a time. The autoscaling lesson at the end of this module relies on that.

A peak of 1,600 requests per second needs 14 instances of 200 requests per second at a target of 60%, which is a capacity of 2,800. Compare two ways of providing it.

  • 14 small instances. Losing one leaves 13, a capacity of 2,600. Utilisation moves from 57.1% to 61.5%, and no request is rejected.
  • One machine 14 times as large. Losing it leaves nothing. Every request is rejected until it is replaced.

A group of N instances that must survive losing one can run at up to (N − 1) ÷ N of its capacity: 50% for 2 instances, 75% for 4, 87.5% for 8, and 92.9% for 14. That is why many small machines can be run hotter than a few large ones, and why scaling out is an availability technique as well as a capacity one. The availability lesson counted how many instances a group can lose.

Capacity only adds up when the work can be split. The scalability lesson showed the limit in a lab: adding API instances stopped helping once the database, which every instance shares, was the bottleneck. The Azure guide makes the same point about data: a database can be scaled out, but this usually involves partitioning the data, which is generally not automated.

The Twelve-Factor App names the property to aim for. Its processes are share-nothing and horizontally partitionable, which is why, in its words, adding more concurrency is a simple and reliable operation. A service that keeps something an instance alone knows is not share-nothing, and the next lesson is about that.

  • Scaling up gives one machine more resources. It is simple, it stops at the largest machine, and changing the size often means a redeploy.
  • Scaling out adds machines. It has no ceiling from the machine, but it needs work that can be split, and what the machines share becomes the limit.
  • At equal capacity and utilisation, one machine with 8 slots has a mean of 25.7 ms at 80%, against 34.9 ms for two machines of 4. What the split buys is resilience.
  • A group of N instances can run at up to (N − 1) ÷ N of its capacity and survive losing one: 75% for 4, 87.5% for 8.
  • A peak of 1,500 requests per second on instances of 200, at a target of 60%, needs 13 instances.

Next: stateless services, and what lets any instance answer any request.

Your progress

Built by GhaziAlibi.

© ShardCraft. All rights reserved.