Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 6

Back-of-the-Envelope System Estimation

Recommended resources

Welcome to the final lesson of our first module. In our previous lessons, we've built a strong foundation, covering scalability, system architectures, data storage, consistency trade-offs, and finally, the deployment and orchestration of services using Docker and Kubernetes. We now understand the building blocks of a distributed system and how to package and manage them.

Today, we address a crucial question that ties all these concepts together: how much? How much compute power, storage capacity, and network bandwidth will our system need? This is the art of back-of-the-envelope (BOE) estimation, a skill that is non-negotiable for senior engineers and a cornerstone of the ML system design interview. By the end of this lesson, you will be able to perform these estimations for a system's compute, storage, and network requirements, grounding your architectural decisions in quantitative reasoning.

The Art of Approximation

In a system design interview, and in real-world planning, you are not expected to produce perfectly accurate figures. The goal is to be directionally correct and to demonstrate a structured thought process. It's about knowing whether you need 10 servers or 100, a terabyte of storage or a petabyte. This ability to reason about scale is what separates a speculative design from a grounded one.

Let's begin by understanding the mindset and importance of this skill.

Back of the Envelope Calculation: A Practical Guide

This guide from SystemDesignHandbook.com perfectly frames why estimation is so critical in system design interviews and what interviewers are looking for.

Please read the introduction and the section on the expected mental model. Focus on what it means to do these calculations and, just as importantly, what it is not about. Then, pay close attention to the concepts of thinking in orders of magnitude and using assumptions.

To reinforce this, the following short video explains how these quick calculations help validate design choices instantly.

Back-Of-The-Envelope Estimation / Capacity Planning

This video from ByteByteGo provides a succinct overview of the purpose of BOE math.

Watch the initial segment from the introduction, which illustrates how a simple estimation can immediately inform architectural needs like load balancing or database sharding.


A Framework for Estimation

To avoid getting lost in the numbers, it's essential to follow a structured approach. This not only keeps your thoughts organized under pressure but also signals to an interviewer that you have a repeatable, mature process.

A robust framework for BOE calculations involves five steps:

  1. Clarify Scope: Explicitly state what you are estimating (e.g., peak write QPS, 5-year storage growth).
  2. State Assumptions: Announce your assumptions about user numbers, behavior, data sizes, etc. This makes your reasoning transparent and invites collaboration.
  3. Decompose the Problem: Break the large estimation task into smaller, manageable parts (e.g., traffic, storage, bandwidth).
  4. Estimate Components: Calculate each part using simple math and aggressive rounding.
  5. Synthesize and Sanity-Check: Combine the estimates and evaluate if the final number seems reasonable. Don't be afraid to self-correct.

The following resource details this framework and provides the fundamental units you'll need.

Back of the Envelope Calculation: A Practical Guide

This part of the guide provides the core tools for estimation.

First, familiarize yourself with the core units for time, traffic, and data size. You don't need to memorize them all, but be comfortable with the orders of magnitude (e.g., ~86,400 seconds in a day, 1 GB is 1 billion bytes). Then, read through the five-step framework to internalize the process.

Now, let's see this framework applied in a practical example.

Capacity Planning and Estimation | System Design for Beginners

This video by Shiran Afergan provides an excellent, clear walkthrough of a full estimation problem, covering traffic, storage, bandwidth, and cache.

Watch the video from the beginning. Pay close attention to these key steps: Traffic Estimation: How to go from Daily Active Users (DAU) to average and peak Requests Per Second (RPS), using a read/write ratio and aggressive rounding (e.g., 86,400 seconds ≈ 100k seconds). Storage Estimation: How to calculate total storage needs by considering average item size, daily ingestion rate, data retention period, and replication. Note the clean use of powers of 10 for calculation. Bandwidth Estimation: A straightforward calculation of incoming and outgoing data per second. Cache Estimation: How to apply the 80/20 rule to estimate memory requirements for caching.


Estimation in Practice: A Deeper Dive into LLM Inference

While the general framework applies broadly, your background in generative AI means you'll encounter more specific and complex estimation challenges. Let's apply these principles to a modern use case: sizing the infrastructure for Large Language Model (LLM) inference.

Here, the key resources to manage are not just server counts, but specifically GPU memory, which is often the primary bottleneck. The main components consuming GPU memory during LLM inference are:

  1. Model Weights: The parameters of the model itself. A simple estimate is Number of parameters * bytes per parameter. For FP16/BF16 precision, this is 2 bytes per parameter.
  2. KV Cache: A stateful cache that stores the keys (K) and values (V) for all preceding tokens in a sequence. This is what allows the model to generate subsequent tokens without reprocessing the entire input, making generation fast. Its size is dynamic and depends on the number of concurrent users and the length of their sequences.
  3. Activation Memory: Intermediate results stored during the forward pass of the model.

The image below shows a tool that automates these calculations, highlighting the key input parameters and the resulting memory breakdown.

This inference memory calculator shows the key inputs (model, data type, concurrency, sequence length) and the detailed breakdown of memory consumption, including model weights, KV cache, and activation peaks.

Let's break down how to calculate these numbers yourself. The following article provides a detailed guide.

LLM Inference Sizing and Performance Guidance - VMware Blogs

This technical blog from VMware provides the formulas needed to estimate memory requirements for LLM inference.

First, read the section "Understand Your LLM’s Specifications" to see the key model parameters. Then, focus on the section "Calculate the Memory Footprint". The core formula is: \text{GPU Memory} = (\text{Model Parameters} \times \text{Bytes per Param}) + (\text{KV Cache per Token} \times \text{Sequence Length} \times \text{Concurrent Users}) Work through the example provided for Llama-3-8B to solidify your understanding.

With the memory footprint established, we can then estimate the system's capacity (how many users it can serve) and latency (how fast it responds).

  • Capacity: The total available GPU memory (after loading the model weights) divided by the memory required per user determines the maximum number of concurrent requests.
  • Latency: The total response time is the sum of two phases:
    • Prefill Time (Time to First Token - TTFT): The time to process the initial prompt. This is typically a compute-bound operation.
    • Generation Time (Time Per Output Token - TPOT): The time to generate each subsequent token. This is a memory-bandwidth-bound operation.

Let's continue with the same resource to see how these are calculated.

LLM Inference Sizing and Performance Guidance - VMware Blogs

This next section of the blog translates memory calculations into performance and capacity estimates.

First, read "Calculate Estimated Capacity" to see how to determine the maximum number of concurrent requests your GPU setup can handle based on the remaining memory after loading the model. Next, read "Calculate Estimated Latency" to understand the formulas for prefill time and generation time, and how they combine to produce the total estimated response time. Pay attention to the distinction between compute-bound prefill and memory-bound generation.

These LLM-specific calculations are a powerful extension of the general BOE framework. They demonstrate a deep understanding of the underlying workload, which is exactly what top-tier companies look for when hiring for specialized ML system design roles.


Conclusion

This lesson concludes our foundational module by equipping you with a quantitative lens to view system design. You've learned that back-of-the-envelope estimation is not about chasing precision but about establishing scale and making informed architectural trade-offs.

Here are the key takeaways:

  • Purpose of BOE: To quickly create reasonable, order-of-magnitude estimates that ground your design in reality and guide architectural choices like scaling, caching, and data partitioning.
  • A Structured Framework: A five-step process—Clarify, Assume, Decompose, Estimate, Sanity-Check—ensures a clear and defensible analysis, especially in an interview setting.
  • Core Estimation Areas: We focused on the three pillars of system resources: Compute (QPS from user traffic), Storage (data size considering growth and retention), and Network (bandwidth from read/write patterns).
  • Specialized ML Estimation: For complex workloads like LLM inference, we extended the framework to estimate GPU memory, system capacity (concurrent users), and latency (TTFT and TPOT), which are the critical constraints.

With this, you have completed the first module, "Foundations of Distributed Systems for ML." You now possess a solid understanding of the core principles and technologies that underpin scalable ML systems.

In our next lesson, we will begin Module 2: Data Management and Governance in ML. We'll move up the stack to the lifeblood of any ML system—the data itself—and start by learning how to design robust data ingestion pipelines for both batch and streaming sources.