Learn the art of quick estimation in system design interviews with this comprehensive guide, packed with practical examples and tips for success.

## Introduction

Back-of-the-envelope estimation is a valuable skill for any software engineer, especially during system design interviews. These rough calculations help you quickly assess the feasibility of a proposed solution, estimate its performance, and identify potential bottlenecks. In this blog, we'll cover the key aspects of back-of-the-envelope estimation, practical examples, and tips for successful estimation in interviews.

## What is Back-of-the-Envelope Estimation?

Back-of-the-envelope estimation is a technique used to quickly approximate values and make rough calculations using simple arithmetic and basic assumptions. This method is particularly useful in system design interviews, where interviewers expect candidates to make informed decisions and trade-offs based on rough estimates.

During a system design interview, you'll be asked to design a scalable and reliable system based on a set of requirements. Your ability to make quick estimations is essential for several reasons:

1. Validate proposed solutions: Estimation helps you ensure that your proposed architecture meets the requirements and can handle the expected load.
3. Demonstrate your thought process: Estimation showcases your ability to make informed decisions and trade-offs based on a set of assumptions and constraints.
4. Communicate effectively: Providing estimates helps you effectively communicate your design choices and their implications to the interviewer.

## Estimation Techniques

### 1. Rule of thumb

Rules of thumb are general guidelines or principles that can be applied to make quick and reasonably accurate estimations. They are based on experience and observation, and while not always precise, they can provide valuable insights in the absence of detailed information. For example, estimating that a user will generate 1 MB of data per day on a social media platform can serve as a starting point for capacity planning.

### 2. Approximation

Approximation involves simplifying complex calculations by rounding numbers or using easier-to-compute values. This technique can help derive rough estimates quickly and with minimal effort. For instance, assuming 1,000 users instead of 1,024 when estimating storage requirements can simplify calculations and still provide a reasonable approximation.

### 3. Breakdown and aggregation

Breaking down a problem into smaller components and estimating each separately can make it easier to derive an overall estimate. This technique involves identifying the key components of a system, estimating their individual requirements, and then aggregating these estimates to determine the total system requirements. For example, estimating the storage needs for user data, multimedia content, and metadata separately can help in determining the overall storage requirements of a social media platform.

### 4. Sanity check

A sanity check is a quick evaluation of an estimate to ensure its plausibility and reasonableness. This step helps identify potential errors or oversights in the estimation process and can lead to more accurate and reliable results. For example, comparing the estimated storage requirements for a messaging service with the actual storage used by a similar existing service can help validate the estimate.

## Important numbers every engineer should know

<DIV align="left">Power</DIV><DIV align="left">Approximate value</DIV><DIV align="left">Full name</DIV><DIV align="left">Short name </DIV>
101 Thousand1 Kilobyte1 KB
201 Million1 Megabyte1 MB
301 Billion1 Gigabyte1 GB
401 Trillion1 Terabyte1 TB

## Important latency numbers every engineer should know

<DIV align="left">Operation name</DIV><DIV align="left">Time</DIV>
L1 cache reference0.5 ns
Branch mispredict5 ns
L2 cache reference7 ns
Mutex lock/unlock100 ns
Main memory reference100 ns
Compress 1K bytes with Zippy10,000 ns = 10 µs
Send 2K bytes over 1 Gbps network20,000 ns = 20 µs
Read 1 MB sequentially from memory250,000 ns = 250 µs
Round trip within the same datacenter500,000 ns = 500 µs
Disk seek10,000,000 ns = 10 ms
Read 1 MB sequentially from network10,000,000 ns = 10 ms
Read 1 MB sequentially from disk30,000,000 ns = 30 ms
Send packet CA->Netherlands->CA150,000,000 ns = 150 ms

In system design interviews, there are several types of estimations you may need to make:

1. Load estimation: Predict the expected number of requests per second, data volume, or user traffic for the system.
2. Storage estimation: Estimate the amount of storage required to handle the data generated by the system.
3. Bandwidth estimation: Determine the network bandwidth needed to support the expected traffic and data transfer.
4. Latency estimation: Predict the response time and latency of the system based on its architecture and components.
5. Resource estimation: Estimate the number of servers, CPUs, or memory required to handle the load and maintain desired performance levels.

## Practical Examples

Suppose you're asked to design a social media platform with 100 million daily active users (DAU) and an average of 10 posts per user per day. To estimate the load, you'd calculate the total number of posts generated daily:

<center><b>100 million DAU * 10 posts/user = 1 billion posts/day</b></center>

Then, you can estimate the request rate per second:

<center><b>1 billion posts/day / 86,400 seconds/day ≈ 11,574 requests/second</center></b>

### 2. Storage Estimation

Consider a photo-sharing app with 500 million users and an average of 2 photos uploaded per user per day. Each photo has an average size of 2 MB. To estimate the storage required for one day's worth of photos, you'd calculate:

<center><b>500 million users * 2 photos/user * 2 MB/photo = 2,000,000,000 MB/day</center></b>

### 3. Bandwidth Estimation

For a video streaming service with 10 million users streaming 1080p videos at 4 Mbps, you can estimate the required bandwidth:

<center><b>10 million users * 4 Mbps = 40,000,000 Mbps</center></b>

### 4. Latency Estimation

Suppose you're designing an API that fetches data from multiple sources, and you know that the average latency for each source is 50 ms, 100 ms, and 200 ms, respectively. If the data fetching process is sequential, you can estimate the total latency as follows:

<center><b>50 ms + 100 ms + 200 ms = 350 ms</b></center>

If the data fetching process is parallel, the total latency would be the maximum latency among the sources:

<center><b>max(50 ms, 100 ms, 200 ms) = 200 ms</b></center>

### 5. Resource Estimation

Imagine you're designing a web application that receives 10,000 requests per second, with each request requiring 10 ms of CPU time. To estimate the number of CPU cores needed, you can calculate the total CPU time per second:

<center><b>10,000 requests/second * 10 ms/request = 100,000 ms/second</b></center>

Assuming each CPU core can handle 1,000 ms of processing per second, the number of cores required would be:

<center><b>100,000 ms/second / 1,000 ms/core = 100 cores</b></center>

## System Design Examples

### 1. Designing a messaging service

Imagine you are tasked with designing a messaging service similar to WhatsApp. To estimate the system's requirements, you can start by considering the following aspects:

• Number of users: Estimate the total number of users for the platform. This can be based on market research, competitor analysis, or historical data.
• Messages per user per day: Estimate the average number of messages sent by each user per day. This can be based on user behavior patterns or industry benchmarks.
• Message size: Estimate the average size of a message, considering text, images, videos, and other media content.
• Storage requirements: Calculate the total storage needed to store messages for a specified retention period, taking into account the number of users, messages per user, message size, and data redundancy.
• Bandwidth requirements: Estimate the bandwidth needed to handle the message traffic between users, considering the number of users, messages per user, and message size.

By breaking down the problem into smaller components and applying estimation techniques, you can derive a rough idea of the messaging service's requirements, which can guide your design choices and resource allocation.

### 2. Designing a video streaming platform

Suppose you are designing a video streaming platform similar to Netflix. To estimate the system's requirements, consider the following aspects:

• Number of users: Estimate the total number of users for the platform based on market research, competitor analysis, or historical data.
• Concurrent users: Estimate the number of users who will be streaming videos simultaneously during peak hours.
• Video size and bitrate: Estimate the average size and bitrate of videos on the platform, considering various resolutions and encoding formats.
• Storage requirements: Calculate the total storage needed to store the video content, taking into account the number of videos, their sizes, and data redundancy.
• Bandwidth requirements: Estimate the bandwidth needed to handle the video streaming traffic, considering the number of concurrent users, video bitrates, and user locations.

By applying estimation techniques and aggregating the individual estimates, you can get a ballpark figure of the video streaming platform's requirements, which can inform your design decisions and resource allocation.

## Tips for Successful Estimation in Interviews

Estimation plays a crucial role in system design interviews, as it helps you make informed decisions about your design and demonstrates your understanding of the various factors that impact the performance and scalability of a system. Here are some tips to help you ace the estimation part of your interviews:

### 1. Break down the problem

When faced with a complex system design problem, break it down into smaller, more manageable components. This will make it easier to estimate each component's requirements and help you understand how they interact with each other. By identifying the key components and estimating their requirements separately, you can then aggregate your estimates to get a comprehensive view of the system's needs.

### 2. Use reasonable assumptions

During an interview, you may not have all the necessary information to make precise estimations. In such cases, make reasonable assumptions based on your knowledge of similar systems, industry standards, or user behavior patterns. Clearly state your assumptions to the interviewer, as this demonstrates your thought process and enables them to provide feedback or correct your assumptions if necessary.

Drawing from your past experiences can be beneficial when estimating system requirements. If you have worked on similar systems or have experience with certain technologies, use that knowledge to inform your estimations. This will not only help you make more accurate estimations but also showcase your expertise to the interviewer.

As you progress through the interview, the interviewer may provide additional information or challenge your assumptions, requiring you to adjust your estimations. Be prepared to adapt and revise your estimations accordingly. This demonstrates your ability to think critically and shows that you can handle changing requirements in a real-world scenario.

Don't hesitate to ask the interviewer clarifying questions if you're unsure about a requirement or assumption. This will help you avoid making incorrect estimations and showcase your problem-solving abilities.

### 6. Communicate your thought process

Throughout the estimation process, communicate your thought process clearly to the interviewer. Explain how you arrived at your estimations and the assumptions you made along the way. This allows the interviewer to understand your reasoning, provide feedback, and assess your problem-solving skills.

By following these tips, you can improve your estimation skills and increase your chances of success in system design interviews. Remember that practice makes perfect, so keep honing your estimation techniques and familiarize yourself with different system design scenarios to build your confidence and expertise.

## Conclusion

Back-of-the-envelope estimation is a crucial skill for software engineers preparing for system design interviews. By understanding the types of estimations, practicing with real-world examples, and following the tips mentioned in this blog, you'll be well-equipped to tackle any estimation challenge during your next interview.

To further improve your back-of-the-envelope estimation skills and prepare for system design interviews, consider exploring the following resources:

1. Design Gurus - Grokking the System Design Interview: This online course covers various system design concepts, including estimation techniques, and provides real-world examples to practice with.
2. Design Gurus - System Design Fundamentals: A comprehensive guide on system design fundamentals, including key concepts, best practices, and tips for acing the interview.

By leveraging these resources and practicing regularly, you'll be better prepared to handle any back-of-the-envelope estimation challenge that comes your way during a system design interview.

Good luck, and happy estimating!

FAANG
Scalability