Sub topic 14
Estimating load and storage from requirements
This chapter assumes you can read short Python snippets and know what a cache, a replica and a read/write split are. You should also have the earlier chapters on scope, assumptions and measurable targets in mind. The goal is to turn the numbers in a requirements document into request rates, storage volumes and bandwidth. These numbers decide how big the system must be.
Why estimate at all
A requirement such as "99% of redirects complete in under 100 ms" says nothing about how many servers you need. It depends on how many requests arrive. An estimate connects the quality targets to a size. It also shows early whether a design is plausible: a single database node can handle 200 writes per second but not 200,000.
An estimate is a calculation with stated inputs, not a prediction. Aim for the right order of magnitude (hundreds, thousands or millions per second), not for three significant digits. Every input must be written down as an assumption, so a reviewer can challenge it.
Where the inputs come from
Each input should trace back to a requirement, a scope statement or an explicit assumption.
| Input | Typical source | Example |
|---|---|---|
| Users or daily active users | Stakeholders, business plan | 10 million daily active users |
| Actions per user per day | Use cases, comparable products | 20 requests |
| Read/write ratio | Functional requirements | 100 reads per write |
| Peak factor | Traffic shape, past data | Peak is 3 times average |
| Record size | Data model | 500 bytes |
| Retention | Scope, compliance | 5 years |
| Replication factor | Durability and availability targets | 3 copies |
If a number is missing, pick a value, label it as an assumption and record it. Never leave it implicit.
The estimation chain
Every estimate follows the same chain. Volume per day becomes an average rate, the average becomes a peak, and the peak is used for sizing.
Request rate
A day has 86,400 seconds. Divide daily requests by that number to get an average rate, then multiply by a peak factor.
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)) # 6944Size the system for the peak. Averages hide the busiest hour, and that hour is when latency and availability targets are most likely to be missed.
Edge cases in request rate
- Peak factors vary. A consumer app in one time zone may peak at 5 times its average. A global service is flatter. A flash sale or a live event can reach 10 times or more. Take the factor from real traffic when you have it.
- One user action can cause many requests. Loading a page may trigger 30 API calls. Count requests at the component you are sizing, not user actions.
- Fan-out multiplies load. If one post is delivered to 500 followers, one write becomes 500 internal writes or reads.
- Retries add load. During a partial failure, clients retry and traffic can rise sharply just when capacity falls.
Splitting reads and writes
Reads and writes load different parts of the system. A read-heavy service benefits from caching and read replicas. A write-heavy service needs partitioning and a fast log or queue. Use the read/write ratio from the functional requirements to split the rate.
Worked estimate: a URL shortener
The URL shortener from the requirements document (FR-1 to FR-3, NFR-1 to NFR-3) needs four more assumptions. Assume 5 million new short URLs per day, 100 redirects per creation, records of 500 bytes, and 5 years of retention. Keep the peak factor at 3 and the replication factor at 3.
SECONDS_PER_DAY = 86_400
new_urls_per_day = 5_000_000
read_write_ratio = 100
peak_factor = 3
record_bytes = 500
retention_years = 5
replication_factor = 3
target_utilization = 0.7 # keep disks at most 70% full
cache_hit_ratio = 0.9
redirect_response_bytes = 500
mean_latency_s = 0.02
reads_per_day = new_urls_per_day * read_write_ratio
avg_write_rps = new_urls_per_day / SECONDS_PER_DAY
peak_write_rps = avg_write_rps * peak_factor
avg_read_rps = reads_per_day / SECONDS_PER_DAY
peak_read_rps = avg_read_rps * peak_factor
print(round(avg_write_rps), round(peak_write_rps)) # 58 174
print(round(avg_read_rps), round(peak_read_rps)) # 5787 17361
# Load that reaches the database after the cache
db_read_rps = peak_read_rps * (1 - cache_hit_ratio)
print(round(db_read_rps)) # 1736
# Bandwidth at peak, in megabits per second
mbps = peak_read_rps * redirect_response_bytes * 8 / 1_000_000
print(round(mbps, 1)) # 69.4
# Concurrent in-flight requests (Little's law: rate x time in system)
print(round(peak_read_rps * mean_latency_s)) # 347
# Storage
records = new_urls_per_day * 365 * retention_years
raw_tb = records * record_bytes / 1e12
replicated_tb = raw_tb * replication_factor
provisioned_tb = replicated_tb / target_utilization
print(round(raw_tb, 2)) # 4.56
print(round(replicated_tb, 2)) # 13.69
print(round(provisioned_tb, 2)) # 19.55Reading the results:
- The service is read-heavy: about 17,000 redirects per second at peak against 174 creations per second.
- Writes are easy for almost any database. The read path is where the 100 ms latency target is tested.
- A 90% cache hit ratio cuts database reads from about 17,000 to about 1,700 per second. That ratio is itself an assumption, so state it.
- Storage grows to about 4.6 TB of raw data. Replication and headroom bring the provisioned figure to about 20 TB. That is modest, so the durability target (NFR-3) costs more in replication design than in disk.
Storage estimation details
Raw data is only the start. Add these items before you commit to a number:
- Replication. Three copies means three times the storage.
- Indexes. A secondary index on a large table can add 20% to 100% of the table size.
- Overhead. Row headers, page fill and compression change the real record size. Measure a sample row when you can.
- Headroom. Running disks near full harms performance and leaves no room for growth or rebuilds after a failure.
- Growth. If usage grows 50% a year, a five-year figure based on today's rate is too low.
Sanity checks and common errors
- Compare your result with a reference point. One modern server commonly handles thousands of simple requests per second, and one database node can store several terabytes. If your estimate says you need a million servers, check the arithmetic.
- Use round numbers. 86,400 seconds is close to 100,000. If the rounded and exact results differ by more than a factor of two, look for a mistake.
- Do not treat the estimate as a final answer. Revisit it when a stakeholder corrects an assumption or when real traffic data arrives.
- Record which result drives each decision. The 17,000 reads per second justifies a cache. The 20 TB figure justifies partitioning or not.
Exercise
A service has 2 million daily active users. Each makes 10 requests per day. Peak traffic is 4 times the average. What are the average and peak request rates per second?
Show answer
Requests per day = 2,000,000 x 10 = 20,000,000. Average = 20,000,000 / 86,400, about 231 requests per second. Peak = 231.5 x 4, about 926 requests per second.
Exercise
A system stores 1,000,000 new items per day. Each item is 2 KB (2,000 bytes). Data is kept for 2 years and stored in 3 replicas. How much storage is needed before indexes and headroom?
Show answer
Items = 1,000,000 x 365 x 2 = 730,000,000. Raw size = 730,000,000 x 2,000 bytes = 1.46 TB. With 3 replicas, about 4.38 TB.