What is a back of the envelope calculation?
A back of the envelope calculation is a quick, rough estimate made with round numbers and simple math, the kind you could do on the back of an envelope. It aims to be right within a factor of about 2 to 10, not exact. In a system design interview, it sizes the system: requests per second, storage and bandwidth, at average and peak load.
How do you do a back of the envelope calculation in a system design interview?
State your assumptions (daily active users, actions per user, data sizes, read to write ratio) and check them with the interviewer. Divide daily counts by about 100,000 seconds to get requests per second, and multiply by a peak factor of 2 to 3. For storage, multiply writes per day by the size of each write, then by 365, the years you keep data and the number of replicas. For bandwidth, multiply requests per second by the payload size. Then say what the numbers mean for the design. The whole step should take about 4 minutes.
How do you calculate QPS from daily active users?
Multiply daily active users by the actions each one takes per day, then divide by 86,400 seconds. For example, 10 million users making 10 requests a day is 100 million requests, and 100 million divided by 86,400 is about 1,160 requests per second on average. Multiply by a peak factor, such as 3, to get the peak: about 3,500 per second.
How many seconds are in a day, and why round to 100,000?
There are 86,400 seconds in a day (24 × 60 × 60). Rounding to 100,000 makes the math easy: divide by 10 to the 5th power. It makes per-second numbers about 14% low, so round your answer up a little, or remember a few exact pairs: 1 million a day is about 12 a second, and 1 billion a day is about 11,600 a second.
What are the latency numbers every programmer should know?
They are a list of rough costs for common operations, popularized by Jeff Dean and Peter Norvig. The commonly cited values: L1 cache reference 0.5 ns, main memory reference 100 ns, sending 1 KB over a 1 Gbps network 10 µs, reading 4 KB at random from an SSD 150 µs, a round trip within a data center 500 µs, a disk seek 10 ms, and a packet from California to the Netherlands and back 150 ms. Modern hardware is faster in places, especially SSDs and networks, but the gaps between memory, disk and network are still huge.
How precise should my estimates be?
One or two significant figures is enough. Say "about 1,200 requests a second", not "1,157.4". Interviewers care that your numbers are the right order of magnitude and that you use them to make design choices, such as adding a cache or sharding a database.
What peak factor should I use?
For most consumer apps, a peak of 2 to 3 times the daily average is a fair starting point. Use more for spiky traffic: a flash sale, a ticket on-sale, a live event or a marketing blast can run 10 times average or far more. Say the number you picked and why.
Do I need to memorize powers of two?
Just the main ones: 2 to the 10th is about a thousand (KB), 2 to the 20th about a million (MB), 2 to the 30th about a billion (GB) and 2 to the 40th about a trillion (TB). In estimates, treat 1 KB as 1,000 bytes. The gap between binary and decimal units is about 2% at KB and about 10% at TB, which rarely changes a design.