Building Software

Engineering Fundamentals for the Agent Era

Contents Section 4, Math and Algorithms

Back-of-the-Envelope Estimation

Mistakes to catch in review

  1. A design that needs tens of thousands of writes per second from a single database node sized for a few thousand.

  2. An agent pipeline that calls a model once per row across a million rows, with nobody having estimated the bill.

  3. Logging or telemetry volume that costs more than the service it describes.

Quick order-of-magnitude math for storage, throughput, latency, cost and time, done before building so bad designs fail on paper.

Topics

Orders of Magnitude and Powers of Two
The handful of numbers worth memorizing, and rounding aggressively to get a fast answer.
Throughput and Latency Budgets
Splitting a response-time target across the steps of a request, and turning requests per second into load per component.
Storage and Bandwidth Math
Estimating data size, growth and transfer volume over time.
Cost Estimation
Pricing compute, storage, data transfer and model tokens before they appear on an invoice.
Units and Sanity Checks
Carrying units through every calculation and comparing results against a known reference point.

You understand it when you can

  • Estimate a year of storage for an event stream from its rate and record size, within an order of magnitude.
  • Estimate the monthly model cost of a feature from its request volume and tokens per request.
  • Redo a number in a design document with units attached and catch an error of a factor of a thousand or more.

Drill

An agent's design stores every page view as a 2 KB JSON row in one database table and makes one model call per view to classify it, for a site with 20 million views a day. Estimate the yearly storage and the daily model cost, and find the part of the design that fails first.

Start here

Watch

From "napkin math" to turbopuffer

Simon Eskildsen, 2026. 56-minute interview.

Eskildsen describes how napkin-math cost and latency estimates shaped the architecture of a database company, connecting estimation to real design and cost decisions.

Read

Programming Pearls

Jon Bentley, 1999, 2nd edition.

Column 7, "The Back of the Envelope", is the canonical short text on order-of-magnitude estimates, the Rule of 72, safety factors and checking an answer against a second method.

Systems Performance: Enterprise and the Cloud

Brendan Gregg, 2020, 2nd edition.

Its methodology and capacity-planning material shows how to turn request rates into load on CPU, memory, disk and network and find which resource saturates first.

Street-Fighting Mathematics: The Art of Educated Guessing and Opportunistic Problem Solving

Sanjoy Mahajan, 2010.

Teaches dimensional analysis, rounding and sanity checks for quick order-of-magnitude answers, the habits behind carrying units through a calculation.

Primary sources

  • Reference

    napkin-math (Simon Eskildsen, GitHub)

    A maintained table of measured base rates for memory, disk, network, serialization and cloud cost, with the benchmark code that produced them, to use as reference points for any estimate.