Sub topic 4
Estimating load: average, peak and headroom
This chapter assumes you know the difference between latency and throughput, and that you can read short Python programs. You will turn a product description into a requests-per-second number. Then you will adjust that number for peaks and for spare capacity.
Why the average is not the target
A system is sized for the busiest moments, not for the daily average. Traffic is uneven. A shopping site may be quiet at 4 a.m. and busy at lunchtime. If you provision for the average, the system will fall behind every day at peak.
Load estimation has three steps:
- Compute the average rate from the user numbers.
- Multiply by a peak factor to get the peak rate.
- Add headroom so the system does not run at its limit.
Step 1: the average rate
Start with the number of active users and how many requests each one makes. Divide the daily total by the 86,400 seconds in a day.
Take 2 million daily active users who make 25 requests each. That is 50 million requests per day, or about 579 requests per second on average.
State your assumptions with the number. "25 requests per user" might come from analytics on an existing product, or it might be a guess based on a similar product. Write down which one it is, so you know what to check later.
Step 2: the peak factor
The peak factor is the ratio of peak traffic to average traffic. Measure it from real traffic if you can. If you cannot, use a rough value and label it as a guess.
| Traffic pattern | Typical peak factor |
|---|---|
| Steady internal service | 1.5 to 2 |
| Consumer app with a daily cycle | 2 to 4 |
| Event-driven spikes (sales, broadcasts) | 10 or more |
Use a shorter window than a day when traffic is spiky. A one-minute peak can be much higher than the hourly average, and your system sees the one-minute peak.
Step 3: headroom
Headroom is the spare capacity above the expected peak. It covers forecast error, a failed server, deployments and short bursts. It also keeps queues short, because latency rises sharply as a system nears full utilization. A later chapter covers that effect.
Express headroom as a target utilization. If you want servers to run at 70% of their limit at peak, divide the peak rate by 0.7.
Putting it together
import math
daily_active_users = 2_000_000
requests_per_user_per_day = 25
peak_factor = 3
target_utilization = 0.7
seconds_per_day = 86_400
daily_requests = daily_active_users * requests_per_user_per_day
avg_rps = daily_requests / seconds_per_day
peak_rps = avg_rps * peak_factor
capacity_rps = peak_rps / target_utilization
print(round(avg_rps)) # 579
print(round(peak_rps)) # 1736
print(math.ceil(capacity_rps)) # 2481The system needs to sustain about 2,500 requests per second. That is more than four times the average. If you had sized for the average, you would have been about 77% short.
You can now apply Little's law. At 1,736 requests per second and 50 ms average latency, about 87 requests are in flight at peak (1,736 × 0.05).
Common errors
- Using the average for sizing. The system meets the average and fails at every peak.
- Mixing request types. A read and a large upload cost very different amounts. Estimate each type separately when the costs differ much.
- Forgetting growth. Add expected growth over the planning period, for example 12 months, to the user count before you start.
- Ignoring non-user traffic. Retries, health checks, cron jobs and internal calls add load. Retries can multiply load during an incident.
- Treating the guess as a fact. Keep the inputs in one place so you can revise them when real data arrives.
Exercise
A service has 10 million requests per day, a peak factor of 4 and a target utilization of 50% at peak. What average rate, peak rate and capacity target (in requests per second) should you plan for?
Show answer
Average = 10,000,000 / 86,400 ≈ 116 requests per second. Peak = 116 × 4 ≈ 463 requests per second. Capacity = 463 / 0.5 ≈ 926 requests per second.