"Estimating the Unseen: Mastering Back of Envelope Calculations"
Introduction
Back of envelope calculations is an essential skill for system designers, allowing them to quickly estimate the feasibility and requirements of a system. In this masterclass, we will delve into the world of back of envelope calculations, focusing on estimating requests per second, storage, bandwidth, and memory requirements.
Requests per Second (RPS) Estimation
Estimating the number of requests per second is crucial for designing a system that can handle the expected load. To calculate RPS, we need to consider the following factors:
- Total users: The total number of users interacting with the system.
- Average requests per user: The average number of requests each user makes per unit of time (e.g., per minute, per hour).
- Time unit: The unit of time used to calculate the average requests per user (e.g., seconds, minutes, hours).
RPS Formula
RPS = (Total users * Average requests per user) / Time unit
Example
Let's say we're designing a social media platform with 1 million active users. On average, each user makes 5 requests per minute (e.g., loading their feed, commenting on a post, liking a photo). We want to calculate the RPS for our system.
RPS = (1,000,000 users * 5 requests/minute) / 60 seconds/minute = approximately 83,333 RPS
Storage Estimation
Estimating storage requirements is vital for designing a system that can store and retrieve data efficiently. To calculate storage needs, we need to consider the following factors:
- Data size: The average size of each data unit (e.g., image, video, text document).
- Total data units: The total number of data units stored in the system.
- Storage overhead: The additional storage required for metadata, indexing, and other overheads.
Storage Formula
Storage = (Data size * Total data units) + Storage overhead
Example
Let's say we're designing an image-sharing platform that stores 10 million images, each with an average size of 2 MB. We also need to account for 10% storage overhead for metadata and indexing.
Storage = (2 MB/image * 10,000,000 images) + (10% * 20,000,000 MB) = approximately 22,000,000 MB or 22 TB
Bandwidth Estimation
Estimating bandwidth requirements is crucial for designing a system that can handle data transfer efficiently. To calculate bandwidth needs, we need to consider the following factors:
- Data transfer size: The average size of each data transfer unit (e.g., image, video, text document).
- Total data transfers: The total number of data transfers per unit of time (e.g., per second, per minute).
- Bandwidth overhead: The additional bandwidth required for protocol overheads, packet headers, and other overheads.
Bandwidth Formula
Bandwidth = (Data transfer size * Total data transfers) + Bandwidth overhead
Example
Let's say we're designing a video-streaming platform that transfers 100,000 video segments per minute, each with an average size of 10 MB. We also need to account for 20% bandwidth overhead for protocol overheads and packet headers.
Bandwidth = (10 MB/segment * 100,000 segments/minute) + (20% * 1,000,000 MB/minute) = approximately 1,200,000 MB/minute or 20 Gbps
Memory Estimation
Estimating memory requirements is vital for designing a system that can handle data processing efficiently. To calculate memory needs, we need to consider the following factors:
- Data processing size: The average size of each data processing unit (e.g., image, video, text document).
- Total data processing units: The total number of data processing units per unit of time (e.g., per second, per minute).
- Memory overhead: The additional memory required for data structures, caching, and other overheads.
Memory Formula
Memory = (Data processing size * Total data processing units) + Memory overhead
Example
Let's say we're designing an image-processing platform that processes 50,000 images per minute, each with an average size of 5 MB. We also need to account for 30% memory overhead for data structures and caching.
Memory = (5 MB/image * 50,000 images/minute) + (30% * 250,000 MB/minute) = approximately 325,000 MB/minute or 5.4 GB/minute
Conclusion
Back of envelope calculations is an essential skill for system designers, allowing them to quickly estimate the feasibility and requirements of a system. By using the formulas and examples provided in this masterclass, you can estimate requests per second, storage, bandwidth, and memory requirements for your system.
Best Practices
- Always consider the worst-case scenario when estimating system requirements.
- Use historical data and industry benchmarks to inform your estimates.
- Continuously monitor and adjust your estimates as the system evolves.
⚔️ YOUR MISSION
Mission: Estimate System Requirements for a Social Media Platform
Design a social media platform that can handle 10 million active users, each making 10 requests per minute. Estimate the requests per second, storage, bandwidth, and memory requirements for the system. Assume an average data size of 2 MB per user and 20% storage overhead. Use the formulas and examples provided in the masterclass to guide your estimates.
Read the exercise prompt
Initial Query: Estimate Requests per Second
SELECT
(total_users * avg_requests_per_user) / time_unit AS rps
FROM
system_metrics
WHERE
total_users = 10000000 AND
avg_requests_per_user = 10 AND
time_unit = 60;
