Sub topic 4
Estimating Load: Average, Peak and Headroom
What this chapter assumes
You should know the client-server request/response model and the usual backend components: load balancers, services and databases. You should also be comfortable with simple Python and with arithmetic on rates and durations. The previous chapters covered percentiles and how product requirements become targets. This chapter covers the other half of a target: how much traffic the system must carry.
A latency target such as "p99 under 300 ms" only means something at a stated load. A system that meets it at 500 requests per second (RPS) may miss it at 3,000. Load estimation gives you that number.
Three numbers, not one
A load estimate has three parts.
- Average load is total requests divided by total time. It is easy to compute and useful for cost and storage.
- Peak load is the highest rate the system must sustain for a meaningful window. It decides how much capacity you need.
- Headroom is the spare capacity you keep above peak. It absorbs forecast errors, growth, failures and bursts.
Sizing for the average is the most common mistake. Traffic is rarely flat. A system sized for the average runs far above its safe utilization every day at peak, and queues form (see the chapter on utilization and queueing).
Step 1: From users to requests per second
Start from a product number and multiply down to requests.
- Pick a user count. Daily active users (DAU) is usually the most stable choice.
- Estimate user actions per user per day, such as page views, searches or purchases.
- Estimate requests per action. One tap in a mobile app may trigger three API calls.
- Divide daily requests by 86,400, the number of seconds in a day.
SECONDS_PER_DAY = 86_400
def estimate_load(dau, actions_per_user_per_day, requests_per_action, peak_factor):
daily_requests = dau * actions_per_user_per_day * requests_per_action
avg_rps = daily_requests / SECONDS_PER_DAY
peak_rps = avg_rps * peak_factor
return daily_requests, avg_rps, peak_rps
daily, avg_rps, peak_rps = estimate_load(
dau=2_000_000,
actions_per_user_per_day=10,
requests_per_action=3,
peak_factor=4,
)
print(daily) # 60000000
print(round(avg_rps, 1)) # 694.4
print(round(peak_rps, 1)) # 2777.8Write down every input as an assumption with an owner and a source, such as product forecasts, marketing plans or existing logs. When an estimate is wrong, you want to see which assumption failed.
Step 2: Finding the peak factor
The peak factor is the ratio of peak load to average load. You can get it from three places, in order of preference.
- Existing traffic. If a similar system exists, measure its request rate in small windows (one minute or one second) and compute peak divided by average.
- Comparable systems. Use the shape of a similar product when you have no data of your own.
- A stated assumption. Choose a factor such as 3 to 5 for consumer products with a daily cycle, and record that it is a guess.
# Requests per hour, in thousands, for one day (24 values)
hourly_k = [100] * 12 + [300] * 6 + [600] * 4 + [1000] * 2
average = sum(hourly_k) / len(hourly_k)
peak = max(hourly_k)
print(round(peak / average, 2)) # 3.24The window size changes the answer. An hourly peak hides the busiest minute, and the busiest minute hides the busiest second. Pick a window close to the time scale at which your system queues. For a service with a 50 ms latency and small buffers, one-second peaks matter. For a batch pipeline that drains work over hours, hourly peaks are enough.
Step 3: Adding headroom
Headroom comes from several separate factors. Keep them separate in your calculation so each can be challenged on its own.
| Factor | What it covers | Typical form |
|---|---|---|
| Growth | Traffic increase before the next capacity review | Multiplier such as 1.5 for 12 months |
| Target utilization | Keeps queueing delay low at peak | Run at 50 to 70 percent of measured capacity |
| Spare units (N+1) | Loss of an instance, zone or node | Add one or more units, or a whole zone |
| Burst allowance | Unforecast spikes, such as a campaign | Extra multiplier, or autoscaling with a time limit |
Target utilization deserves attention. The capacity of one instance is the rate at which it still meets the latency target, and that is lower than the rate at which it saturates. Measure it with a load test, as described in the validation chapter. Never take the number from a CPU count alone.
import math
def instances_needed(peak_rps, per_instance_rps, target_utilization,
growth=1.0, spare=1):
planned_rps = peak_rps * growth
usable_rps = per_instance_rps * target_utilization
return math.ceil(planned_rps / usable_rps) + spare
peak_rps = 2777.8
# One instance meets the latency target up to 400 RPS in a load test.
print(instances_needed(peak_rps, 400, 0.6)) # 13
print(instances_needed(peak_rps, 400, 0.6, growth=1.5)) # 19With a 60 percent utilization target, each instance contributes 240 usable RPS. The first call gives 2,777.8 divided by 240, which is 11.6, rounded up to 12, plus one spare. The second call raises the planned load to about 4,167 RPS, which needs 18 instances plus one spare.
Step 4: Splitting load by type and by tier
One number for "load" is rarely enough. Break it down in at least these ways.
- Reads and writes. Writes often hit a single primary database and are much more expensive. A 100:1 read-to-write ratio means the write path may still be the bottleneck.
- Request classes. A search request and a login request cost different amounts of CPU and I/O. Estimate each class and weight it by cost, or size the expensive class on its own.
- Tiers. The rate at the edge is not the rate at the database. A cache cuts backend traffic, and fan-out multiplies it.
user_rps = 2777.8
cache_hit_ratio = 0.9
db_reads_per_miss = 2
db_rps = user_rps * (1 - cache_hit_ratio) * db_reads_per_miss
print(round(db_rps, 1)) # 555.6Be careful with cache hit ratios. If the hit ratio drops from 0.9 to 0.8 (after a deploy that clears the cache, for example), the backend load doubles. Size the database for the cold-cache case, or protect it with a rate limit.
Bytes as well as requests
Requests per second is the usual unit, but two other quantities can be the limiting factor.
- Bandwidth is requests per second times average response size. 2,778 RPS at 50 KB per response is about 139 MB/s, or roughly 1.1 Gbit/s. That can exceed a network interface or a load balancer limit.
- Storage growth is writes per day times record size times replication factor, summed over the retention period.
Check each quantity against the limit of the component that carries it.
Edge cases that change the estimate
Retries. When a call fails, clients retry. If a dependency starts failing, each client may send up to three attempts, so load can triple exactly when the system is weakest. Budget for retry amplification, cap the number of retries, and use backoff.
Fan-out. One user request that calls five internal services produces five times the internal load. Count requests at each tier, not only at the edge.
Synchronized peaks. Many users act at the same moment: the start of a sale, a push notification, midnight cron jobs, or a top-of-the-hour schedule. These peaks are far above the smooth daily curve. Spread scheduled work with random jitter, and treat known events as separate scenarios.
Time zones and regions. A global product has several overlapping daily curves, which flattens the global peak factor. A single-region system or a regional database may still see the sharp local peak.
Seasonality and growth. Holiday peaks, month-end processing and product launches repeat on a calendar. Multiply the base peak by the seasonal factor, not just by general growth.
Unit confusion. Mixing requests per second, per minute and per day is a frequent source of errors of 60x or 86,400x. Put the unit in every variable name, as in the code above.
Common errors
| Error | Effect | Fix |
|---|---|---|
| Sizing for average load | Overload at every daily peak | Size for peak, with a measured peak factor |
| Using hourly peaks for a latency-sensitive path | Misses short bursts that cause queues | Measure peaks at one-minute or one-second windows |
| Running at 100 percent of tested capacity | No room for variance, latency rises sharply | Apply a target utilization of 50 to 70 percent |
| Ignoring failure capacity | An instance or zone loss causes overload | Add N+1 and test it at peak |
| Counting only edge requests | Internal tiers are undersized | Estimate load per tier with fan-out and cache ratios |
| Hiding assumptions | A wrong input is hard to find later | List each input, its source and its owner |
Connecting to the rest of the targets
The peak RPS you derive here feeds the next calculation. With a peak of about 2,778 RPS and an average latency of 50 ms, Little's law gives about 139 requests in flight at peak. That figure sizes thread pools, connection pools and concurrency limits. The throughput target in your written SLO should state the load at which the latency target applies, for example "p99 under 300 ms at up to 3,000 RPS", so that the two targets cannot be read apart.
Treat the whole estimate as a hypothesis. You will compare it with production measurements and load test results, and revise it. That loop is the subject of the final chapter.
Exercise
A service has 500,000 DAU. Each user performs 8 actions per day, and each action makes 2 API requests. The peak factor is 5, per-instance tested capacity at the latency target is 200 RPS, target utilization is 0.5, and you want one spare instance with no growth multiplier. How many instances do you provision?
Show answer
Daily requests = 500,000 x 8 x 2 = 8,000,000. Average RPS = 8,000,000 / 86,400 = 92.6. Peak RPS = 92.6 x 5 = 463. Usable per instance = 200 x 0.5 = 100 RPS. 463 / 100 = 4.63, rounded up to 5, plus 1 spare = 6 instances.
Exercise
Your cache hit ratio is normally 0.95 and the frontend peak is 4,000 RPS, with one database read per cache miss. What is the database read rate normally, and what is it if a deploy empties the cache and the hit ratio falls to 0.5? What does this imply for sizing the database?
Show answer
Normally 4,000 x 0.05 = 200 reads per second. With a 0.5 hit ratio it is 4,000 x 0.5 = 2,000 reads per second, ten times higher. The database should be sized for the cold-cache case, or protected by rate limiting, request coalescing or a gradual cache warm-up.
Exercise
Why can an hourly peak-to-average ratio of 3 understate the load that a latency-sensitive service must handle?
Show answer
Averaging over an hour smooths out bursts. The busiest minute or second can be much higher than the hourly rate, and queues build on that shorter time scale. Measure peaks in windows close to the service's latency scale, such as one minute or one second.