Back-of-the-Envelope Calculations
Overview
Back-of-the-envelope calculations are rough estimates used to determine the scale of a system before you design it. By approximating traffic, storage, and bandwidth, you can make informed decisions about database choices, caching strategies, and network architecture.
Key Concepts
The "Magic Numbers" to Memorize
To do these calculations quickly, you must memorize basic data sizes and time conversions:
- Data sizes: Char = 1 byte; Integer = 4 or 8 bytes; UUID = 16 bytes; Short string = 100 bytes; JSON payload ~ 1-2 KB; Image ~ 1-5 MB; Video ~ 50-100 MB.
- Time conversions: 1 day ~ 100,000 seconds (actually 86,400, but 100k makes math easy). 1 month ~ 30 days.
- Powers of 10 vs 2: 1 KB ~ 1,000 bytes. 1 MB ~ 1,000 KB (1 Million bytes). 1 GB ~ 1 Billion bytes. 1 TB ~ 1 Trillion bytes.
The Basic Formula
Most estimations follow this pattern:
- Determine Daily Active Users (DAU).
- Estimate the number of actions per user per day.
- Multiply to get total daily events.
- Divide by 100,000 to get events per second (QPS).
- Multiply events by the average size of the data payload to get Storage/Bandwidth.
Trade-offs
These calculations are intentionally imprecise. The tradeoff is speed over accuracy. You are aiming to be within a factor of 10 (an order of magnitude). If your estimate says you need 5 TB of storage, it doesn't matter if the real number is 4 TB or 6 TB; it matters that it's not 500 TB. The danger is getting bogged down in perfect arithmetic and wasting interview time.
Interview Tips
- Always round numbers to make math easy (e.g., round 86,400 seconds in a day to 100,000). Tell the interviewer you are doing this.
- Write down your assumptions clearly. "Assuming 10 million DAU and each user sends 5 messages a day..."
- Use these numbers to justify architectural choices later. "Since we only have 100 QPS but 10 PB of data, I'm choosing a highly scalable object store rather than focusing on aggressive load balancing."
Summary
- Back-of-the-envelope calculations determine the order of magnitude of a system's scale.
- Memorize that there are roughly 100,000 seconds in a day for easy QPS math.
- Estimate Daily Active Users (DAU) and actions-per-user first.
- Speed and scale (Orders of Magnitude) matter more than perfect precision.
- Use the results to justify your database and architecture choices.