Skip to lesson

Estimation practice

A tired estimate often has the right method and one wrong unit, which makes the answer 24 or 1,000 times off. Drills build speed and teach you to spot that mistake.

Five timed drills with one method

An estimation drill is a short, timed exercise: given a product, estimate its traffic and storage in about five minutes, always in the same order.

The method never changes: write assumptions, compute average and peak RPS, compute storage per year, then decide. The code runs five classic drills: photo app, chat app, URL shortener, ShopLite and logs.

Example 1 · Five drills, one method

FiveDrillsDemo.javaJava
import java.util.List;
record Drill(String name, double dau, double requestsPerUser, double writesPerUser, double bytesPerWrite, int peak) {    double avgRps() { return dau * requestsPerUser / 86_400; }    double peakRps() { return avgRps() * peak; }    double storagePerYearGb() { return dau * writesPerUser * bytesPerWrite * 365 / 1e9; }}
public class FiveDrillsDemo {    public static void main(String[] args) {        List<Drill> drills = List.of(                new Drill("Photo app", 10e6, 50, 2, 2_000_000, 3),                new Drill("Chat app", 50e6, 100, 40, 200, 3),                new Drill("URL shortener", 1e6, 100, 1, 500, 5),            // 1 new link, 100 clicks                new Drill("ShopLite", 1e6, 30, 0.2, 200, 5),                // 5% buy, 4 writes each                new Drill("Logs, 200 servers", 200, 864_000, 864_000, 300, 2)); // 10 lines/s each
        System.out.printf("%-18s %10s %10s %14s%n", "drill", "avg RPS", "peak RPS", "storage/year");        for (Drill d : drills) {            System.out.printf("%-18s %,10.0f %,10.0f %,11.0f GB%n", d.name(), d.avgRps(), d.peakRps(), d.storagePerYearGb());        }    }}
Output
drill                 avg RPS   peak RPS   storage/year
Photo app               5,787     17,361  14,600,000 GB
Chat app               57,870    173,611     146,000 GB
URL shortener           1,157      5,787         183 GB
ShopLite                  347      1,736          15 GB
Logs, 200 servers       2,000      4,000      18,922 GB

What this code does

  • Every drill uses the same two formulas: RPS = users × requests ÷ 86,400 and storage = users × writes × bytes × 365. Only the assumptions change.
  • For logs the "users" are 200 servers, each writing 10 lines a second (864,000 a day). The method works for machines as well as people.
  • Notice the spread: the photo app needs about 15 PB a year, which only object storage can hold, while ShopLite needs about 15 GB.

Only the assumptions change between drills, so practise saying each one aloud with a reason, such as "50 million users, because it is a national app". The arithmetic then becomes quick.

Finding the unit mistake

A unit mistake is a right method with one wrong unit: seconds per hour instead of per day, KB used as bytes, MB/s compared with Mbit/s. The size of the error points to the cause.

The code shows three estimates, each with one wrong unit, next to the right answer and the size of the error.

Example 2 · Find the unit mistake: three estimates

UnitMistakesDemo.javaJava
public class UnitMistakesDemo {    public static void main(String[] args) {        double wrong1 = 2e6 * 20 / 3_600;        double right1 = 2e6 * 20 / 86_400;        System.out.printf("1. RPS: wrong %,.0f, right %,.0f (24x too big)%n", wrong1, right1);
        double wrong2 = 1e5 * 300 / 1e9;                 // 300 "bytes"        double right2 = 1e5 * 300_000 / 1e9;             // 300 KB = 300,000 bytes        System.out.printf("2. Images: wrong %.2f GB, right %.0f GB (1,000x too small)%n", wrong2, right2);
        // 3. MB/s compared with a link speed in Mbit/s        double mbPerSecond = 150;        System.out.println("3. Link of 1,000 Mbit/s: wrong \"150 < 1000, fine\"; right "                + (mbPerSecond * 8) + " Mbit/s, which is " + (mbPerSecond * 8 > 1_000 ? "too much" : "fine"));    }}
Output
1. RPS: wrong 11,111, right 463 (24x too big)
2. Images: wrong 0.03 GB, right 30 GB (1,000x too small)
3. Link of 1,000 Mbit/s: wrong "150 < 1000, fine"; right 1200.0 Mbit/s, which is too much

What this code does

  • Each mistake is one wrong unit: hours instead of days, KB instead of bytes, bytes instead of bits. The size of the error (24×, 1,000×, 8×) is a clue to which one it is.
  • A habit that catches all three: write the unit next to every number and check that they cancel to the unit you want.

The size of the error is a clue: 24× points to hours vs days, 1,000× to KB vs bytes or ms vs µs, 8× to bytes vs bits, and 365× to a missing "per year".

Find the bug

Find the unit mistake

Click the line that gives the wrong answer.

This should print the size of 100,000 images of 300 KB each, in GB.

Round 1 of 3

Converting estimates into counts

A spare is an extra server or node on top of the busy ones, so that one failure does not cause an outage.

App servers = peak RPS ÷ (one server's RPS × target use) + spare; cache nodes = cache bytes ÷ node memory. The code turns ShopLite's estimates into servers, Redis nodes and disks.

Example 3 · From estimates to server, cache and storage counts

CountsDemo.javaJava
public class CountsDemo {    public static void main(String[] args) {        double peakRps = 17_361;          // ShopLite in 3 years        double perServer = 500;        double cacheBytes = 150_000 * 5_000 * 0.2 * 2;        double dbBytes = 600e9;        double imageBytes = 1.4e12;
        int appServers = (int) Math.ceil(peakRps / (perServer * 0.7)) + 1;        int redisNodes = (int) Math.ceil(cacheBytes / 1e9);              // 1 GB nodes        int dbDisksTb = (int) Math.ceil(dbBytes * 1.3 / 1e12);           // 30% free space        System.out.println("App servers:      " + appServers + " (500 RPS each, 70% busy, 1 spare)");        System.out.println("Redis nodes:      " + redisNodes + " x 1 GB (+1 replica for failover)");        System.out.println("MySQL disk:       " + dbDisksTb + " TB per server (primary and each replica)");        System.out.printf("Object storage:   %.1f TB of images%n", imageBytes / 1e12);    }}
Output
App servers:      51 (500 RPS each, 70% busy, 1 spare)
Redis nodes:      1 x 1 GB (+1 replica for failover)
MySQL disk:       1 TB per server (primary and each replica)
Object storage:   1.4 TB of images

What this code does

  • The last step of every estimate is a count of real things: servers, cache nodes, disk sizes. Always round up and add a spare where a failure would hurt.
  • Each line keeps its assumptions in the code (500 RPS per server, 1 GB Redis nodes, 30% free disk), so a reviewer can change one and see the effect.

Round up every time, and add a spare wherever one failure would take the service down. Disk per database server = data × (1 + free space).

Estimating cache memory for a hot set

The hot set is the small share of items that gets most of the reads, such as the popular products or the newest links. The cache must hold exactly this part.

Cache memory = hot items × bytes per entry × overhead. The code sizes a URL shortener's cache two ways: the 80/20 rule, and "only the last 7 days".

Example 4 · Cache memory for a URL shortener's hot links

HotLinksCacheDemo.javaJava
public class HotLinksCacheDemo {    public static void main(String[] args) {        double newLinksPerDay = 1e6;        int yearsKept = 5;        double totalLinks = newLinksPerDay * 365 * yearsKept;        int bytesPerEntry = 100;                      // short code + long URL in the cache        double hotShare = 0.20;        double overhead = 2;
        double cacheBytes = totalLinks * hotShare * bytesPerEntry * overhead;        System.out.printf("Links stored: %.2f billion%n", totalLinks / 1e9);        System.out.printf("Hot 20%% in cache: %.0f GB%n", cacheBytes / 1e9);
        // Most clicks go to links made in the last few days: cache only those instead        double recentLinks = newLinksPerDay * 7;        System.out.printf("Only last 7 days in cache: %.1f GB%n", recentLinks * bytesPerEntry * overhead / 1e9);    }}
Output
Links stored: 1.83 billion
Hot 20% in cache: 73 GB
Only last 7 days in cache: 1.4 GB

What this code does

  • Applied blindly, the 80/20 rule says 73 GB of cache for 1.8 billion links: several large Redis nodes.
  • Knowing the traffic pattern changes the answer. If most clicks hit links from the last week, caching only those needs about 1.4 GB. A better assumption beats a bigger cache.

The 80/20 rule is only a starting point. In a URL shortener or a news site most reads go to items created in the last few days, so the hot set is "recent items". Say which assumption you used, because it changes the answer more than any other number.

Interview drill: the questions that come up

These prompts appear in placement rounds again and again. Answer each in under three minutes, out loud, with rounded numbers.

"Estimate QPS for 10M DAU": about 2,000–2,500 average, about 10,000 at a 5× peak, if each user makes 20 requests. "How much storage for a chat app in 5 years?": messages per day × bytes × 365 × 5, then replicas and growth. "How many servers for 20,000 peak RPS?": divide by one server's load-test number at 70%, add spares. "How big a cache?": hot items × bytes × overhead, and say your hot-set assumption.

Your turn: a five-minute drill

Set a five-minute timer. ShopLite adds support chat: 100,000 DAU, 20 messages each a day, about 150 bytes a message, kept one year. Write your own two answers first, then check.

Predict the output

Estimate, then check

Do the sum yourself, then pick the closest answer.

Round 1 of 2

About how many messages arrive per second on average?

long dau = 100_000;
int messagesPerUser = 20;
// messages per second = ?

Next step

Check your understanding

12 quick questions