Foundations
Back-of-the-envelope estimation is the practice of using a combination of thought experiments and simple mathematical calculations to quickly arrive at a reasonable estimate for a system's capacity needs. It's one of the most important skills in a system design interview because it demonstrates that you can think about scale and make data-driven decisions.
The goal is not to find the exact right answer, but to be in the right order of magnitude.
Before you can design a system, you need to know what you're designing for.
These estimations will directly influence your choice of technology, architecture, and infrastructure.
You don't need to be a human calculator, but you should have a few key numbers memorized to speed up your calculations.
2^10 = 1,024 ≈ 1 Thousand (Kilo)2^20 = 1,048,576 ≈ 1 Million (Mega)2^30 ≈ 1 Billion (Giga)2^40 ≈ 1 Trillion (Tera)2^50 ≈ 1 Quadrillion (Peta)Key Takeaway: Reading from memory is fast. Reading from disk is slow. Reading over the network is even slower. This is why caching is so important.
24 hours * 60 min/hr * 60 sec/min ≈ 25 * 3600 = 86,400 ≈ 90,000 seconds90,000 * 30 ≈ 2.7 MillionLet's walk through an estimation exercise for a simplified version of Twitter.
Interviewer: "Let's design a service where users can post short text messages. How would you estimate the scale?"
200 Million DAU * 0.5 tweets/DAU = 100 Million tweets per day200 Million DAU * 5 views/DAU = 1 Billion feed views per day1 Billion reads / 100 Million writes = 10:1. This is a very common ratio for social media. The system is "read-heavy".Write QPS:
100 Million tweets / 90,000 seconds ≈ 100,000,000 / 90,000 ≈ 10,000 / 9 ≈ ~1,100 QPS (write)Read QPS:
1 Billion reads / 90,000 seconds ≈ 1,000,000,000 / 90,000 ≈ 100,000 / 9 ≈ ~11,000 QPS (read)Peak QPS: Traffic is not evenly distributed. It often has peaks. A common rule of thumb is to assume peak traffic is 2x - 3x the average.
1,100 * 2 = ~2,200 QPS11,000 * 2 = ~22,000 QPSSize of a single tweet:
tweet_id: 8 bytes (64-bit integer)user_id: 8 bytestext: 280 characters * 2 bytes/char (UTF-8) = 560 bytesmedia_url (optional): ~50 bytestimestamp: 8 bytesStorage per day:
100 Million tweets/day * 700 bytes/tweet = 70 Billion bytes/day = 70 GB per dayStorage for 5 years:
70 GB/day * 365 days/year * 5 years70 * 365 * 5 ≈ 70 * 1800 ≈ 126,000 GB = ~126 TBIngress (Writes):
1,100 QPS * 700 bytes/tweet = 770,000 bytes/sec = ~0.77 MB/sEgress (Reads):
11,000 QPS * (700 bytes/tweet * 20 tweets/view) = 11,000 * 14,000 ≈ 154,000,000 bytes/sec = ~154 MB/sNow you have a concrete set of numbers to guide your design. You know you need a system that can handle thousands of queries per second and store terabytes of data. This immediately tells you that a single server won't be enough, and you'll need to think about load balancing, distributed databases, and caching.