Sub topic 1
What Scaling Means: Capacity Versus Load
Prerequisites
This chapter assumes you know the following:
- How a client sends requests to a server and gets responses back, as in a typical web application.
- What CPU, memory, disk, and network are, and that a server has a limited amount of each.
- What a web server and a database do at a basic level.
You do not need to know any scaling techniques yet. This chapter sets up the vocabulary that the rest of the tutorial uses.
Two quantities: load and capacity
Scaling is easiest to understand as a comparison between two numbers.
- Load is the amount of work the system is asked to do. Examples are requests per second, active users, or gigabytes of data to process.
- Capacity is the maximum load the system can handle while still meeting its performance goals.
A system is healthy when load stays comfortably below capacity. Scaling means changing capacity so that it keeps up with load. Load usually changes for reasons you do not control, such as a marketing campaign, a holiday, or steady user growth. Capacity changes only when you change the system.
Capacity is not a single fixed number. It depends on which performance goal you care about. A server that can accept 2,000 requests per second may only answer in under 200 ms up to 800 requests per second. If your goal is "respond in 200 ms", your capacity is 800, not 2,000.
What happens when load reaches capacity
Systems rarely fail the moment load equals capacity. They degrade first. As load approaches capacity, requests wait in queues, response times rise, and eventually requests time out or are rejected.
The numbers in the chart are illustrative, but the shape is typical. Queues grow slowly at first and then very quickly. This is why teams keep headroom: spare capacity above the normal load. Running at 95% of capacity leaves no room for a traffic spike.
Ways to add capacity
There are two basic directions, and the rest of this tutorial covers each in detail.
| Approach | What changes | Example |
|---|---|---|
| Vertical scaling (scale up) | The size of one machine | Move from 4 vCPUs to 16 vCPUs |
| Horizontal scaling (scale out) | The number of machines | Run 6 servers instead of 2 |
Both raise capacity. They differ in cost, limits, availability, and what they require from your application. Those differences are the subject of later chapters.
A small model of capacity
You can reason about capacity with simple arithmetic. Suppose one server handles 200 requests per second at your target latency. Then the capacity of a pool of identical servers is roughly the per-server capacity times the number of servers, assuming the work spreads evenly.
def pool_capacity(per_server_rps, servers):
return per_server_rps * servers
def servers_needed(load_rps, per_server_rps, headroom=0.3):
# Plan so that normal load uses only (1 - headroom) of capacity.
usable = per_server_rps * (1 - headroom)
return -(-load_rps // usable) # ceiling division
print(pool_capacity(200, 3)) # 600
print(servers_needed(1000, 200)) # 8.0With a 30% headroom target, each server is treated as handling 140 requests per second. A load of 1,000 requests per second then needs 8 servers (1,000 / 140 is about 7.14, rounded up).
Common mistakes
- Treating capacity as one number. Capacity depends on the goal. Always state it together with a latency or error-rate target.
- Planning for average load. Traffic has peaks. Capacity must cover the peak plus headroom, not the daily mean.
- Scaling before measuring. Adding capacity to a component that is not the limiting one changes nothing. The next chapters cover how to measure and find the real limit.
- Ignoring the direction of change. Load can fall as well as rise. Capacity you no longer need still costs money.
Exercise
One server handles 250 requests per second while meeting your latency target. You expect a peak load of 1,800 requests per second and want each server to run at no more than 80% of that capacity at peak. How many servers do you need?
Show answer
Usable capacity per server is 250 × 0.8 = 200 requests per second. 1,800 / 200 = 9, so you need 9 servers.
Exercise
Why can a system be failing its users even though load is still below its maximum measured throughput?
Show answer
Capacity is defined relative to a performance goal. Near the maximum throughput, queues build and latency rises sharply, so response times can exceed the target well before the system reaches its absolute limit. The usable capacity is lower than the maximum throughput.