Topic 090 / Core
Vertical and horizontal scaling
Chapter 6.3 · Scaling Services
What and why
A system under growing load eventually runs out of capacity on whatever it is running on; two structurally different responses exist. Vertical scaling makes the one machine bigger (more CPU, RAM, faster disk). Horizontal scaling adds more machines and spreads load across them. Scalability was defined as a quality attribute at → 16; this topic is the two mechanisms for achieving it. Builds on: → 16 (non-functional requirements and quality attributes: scalability).
Diagram
| Vertical | Horizontal | |
|---|---|---|
| Mechanism | bigger machine | more machines |
| Ceiling | a hardware/cost limit | mainly coordination, not hardware |
| Single point of failure | yes, inherently (one machine) | no, if load is spread and any one can fail |
| Needs | nothing extra | statelessness or state partitioning (→ 91, → 73) |
| Typical change | resize or upgrade, often a restart | add/remove instances, no restart of existing ones |
How it works
- Vertical scaling: measure the current bottleneck resource (CPU, RAM, I/O — → 103), move to a machine with more of it; no application change is strictly required.
- Vertical scaling has a hard ceiling — the largest machine money can buy — and it remains one machine: one failure takes the whole service down.
- Horizontal scaling: add instances behind a load balancer (→ 92); each instance handles a share of the work.
- Horizontal scaling needs either no shared mutable state between instances (statelessness, → 91) or a way to partition state correctly across instances (sharding, → 73); without one of these, adding machines just duplicates or corrupts shared work.
- Most systems do both: scale a single instance vertically up to a sensible size, then scale horizontally beyond that for capacity and redundancy together.
Practical example
(numbers illustrative). A service handles 1,000 requests/second; one instance sustainably handles 250 requests/second before p99 latency degrades (→ 100). Vertically, doubling the machine's CPU might raise that ceiling to roughly 450 requests/second (scaling is rarely linear — other bottlenecks limit the gain) — still short of 1,000 alone. Horizontally, 4 instances at 250 requests/second each = exactly 1,000 requests/second, with no single-machine ceiling, and the ability to lose one instance and still serve 750 requests/second.
When to use it
- Use vertical scaling first when it's cheap, simple, and the ceiling isn't close — fewer moving parts, no load balancer or statelessness work needed.
- Use horizontal scaling once vertical hits its ceiling, needs redundancy, or needs elastic capacity that tracks demand (→ 95).
- Avoid horizontal scaling for state that can't be partitioned or made stateless without real engineering — do that work first (→ 91, → 73), don't bolt on instances and hope.
- Failure scenarios: scaling horizontally while a component still assumes single-instance state (an in-memory session, local file writes) — silent corruption or lost data, not an obvious crash; vertical scaling masking a real algorithmic problem (an O(n²) hot path, → 3) that a bigger machine only postpones.
- Simpler alternative: before either, check whether the bottleneck is fixable in software — an index (→ 64), a cache (→ 82), or a query fix; scaling hardware to cover a fixable inefficiency is the most expensive wrong answer available.
Practice
(decision kind — judge scenarios, 15–20 min, paper exercise).
- Given a single-instance monolith with an in-memory shopping cart and a sudden 3× traffic increase, decide: scale vertically, scale horizontally, or fix something else first — defend the choice, including what would have to change to make horizontal scaling safe.
- One instance sustains 250 requests/second; demand is 1,000 requests/second. Compute the instance count needed horizontally, and compare it against the vertical path's uncertain, non-linear gain from the practical example.
- List, for a system you know, every piece of state that would break if a second instance were added right now.
Done when you can name the specific blocker that would break under horizontal scaling before adding a single instance.
Key takeaway
Vertical scaling buys capacity with no architecture change but keeps a ceiling and a single point of failure; horizontal scaling removes both but demands statelessness or partitioning first. Done when you can: given a bottleneck and a traffic target, choose a scaling direction and name its prerequisite. Used next in → 91 (statelessness, horizontal scaling's prerequisite), → 95 (auto scaling, automating the horizontal case).
References
None — this topic makes no external claims.
Source directory