Sub topic 4
Estimate traffic, storage, and bandwidth
This chapter assumes you know how client-server systems work, can read short Python snippets, and have used HTTP APIs and databases. It covers back-of-envelope estimation: rough arithmetic that tells you which order of magnitude your design must handle.
Why estimate at all
An estimate does not need to be exact. It needs to be right within a factor of two or three. The result tells you whether one database server is enough or whether you need partitioning, and whether caching matters. A system serving 50 requests per second and one serving 50,000 need different designs.
Estimate from the assumptions you wrote down in the previous chapter. If an assumption changes, the numbers change with it, and you can redo the arithmetic quickly.
The working model
Three quantities cover most estimates:
- Traffic is requests per second, usually written QPS (queries per second). Split it into reads and writes, because they scale differently.
- Storage is how much data you accumulate over time.
- Bandwidth is bytes per second moving in or out of the system.
The basic steps are:
- Start from daily active users (DAU).
- Multiply by actions per user per day to get requests per day.
- Divide by 86,400 seconds in a day to get average QPS.
- Multiply by a peak factor, commonly 2 to 3, to get peak QPS.
- Multiply writes by record size to get storage growth.
A worked example
Assume 10 million DAU. Each user makes 5 writes and 100 reads per day. Each record is 500 bytes. The script below applies the steps.
DAU = 10_000_000
WRITES_PER_USER_PER_DAY = 5
READS_PER_USER_PER_DAY = 100
RECORD_BYTES = 500
SECONDS_PER_DAY = 86_400
PEAK_FACTOR = 2
write_qps = DAU * WRITES_PER_USER_PER_DAY / SECONDS_PER_DAY
read_qps = DAU * READS_PER_USER_PER_DAY / SECONDS_PER_DAY
storage_per_day_gb = DAU * WRITES_PER_USER_PER_DAY * RECORD_BYTES / 1e9
storage_per_year_tb = storage_per_day_gb * 365 / 1000
print(f"average write QPS: {write_qps:.0f}")
print(f"peak write QPS: {write_qps * PEAK_FACTOR:.0f}")
print(f"average read QPS: {read_qps:.0f}")
print(f"storage per day: {storage_per_day_gb:.1f} GB")
print(f"storage per year: {storage_per_year_tb:.1f} TB")The output is about 579 average write QPS, 1,157 peak write QPS, 11,574 average read QPS, 25 GB per day, and 9.1 TB per year.
Read the results as design inputs:
- Reads outnumber writes 20 to 1, so caching and read replicas are likely to pay off.
- About 1,157 peak writes per second is within reach of a single well-provisioned database, but not with much headroom. Plan for partitioning if growth is expected.
- 9.1 TB per year fits on one large disk array but is awkward to back up and query. Over several years it pushes you toward partitioned storage.
Bandwidth
Bandwidth follows from QPS and payload size. If each read returns a 500-byte record, peak read traffic is about 23,148 QPS times 500 bytes, which is roughly 11.6 MB per second, or 93 Mbit/s. That is modest. If each response also carries a 200 KB image, the same QPS needs about 4.6 GB per second, and you would need a content delivery network (CDN). Payload size can change the design more than QPS does.
Common errors
- Mixing units. Bytes and bits differ by a factor of 8. Network capacity is quoted in bits, storage in bytes.
- Using the average as the limit. Traffic is uneven. Size for peak, not average.
- Forgetting overhead. Indexes, replicas, and metadata multiply raw storage. Three replicas triple the disk you need.
- Hiding assumptions. A number without its inputs cannot be checked or corrected.
- False precision. Round aggressively. Say "about 600 writes per second", not "578.7".
Exercise
A service has 2 million DAU. Each user makes 20 writes per day, and each record is 1 KB. Using a peak factor of 3, what are the average write QPS, the peak write QPS, and the storage added per day? Use 86,400 seconds per day and 1 KB = 1,000 bytes.
Show answer
Writes per day = 2,000,000 x 20 = 40,000,000. Average write QPS = 40,000,000 / 86,400, about 463. Peak write QPS = 463 x 3, about 1,389. Storage per day = 40,000,000 x 1,000 bytes = 40 GB, before replication and indexes.