Estimating Scale in a Design Interview
Estimating scale in a design interview is the skill of turning plain user numbers into requests, storage, and bandwidth figures. The arithmetic uses round numbers and powers of ten.
The recognition signal
An estimation question asks how many, how much, or how fast. The prompts below are the signals.
prompts = [
"How many users will use it?",
"How much storage will it need?",
"How many requests arrive each second?",
]
for p in prompts:
print("Estimate: " + p)The estimation template
Ten million users making five requests each give fifty million daily requests. Dividing by 86400 gives about 579 requests per second.
daily_users = 10000000
requests_each = 5
daily_requests = daily_users * requests_each
per_second = round(daily_requests / 86400)
print("Daily requests:", daily_requests)
print("Requests per second:", per_second)Worked problem: photo storage
One million photos a day at 200000 bytes each need 200000000000 bytes a day. That is 200 gigabytes a day.
photos_per_day = 1000000
bytes_each = 200000
bytes_per_day = photos_per_day * bytes_each
print("Storage per day (GB):", bytes_per_day // 1000000000)Example
daily_users = 20000000
requests_each = 10
daily_requests = daily_users * requests_each
print("Daily requests:", daily_requests)
print("Requests per second:", round(daily_requests / 86400))
posts_per_day = 2000000
bytes_each = 500
print("Storage per day (GB):", posts_per_day * bytes_each // 1000000000)Key points
- Start from daily users, not from components.
- Requests per second equal daily requests divided by 86400, the seconds in a day.
- Storage equals items per day times the average size of one item.
- Bandwidth equals requests times the average size of one reply.
- Round to powers of ten and state each assumption out loud.
- Estimating scale turns user numbers into request, storage, and bandwidth figures.
Twenty million users making ten requests each give two hundred million daily requests. Dividing by 86400 gives about 2315 requests per second. Two million posts at 500 bytes each need 1 gigabyte a day.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Python Playground
Exercise
One hundred million requests arrive in one day. About how many requests per second is that?