Sub topic 10
Scalability requirements
This chapter assumes you can write measurable targets (SLIs and SLOs) and percentile latency requirements from the earlier chapters, and that you can read short Python snippets. It shows how to turn "the system must scale" into a requirement you can test and size.
What a scalability requirement is
Scalability is the ability of a system to keep meeting its other targets as load grows. A scalability requirement is therefore not a standalone quality. It is a statement of the form: "while load grows from A to B, the latency, availability and cost targets still hold."
"The system must be scalable" is not testable. Every real system scales to some point and fails beyond it. The useful question is how far, how fast, and at what cost.
A complete scalability requirement names four things:
- The load dimension that grows, such as requests per second, stored items, or concurrent connections.
- The starting value and the target value.
- The time frame in which the growth is expected.
- The targets that must still hold at the higher load, such as NFR-1 from the URL shortener (99% of redirects under 100 ms).
Compare these two requirements:
- Weak: "The service must scale to many users."
- Testable: "Within 12 months the service sustains 20,000 redirects per second at peak while still meeting NFR-1 and NFR-2."
Dimensions of growth
Load does not grow in only one way, and each dimension stresses a different part of the system.
| Dimension | Example metric | Usually stresses |
|---|---|---|
| Request rate | Peak requests per second | Application servers, load balancers, database read capacity |
| Data volume | Rows or gigabytes stored | Storage, index size, backup time |
| Write rate | Writes per second | Database write path, replication |
| Concurrency | Open connections or sessions | Memory, connection limits, thread pools |
| Fan-out | Followers per user, recipients per message | Per-request work, queue depth |
| Tenants or regions | Customers, deployments | Operations effort, configuration, data isolation |
Pick the dimensions that matter for your system and state each one separately. A URL shortener has a heavy read rate and a modest write rate. A messaging system may be limited by fan-out instead. A requirement that lumps these together hides where the bottleneck will be.
Vertical and horizontal scaling
The requirement does not choose the scaling method, but it constrains it. There are two basic approaches.
- Vertical scaling (scaling up) means moving to a bigger machine. It is simple and needs no code changes, but it has a hard ceiling, usually costs more per unit of capacity at the top end, and leaves a single point of failure.
- Horizontal scaling (scaling out) means adding more machines behind a load balancer or a partitioning scheme. It has a much higher ceiling and improves availability, but it requires the software to cope with distribution: shared state, partitioning, and coordination.
If your requirement says "10x in 12 months," vertical scaling may be enough. If it says "1000x," you will need horizontal scaling, and you should design for it early. This is how scalability requirements start to shape architecture, which a later chapter covers.
Writing the growth into numbers
Use the capacity arithmetic from the spine: the system sized for 10 million daily active users at 20 requests each has an average of about 2,315 requests per second and a peak of about 6,944 with a peak factor of 3. A scalability requirement adds a growth rate on top of that baseline.
The snippet below projects peak load under compound monthly growth. Compound growth means each month grows by a percentage of the previous month's value, not by a fixed amount.
def project(value, monthly_growth, months):
"""Project a load value under compound monthly growth."""
return value * (1 + monthly_growth) ** months
current_peak_rps = 6944
for months in (0, 6, 12, 24):
print(months, round(project(current_peak_rps, 0.10, months)))
# 0 6944
# 6 12302
# 12 21793
# 24 68397At 10% monthly growth, load doubles in about 7 months and grows roughly tenfold in 24 months. Small monthly percentages hide large totals, so always convert growth into the absolute target at the end of the planning horizon, and write that number into the requirement.
Elasticity, headroom and limits
Three related ideas often get mixed up with scalability.
- Elasticity is how quickly capacity follows load, both up and down. A system can scale to a large size but react slowly, for example if it takes 10 minutes to add servers and traffic doubles in 2 minutes. State the reaction time if bursts matter: "capacity increases within 5 minutes of sustained load above 70%."
- Headroom is spare capacity kept in reserve for spikes and failures. A common rule is to run at no more than 60 to 70% of capacity at peak. If a target says "sustain 20,000 RPS," clarify whether that is the maximum the system can handle or the load at which it is still comfortable.
- Limits are the explicit upper bounds. State what is not promised, for example "beyond 100,000 RPS is out of scope for this release." This ties back to the scope and out-of-scope list.
Scalability is rarely free
Real systems do not scale perfectly. Adding a second server rarely doubles capacity, because of shared resources and coordination costs. Common causes include:
- A single shared database that all servers write to.
- Hot keys, where one popular item receives a disproportionate share of traffic and overloads one partition.
- Locks or global counters that serialize work.
- Cross-partition operations such as joins or transactions.
A good requirement therefore says where you expect scaling to be linear and where you accept limits. For the URL shortener, redirects are read-heavy and cacheable, so read capacity can scale by adding cache and replica nodes. Creating short URLs needs unique ID generation, which is the likely point of contention.
A scalability requirement for the URL shortener
Here is how the requirement from the opening can be added to the requirements document in the same format as the earlier chapters:
non_functional:
- id: NFR-4
quality: scalability
text: Within 12 months, peak redirect load grows from 7,000 to 20,000 requests per second, and NFR-1 and NFR-2 still hold.
- id: NFR-5
quality: scalability
text: Stored short URLs grow from 1 billion to 5 billion records over 3 years without changing the redirect latency target.
- id: NFR-6
quality: elasticity
text: Capacity increases within 5 minutes when peak load stays above 70% of provisioned capacity.Each item names a metric, a starting and target value, a time frame, and the targets that must remain true. Each can be checked with a load test.
Verifying a scalability requirement
You cannot verify scalability by reading code. You need to test it.
- Run a load test at the current level and record SLIs such as p99 latency and error rate.
- Increase load in steps toward the target and repeat the measurement at each step.
- Check that the SLO still holds at the target load, with the headroom you required.
- Note the first resource that saturates (CPU, database connections, network), because that is the next bottleneck.
Exercise
A team writes the requirement "The system must handle growth." Rewrite it as a testable scalability requirement for a service that now handles 500 requests per second at peak, expects 4x growth in 6 months, and has a p99 latency target of 200 ms.
Show answer
Example: "Within 6 months, peak load grows from 500 to 2,000 requests per second, and 99% of requests still complete in under 200 ms, measured over 30 days." It names the load dimension, the start and target values, the time frame, and the latency target that must hold. It can be tested by running a load test at 2,000 requests per second and checking the p99 latency.
Exercise
A service grows 5% per month. Using the compound growth formula from this chapter, will its load more than double within a year? Explain.
Show answer
Yes. After 12 months the factor is 1.05^12, which is about 1.80, so load grows by about 80% and does not double. After 15 months the factor is about 2.08, so doubling takes about 14 months. A 5% monthly growth rate looks small but still compounds to nearly double in a year.