AlgoViz

Back-of-the-envelope calculations

easy 25 min

A back-of-the-envelope calculation is a quick, rounded sum that tells you whether a design is feasible.

See it run

Four steps, five sums, and how far an input may move before the decision changes.

Operations

Clarify to evaluate

One estimate in the four CAFE steps, with a decision at the end.

Step 1 of 5

Clarify

StepSaid aloudOn paper
ClarifyDaily users? How many views?reads per second
Assume
Figure
Peak
Evaluate

What is asked: reads a second. Ask for daily users and views per user.

Step 1: Clarify

DAY = 86_400def peak(users, per_user, factor=3):    daily = users * per_user    return daily / DAY * factordef machines(peak, capacity=1_000):    return ceil(peak / (capacity * 0.7)) + 1
When
One minute
You leave with
Machines to plan

Say the assumption before the arithmetic. If it is wrong, someone can stop you early.

In the real world

The same back-of-the-envelope calculations doing real jobs. Pick one and step through it.

Someone presents 10 billion clicks a day from 1 million users.

Step 1 of 4

The claim

CheckWorkingVerdict
The claim1M users, 10B clicks a day?
Per person
Per second
So

It sounds impressive, and nobody objects.

Step 1: The claim

Common mistakes

The bugs interviewers watch for, with the fix beside each.

  • Storing the reads

    critical

    Multiplying all requests by the record size counts every view as new data. Only writes add bytes.

    Wrong
    stored = daily_requests * size * 365
    Right
    stored = daily_writes * size * 365
  • Rounding machines down

    major

    round(2.4) is 2, which cannot carry 2.4 machines of work. Round up, then add a spare.

    Wrong
    servers = round(peak / capacity)
    Right
    servers = ceil(peak / (capacity * 0.7)) + 1
  • Bits and bytes mixed

    major

    Networks are sold in bits a second, files are measured in bytes. The slip is a factor of eight.

    Wrong
    gbps = rate * bytes_each / 1e9
    Right
    gbps = rate * bytes_each * 8 / 1e9
  • Planning for the average

    critical

    Average load never overloads anything on paper. The evening does.

    Wrong
    plan(daily / 86_400)
    Right
    plan(daily / 86_400 * 3)

Interview tips

  • How to explain it

    • A rough sum that decides something.
    • Right number of zeros, not right digits.
    • Assumptions said aloud.
  • Memory trick: CAFE

    • C: clarify what is asked.
    • A: assume, and say it.
    • F: figure with round numbers.
    • E: evaluate: true? so what?
  • Numbers to know

    • 86,400 s a day, about 100,000.
    • 1M a day is 12 a second, 1B is 12,000.
    • Peak is three times average.
  • Stop when

    • Half and double give the same decision.
    • Nobody waits for the number.
    • Only a measurement can answer it.