Sub topic 14
Sanity Checks and Common Pitfalls
This chapter assumes you can already chain the estimates from earlier chapters: daily active users (DAU) to queries per second (QPS), records to storage, QPS and payload size to bandwidth, and QPS to server count. It does not introduce a new formula. It covers how to check a finished estimate and which mistakes show up most often.
Why a final check matters
An estimate is only useful if it is right to within a factor of about 2 to 10. Most errors are much larger than that. A misplaced unit or a forgotten multiplier gives a 1,000x error, and a design built on that number is wrong from the start.
Arithmetic is rarely the cause. The usual causes are:
- Mixing units, such as bits and bytes, or per day and per second.
- Using the wrong time base.
- Reporting average load where the design needs peak load.
- Omitting a multiplier such as replication.
You can catch all of these cheaply if you check each result before you use it.
Pitfall 1: unit mistakes
Unit errors cause the largest mistakes. Check three things.
Bits versus bytes. Storage and payload sizes are usually in bytes. Network links are rated in bits per second. Multiply bytes per second by 8 to get bits per second.
Decimal versus binary prefixes. A kilobyte is 1,000 bytes in decimal and 1,024 in binary. The gap is 2.4% at kilo and about 10% at tera. In an order-of-magnitude estimate you can use either, but use one throughout and say which.
Skipping a step in the ladder. Going from MB to TB means three decimal steps of 1,000, not two. Write the ladder down: KB, MB, GB, TB, PB.
The following example turns the peak QPS from the traffic chapter into link bandwidth. It assumes a 100 KB response.
def mb_per_s_to_gbps(mb_per_s):
return mb_per_s * 8 / 1000
peak_qps = 2315
response_kb = 100
mb_per_s = peak_qps * response_kb / 1000
print(round(mb_per_s, 1)) # 231.5 (megabytes per second)
print(round(mb_per_s_to_gbps(mb_per_s), 2)) # 1.85 (gigabits per second)The same load is 231.5 MB/s or 1.85 Gbps. A 1 Gbps network card cannot carry it. Someone who reports "231 Mbps" has dropped the factor of 8 and would pick hardware that is far too small.
Pitfall 2: wrong time bases
The day-to-second conversion appears in almost every estimate. Common slips:
- Using 24 x 60 x 60 incorrectly, or using 8,640 or 864,000 by mistake. A day is 86,400 seconds, and it is fine to round to about 10^5 when you need speed.
- Treating a month as 31 days in one place and 30 days in another. Pick 30 and keep it.
- Forgetting that retention is in days while traffic is in seconds. Convert one to match the other.
Rounding 86,400 up to 100,000 costs about 16%. That is small next to the uncertainty in your inputs. The next snippet shows the cross-check.
dau = 10_000_000
requests_per_user_per_day = 10
seconds_per_day = 86_400
# Method A: exact seconds per day
avg_qps_a = dau * requests_per_user_per_day / seconds_per_day
# Method B: rounded to 10^5 seconds per day, easy to do in your head
avg_qps_b = dau * requests_per_user_per_day / 100_000
ratio = avg_qps_a / avg_qps_b
print(round(avg_qps_a), round(avg_qps_b), round(ratio, 2))
# 1157 1000 1.16
assert 0.5 < ratio < 2The two methods agree within 16%. If they differed by 10x, one of them would contain an error.
Pitfall 3: average versus peak
Average QPS describes the whole day. Servers fail at the busiest moment, so you must size for peak. The 10 million DAU example gave an average of 1,157 QPS and a peak of 2,315 with an assumed factor of 2.
Related mistakes:
- Applying the peak factor twice, once to QPS and again to bandwidth derived from that peak QPS.
- Applying the peak factor to storage. Storage grows with total volume, not with the busiest second.
- Using a peak factor of 2 for traffic that is naturally spiky. Events, launches and time-zone clustering can push the factor to 5 or 10. State the factor as an assumption.
Pitfall 4: false precision and rounding drift
An answer such as "2,314.8 QPS" suggests accuracy you do not have. Your inputs, such as 10 requests per user per day, may be wrong by a factor of 2. Report roughly 2,000 to 2,500 QPS, or say "a few thousand".
Rounding can also drift. Rounding up at every step compounds. If you round five numbers up by 20% each, the final result is about 2.5x too high. When you round, alternate directions or keep exact numbers until the last step.
Pitfall 5: forgotten multipliers
A raw calculation often leaves out factors that apply in practice. Check the list below each time.
| Forgotten factor | Typical effect | Where it applies |
|---|---|---|
| Replication | 3x storage | Storage, and write bandwidth between nodes |
| Indexes and metadata | 1.2x to 2x storage | Databases |
| Headroom | 1.5x to 2x servers | Server count |
| Read amplification | Several reads per request | Backend QPS |
| Cache hit rate | Reduces database QPS by the hit fraction | Database load |
| Growth | Next year's numbers, not today's | All of them |
For the earlier storage example of 100 million records per day, 500 bytes each, kept for 5 years, the raw figure is 91.25 TB. With 3 replicas, the cluster must hold about 274 TB. Quoting 91 TB and buying disks for it would leave you short by two thirds.
Sanity-check techniques
Use these in order. Each takes under a minute.
- Check the magnitude. Count the zeros. Does the answer have the right number of digits for its unit? For example, a single machine holding 5 PB is suspect.
- Calculate by a second route. Compute storage bottom-up (records x size x days) and top-down (storage per day x days). Compute traffic from DAU and also from a per-user rate. If the two disagree by more than about 3x, find the discrepancy.
- Compare with a known reference. One commodity server handles roughly hundreds to a few thousand simple requests per second. A single SSD holds a few terabytes. A single server holds hundreds of gigabytes of RAM. If your answer says one machine must serve 500,000 database QPS, a assumption has gone wrong.
- Divide by something small. Divide total load by the number of servers and check that the per-server share is sensible.
- Test the extremes. If DAU doubled, would your design change? If an estimate does not change the decision, further precision is wasted effort.
You can encode the plausibility check as a small helper:
def check_range(name, value, low, high):
status = "ok" if low <= value <= high else "CHECK"
print(f"{name}: {value:,.0f} [{status}]")
check_range("peak QPS", 2315, 100, 100_000)
check_range("servers at 1000 QPS each, 50% headroom", 2315 / (1000 * 0.5), 1, 1000)
check_range("storage in TB for 5 years", 91.25, 1, 10_000)
# peak QPS: 2,315 [ok]
# servers at 1000 QPS each, 50% headroom: 4,630 [ok]
# storage in TB for 5 years: 91 [ok]The ranges are your own expectations, written down before you see the result. That habit is more important than the code. The server line prints 4,630 because the expression divides by 0.5 without dividing by 1,000 first. This is a real unit slip, and the range check passes it anyway because the range is wide. The correct figure is 2315 / (1000 x 0.5) = 4.63 servers, rounded up to 5. The lesson is that a loose range cannot replace a unit check.
A checklist before you present
- Every number has a unit.
- Bits and bytes are not mixed.
- Seconds per day is 86,400, or 10^5 if you rounded on purpose.
- You state whether each figure is average or peak.
- Replication, indexes, headroom and growth are included or explicitly excluded.
- A second method agrees within about 3x.
- The answer is rounded to its real precision.
- Your assumptions are written down so a reviewer can change them.
Exercise
A teammate estimates a photo service: 50 million uploads per day, 2 MB each, kept 3 years. They report about 110 TB of storage. Check the result and give a corrected figure.
Show answer
Daily volume is 50,000,000 x 2 MB = 100,000,000 MB = 100 TB per day. Over 3 years (1,095 days) that is about 109,500 TB, or roughly 110 PB. The teammate reported the right digits with the wrong unit and is off by a factor of 1,000. A magnitude check would have caught it: 100 TB per day cannot fill only 110 TB in 3 years.
Exercise
A service must send responses at 400 MB/s at peak. Can a single 1 Gbps network link carry it? What is the minimum number of 1 Gbps links, ignoring headroom?
Show answer
No. 400 MB/s x 8 = 3,200 Mb/s = 3.2 Gbps, which exceeds 1 Gbps. You need at least 4 links (3.2 rounded up) with no headroom, and more once you add headroom, for example 6 links at about 50% utilization.