Sub topic 4
Estimate traffic, storage, and bandwidth
This chapter assumes you have already written down requirements and stated assumptions for the problem. It also assumes you can read short Python snippets and know what a request, a database, and a cache are. Here you turn those assumptions into numbers that guide the design.
Why estimate at all
A back-of-envelope estimate is a quick calculation that is accurate to within a factor of two or three. Its job is to tell you which kind of system you need. It does not predict exact costs.
The numbers answer questions that shape the architecture:
- Can one database server handle the writes, or do you need partitioning?
- Does the data fit on one machine's disks, or must it spread across many?
- Will a cache help, and how much memory would it need?
- Does the network link become a bottleneck?
If an estimate says you need 600 writes per second, a single well-tuned database is probably enough. If it says 600,000, it is not. The two answers lead to different designs, and you only need the estimate to be right within an order of magnitude to choose between them.
Start from stated assumptions
Every estimate is a chain of multiplications from inputs you chose. Write the inputs down first, so a reviewer can challenge any of them without redoing the whole calculation.
For this chapter, use these assumptions:
- 10 million daily active users (DAU), meaning distinct users who use the product on a given day.
- Each user performs 5 writes and 100 reads per day.
- Each record is 500 bytes.
- Peak traffic is 2 times the daily average.
The ratio of reads to writes is 20 to 1. This ratio is one of the most useful numbers in the estimate. It tells you whether the system is read-heavy, which favors caching and read replicas, or write-heavy, which favors partitioning and queues.
Traffic: queries per second
Queries per second (QPS) is the number of requests the system handles each second. Convert daily totals to a per-second rate by dividing by the seconds in a day:
- Seconds per day: 24 × 60 × 60 = 86,400. Rounding to 100,000 is common in interviews and costs about 15% accuracy. Use the exact figure when the arithmetic is easy to do in code.
- Average write QPS: 10,000,000 × 5 / 86,400 ≈ 579.
- Average read QPS: 10,000,000 × 100 / 86,400 ≈ 11,574.
The following script performs these calculations and the storage calculation that comes next.
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 579 average write QPS, 1157 peak write QPS, 11574 average read QPS, 25.0 GB per day, and 9.1 TB per year.
Average versus peak
Users do not spread their activity evenly across 24 hours. Most traffic arrives in a few busy hours, so you must size the system for the peak and not the average. A peak factor of 2 to 3 is a reasonable default for consumer products. Products tied to events, such as ticket sales or live sports, can see factors of 10 or more. State the factor you chose and why.
Storage
Storage is the number of records, times the size of each record, times how long you keep them.
- New data per day: 10,000,000 × 5 × 500 bytes = 25 GB.
- New data per year: 25 GB × 365 ≈ 9.1 TB.
This is raw payload. Real storage is larger, and three multipliers usually matter:
- Replication. Keeping 3 copies of every record triples the disk you need.
- Indexes and metadata. Secondary indexes, row headers, and write-ahead logs often add 20% to 100% on top of the payload. Pick a factor and state it.
- Retention. Decide how many years you keep data. Five years of 9.1 TB is 45.6 TB before replication.
Multiply them together to get a planning figure. Here, 5 years × 9.1 TB × 3 replicas is about 137 TB, before index overhead. That is more than one server holds comfortably, which is an early signal that you will need partitioning.
Bandwidth
Bandwidth is the amount of data moved per second. Compute it separately for incoming traffic (ingress) and outgoing traffic (egress), because they usually differ and are often billed differently.
- Ingress is write QPS times the request size.
- Egress is read QPS times the response size.
Be careful with the response size. If a read returns a list of 20 records, the response is about 10 KB and not 500 bytes, which makes egress 20 times larger. Always ask what a single read returns.
The next script extends the estimate with bandwidth, multi-year replicated storage, and a cache size. It assumes each read returns one 500-byte record.
DAU = 10_000_000
WRITES_PER_USER_PER_DAY = 5
READS_PER_USER_PER_DAY = 100
RECORD_BYTES = 500
READ_RESPONSE_BYTES = 500
SECONDS_PER_DAY = 86_400
PEAK_FACTOR = 2
REPLICAS = 3
YEARS = 5
HOT_FRACTION = 0.2
write_qps = DAU * WRITES_PER_USER_PER_DAY / SECONDS_PER_DAY
read_qps = DAU * READS_PER_USER_PER_DAY / SECONDS_PER_DAY
def mbps(bytes_per_second: float) -> float:
return bytes_per_second * 8 / 1e6
ingress = mbps(write_qps * RECORD_BYTES)
egress = mbps(read_qps * READ_RESPONSE_BYTES)
raw_tb = DAU * WRITES_PER_USER_PER_DAY * RECORD_BYTES * 365 * YEARS / 1e12
replicated_tb = raw_tb * REPLICAS
daily_read_gb = DAU * READS_PER_USER_PER_DAY * READ_RESPONSE_BYTES / 1e9
cache_gb = daily_read_gb * HOT_FRACTION
print(f"average ingress: {ingress:.1f} Mbps")
print(f"average egress: {egress:.1f} Mbps")
print(f"peak egress: {egress * PEAK_FACTOR:.1f} Mbps")
print(f"raw storage ({YEARS}y): {raw_tb:.1f} TB")
print(f"replicated: {replicated_tb:.1f} TB")
print(f"daily read volume: {daily_read_gb:.0f} GB")
print(f"cache estimate: {cache_gb:.0f} GB")The output is 2.3 Mbps average ingress, 46.3 Mbps average egress, 92.6 Mbps peak egress, 45.6 TB raw storage, 136.9 TB replicated, 500 GB of daily read volume, and a 100 GB cache estimate.
The bandwidth figures are small. A single modern network interface handles 92.6 Mbps easily, so network is not the bottleneck in this design. Finding that out is a useful result. You can move on without spending design effort there.
Where the cache figure comes from
The cache estimate uses a common rule of thumb: roughly 20% of the data serves 80% of the reads. Caching 20% of one day's read volume (500 GB) gives 100 GB. This is an upper bound, because many reads hit the same records and the real working set is often smaller. It still tells you the cache fits in the memory of a small cluster and not in one machine's RAM.
How the estimate flows
Each number depends on the ones before it. Changing one assumption changes everything downstream, which is why you write the assumptions down first.
Turning numbers into design decisions
An estimate matters only if it changes what you do. Read the results against the design:
| Result | What it suggests |
|---|---|
| 1,157 peak write QPS | A single primary database can likely handle this, so partitioning is not needed for write throughput. |
| 11,574 average read QPS | Read replicas or a cache will take load off the primary. |
| About 137 TB replicated over 5 years | Storage must be spread across several machines, so plan partitioning by key. |
| 92.6 Mbps peak egress | Network is not a constraint. |
| 100 GB cache estimate | A distributed cache of a few nodes is enough. |
Notice that the write rate does not force partitioning, but the total data volume does. Throughput and capacity are separate questions, and a design can be limited by one and not the other.
Common errors
- Mixing units. Bytes versus bits is the most frequent mistake. Network figures are in bits per second, so multiply bytes by 8, as the
mbpsfunction does. - Mixing decimal and binary prefixes. Treating 1 GB as 10^9 bytes is fine for estimation. Just be consistent.
- Forgetting the peak. Report both average and peak figures.
- Ignoring response size. A paginated list returns many records per read. Estimate the size of the full response.
- False precision. Reporting 11,574.07 QPS suggests accuracy you do not have. Round to 11,500 or "about 12,000" when you present it.
- Skipping the sanity check. Compare your result with known systems. If your estimate for a small product implies petabytes per day, an assumption is probably wrong.
Exercises
Exercise
A smaller product has 1 million daily active users. Each user makes 2 writes and 50 reads per day. Compute the average write QPS and average read QPS using 86,400 seconds per day. If the peak factor is 3, what is the peak read QPS?
Show answer
Average write QPS = 1,000,000 × 2 / 86,400 ≈ 23. Average read QPS = 1,000,000 × 50 / 86,400 ≈ 579. Peak read QPS = 579 × 3 ≈ 1,736.
Exercise
A read returns a page of 20 records, each 500 bytes, instead of one record. Using the 11,574 average read QPS from this chapter, what is the average egress bandwidth in Mbps, and how does it compare with the 46.3 Mbps figure for single-record reads?
Show answer
Each response is 20 × 500 = 10,000 bytes. Egress = 11,574 × 10,000 bytes per second = about 115.7 MB/s, which is about 926 Mbps. This is 20 times the single-record figure, and it approaches the capacity of a 1 Gbps link, so network now matters for the design.