Patterns

Vertical and horizontal scaling

Make one machine bigger, or run more machines, and know which one to reach for first.

Scaling vertically means a bigger machine, and scaling horizontally means more machines sharing the work.

Use it when#

  • Vertical: one box is the limit, the code keeps state in memory, and a restart is acceptable.

  • Horizontal: you need to survive losing a machine, or one box of the biggest size is not enough.

  • Either: a load bar is red on a single tier, which tells you what to grow.

How it works#

Going vertical changes one number, and nothing else in the system notices. A 4 vCPU server becomes an 8 vCPU one. The ceiling is the largest machine you can rent, and the price per core climbs near the top.

Going horizontal puts a load balancer in front of several copies. Two 2 vCPU servers hold as much CPU as one 4 vCPU server, but they need a place to share state, usually the database, because a user's next request may land on the other copy.

What it costs#

Vertical scaling has a hard ceiling and one point of failure, and resizing a box usually means a restart. Horizontal scaling adds a balancer, health checks, and the rule that servers hold no local state. It also multiplies database connections, which is why people add a connection pool soon after.

Start vertical because it is cheap in engineering time, then go horizontal when you need failure tolerance or run out of box.

In Quorum#

The two Designs serve the same Users with the same total CPU. The first has one larger App Server, and the second has two smaller ones behind a Load Balancer. Compare the Burn and the caption of each.

Drag to pan. Hold Ctrl or Cmd and scroll to zoom.

At 3.00k Users the Simulation solves this Design to Apdex 1.00, p99 253 ms, 0.0% errors and $1.20/s Burn.
WhereSettingValueWhy
App ServerInstance sizemediumOne Medium box has four vCPUs. It needs no Load Balancer, but it is a single point of failure and has a ceiling.
DatabaseInstance sizesmallSmall gives the Database two vCPUs, so the figures below reflect the Cache and not a starved Database.

Drag to pan. Hold Ctrl or Cmd and scroll to zoom.

At 3.00k Users the Simulation solves this Design to Apdex 1.00, p99 266 ms, 0.0% errors and $1.52/s Burn.
WhereSettingValueWhy
App ServerInstance sizesmallTwo Small boxes hold the same four vCPUs as one Medium, so the comparison is fair.
App ServerInstance sizesmallThe second copy. If one dies, the other keeps serving.
DatabaseInstance sizesmallSmall gives the Database two vCPUs, so the figures below reflect the Cache and not a starved Database.

Research this Design needs: Load balancing.

The Scale up first and Several app servers behind a load balancer rungs cover each step. The glossary defines vertical and horizontal scaling, and Survive a traffic spike uses both.