Sub topic 14
Estimating load and storage from requirements
This chapter assumes you can read short Python snippets. It also assumes you know what a request, a database and a cache are. Earlier chapters showed how to write measurable targets. Here you turn user numbers and usage assumptions into request rates and storage sizes. Those sizes tell you whether one server is enough or whether you need to scale out.
Why estimate at all
An estimate is not a prediction. It tells you the order of magnitude: 100 requests per second, 10,000, or a million. Each size leads to a different design. At 100 requests per second, one database may be enough. At 100,000, you need caching, partitioning or both.
Estimating request rate
Follow three steps. Multiply daily active users by requests per user to get daily requests. Divide by the 86,400 seconds in a day to get the average rate. Multiply by a peak factor to get the rate you size for.
daily_active_users = 10_000_000
requests_per_user_per_day = 20
peak_factor = 3
requests_per_day = daily_active_users * requests_per_user_per_day
average_rps = requests_per_day / 86_400
peak_rps = average_rps * peak_factor
print(round(average_rps)) # 2315
print(round(peak_rps)) # 6944The peak factor is an assumption. Traffic is rarely flat, so sizing for the average would fail at busy hours. Record the factor in your assumptions list and revisit it when you have real traffic data.
Estimating storage
Storage depends on how many records you create, how big each one is, how long you keep it, and how many copies you store. Reads do not add storage, so use the write rate here.
new_records_per_day = 1_000_000
bytes_per_record = 500
retention_years = 5
replication_factor = 3
raw_bytes = new_records_per_day * bytes_per_record * 365 * retention_years
total_bytes = raw_bytes * replication_factor
print(round(raw_bytes / 1e9, 1)) # 912.5 (GB)
print(round(total_bytes / 1e9, 1)) # 2737.5 (GB)The replication factor links back to your durability requirement. Keeping three copies protects against losing a disk, but it triples the storage you pay for.
Reading the numbers
Compare each result with what one machine can do. A single well-tuned database node can often serve a few thousand simple queries per second, and a few terabytes fits on one disk array. These are rough figures, so check them against your own hardware. If your peak is well below them, a simple design may be enough. If it is far above, your scalability requirement is real and you need to plan for it.
Common errors
- Using the average rate as the design target and ignoring peaks.
- Mixing units, such as megabits with megabytes or per-day with per-second figures.
- Forgetting replication, indexes and backups when sizing storage.
- Using false precision. Round to one or two significant figures and state the assumptions.
- Estimating reads and writes as one number. They often differ by 100 to 1, and they stress different components.
Exercise
A service has 5 million daily active users. Each makes 10 requests per day, and the peak factor is 2. What are the average and peak requests per second?
Show answer
Daily requests are 5,000,000 × 10 = 50,000,000. Average rate is 50,000,000 / 86,400 ≈ 579 requests per second. Peak rate is 579 × 2 ≈ 1,157 requests per second (1,158 if you multiply the unrounded average).