Sub topic 14
Sanity Checks and Common Pitfalls
This chapter assumes you can convert daily active users (DAU) to queries per second (QPS), estimate storage over a retention period, and read short Python snippets. It covers how to check an estimate before it drives a design, and the mistakes that most often break one.
Why check an estimate
An estimate is a chain of multiplications. One wrong factor of 1,000 early in the chain carries through to every later number. A quick check against known reference points catches most of these errors in seconds.
Sanity-check techniques
- Compare to a known system. If your design for 10 million DAU needs 5 million QPS, something is off. Average load is usually a few thousand QPS at that scale.
- Recompute a different way. Estimate the same quantity from a second direction and see whether the answers land within a factor of 2 to 3.
- Check units on every line. Write the unit next to each number. If you multiply records by bytes, the result must be bytes.
- Check the order of magnitude. Count the digits. A result of 91 TB should not be written as 91 PB.
- Ask whether it is physically plausible. One server cannot serve 10 million QPS from disk. A 1 Gbps link cannot carry 5 Gbps.
Common pitfalls
| Pitfall | Example | Fix |
|---|---|---|
| Bits versus bytes | Network speeds are in bits per second, storage in bytes | Divide bits by 8 to get bytes |
| Decimal versus binary units | 1 TB is 10^12 bytes, 1 TiB is 2^40 bytes | Pick one and state it. The gap is about 10% at TB scale |
| Average versus peak | Sizing servers for 1,157 QPS when peak is 2,315 | Apply a peak factor and state it |
| Forgetting retention | Counting one day of writes, not five years | Multiply by retention days |
| Ignoring replication | Storing one copy when you keep three | Multiply storage by the replica count |
| False precision | Reporting 1,157.407 QPS | Round to 1,200 and say "about" |
| Wrong day length | Using 100,000 s when you meant 86,400 | Round to 10^5 only if you say so |
Worked check: storage
Suppose you estimate 100 million new records per day at 500 bytes each, kept for 5 years. The code below recomputes that estimate and checks it against a rougher version rounded to powers of ten.
new_records_per_day = 100_000_000
bytes_per_record = 500
retention_days = 365 * 5
exact = new_records_per_day * bytes_per_record * retention_days
rough = 1e8 * 5e2 * 2e3 # 2e3 days is a rounded 1,825
print(exact / 1e12) # 91.25 TB
print(rough / 1e12) # 100.0 TB
print(abs(rough - exact) / exact < 0.15) # TrueThe rough and exact answers agree within about 10%. Both are on the order of 100 TB, so the estimate passes. If you also keep three replicas, the raw total becomes about 270 TB, which is a different design decision. Check that you counted replicas before you trust the number.
Check availability too
Allowed downtime is another place for unit slips. At 99.9% availability, the allowed downtime is about 526 minutes per year, which is roughly 8.8 hours. At 99.99%, it is about 53 minutes. If you quote "99.99% means 5 minutes a year," you are off by a factor of 10, and the check against the nines table would have caught it.
State what you left out
A good estimate ends with its limits. Say which factors you ignored, such as metadata overhead, indexes, compression, and traffic growth. Naming them lets a reviewer judge whether the omission could change the answer by more than a factor of 2.
Exercise
An estimate says a service with 1 million DAU, each making 20 requests per day, needs 2,000 QPS on average. Is this plausible? Find the likely error.
Show answer
Average QPS is 1,000,000 * 20 / 86,400, which is about 231 QPS. The figure of 2,000 is roughly 9 times too high. The likely cause is dividing by 10,000 instead of 86,400, or applying a peak factor and calling it the average. Even with a peak factor of 2, the result is about 460 QPS.
Exercise
A link is rated 1 Gbps. Your estimate needs 200 MB per second of egress. Does it fit?
Show answer
No. 200 MB/s is 1,600 Mbps, or 1.6 Gbps, because one byte is 8 bits. That is more than the 1 Gbps link can carry, so you need a faster link or several links.