AlgoViz

Resource estimation examples

medium 30 min

Five complete estimates, each from the given facts to a decision: a timeline, a URL shortener, video streaming, chat and a shop.

Video lesson · Chapter 1 of 6

A timeline amplifies a write

0:00 / 5:43

Same sums, five different answers

1:20Reel coming soon

Theory

Read or listen first. About 1 min.

What it is

Resource estimation turns what people do with a product into what its machines need: requests a second, terabytes, gigabits a second, open connections, servers.

The same handful of sums is used each time. What changes is which of them matters. Video is a bandwidth problem, chat is a connection problem, a link shortener is a read problem, and a flash sale is a problem of one row that everybody wants.

Why it exists

Reading about estimation is not enough; the skill is choosing which facts to multiply. Worked examples show the choice as well as the arithmetic.

They also show how estimates fail. Given facts can contradict each other, and only a check with a second method reveals it. One of the examples below does exactly that.

A short history

  1. 1909

    Agner Krarup Erlang publishes a first paper on telephone traffic, "The theory of probabilities and telephone conversations": how many lines does an exchange need for the calls that arrive?

  2. 1961

    John Little proves that the average number in a system is the arrival rate times the average time spent, the law used below to count viewers.

  3. 2016

    Google's Site Reliability Engineering book describes capacity planning from the intent of a service instead of from a list of machines.

Words to know

DAU, MAU
Daily and monthly active users.
Read to write ratio
How many reads happen for each write. Say whether you count requests or items.
Concurrent users
People using the service at the same moment.
Replication factor
How many copies are kept, often three.
Bitrate
Bits of video or audio a second.
PoP
Point of presence: a place where a content network keeps servers.
Flash sale
A sale that starts at a set moment, so people arrive together.

How it works

Step through the idea, or press Play.

Step 1 of 3

Facts. Users, what each does, how big, how long kept

Understand it

Start here

One trip, five questions

A school plans a day out. One trip raises several questions, and each needs its own sum. How long the coaches take at the gate says nothing about the luggage. A system is the same: traffic, storage, bandwidth and machines are separate sums about one product.

The class trip
50 seats50 seats50 seats120 ÷ 50 = 2.4, so 3 coaches

Different questions need different sums.

The checklist

Six steps for any system

  1. 1

    Clarify users and behaviour

    Daily or monthly users? What does each do, how often?

  2. 2

    Compute reads and writes

    Separately. They lead to different parts.

  3. 3

    Take the peak

    Three times average on an ordinary day. For a sale, count the people who arrive.

  4. 4

    Work out storage

    New items × size × time kept, with and without copies.

  5. 5

    Work out bandwidth

    Peak × response size × 8.

  6. 6

    Count machines

    Peak / (capacity × 0.7), rounded up, plus one spare.

From facts to the limit

Multipliers to start with

SituationMultiplierRemember
Ordinary peak3 × averageAn assumption until you have a graph
Sale or viral eventoften said to be 10 ×Better: people / seconds between their requests
Copies of data3 ×Say storage both ways; object stores keep their own copies
Spare capacityplan at 70%, plus one machineInstead of a 1.5 or 2 times guess
How and when to estimate at all: Back-of-the-envelope and Numbers that decide.

Example 1

A timeline service

Given: 500 million daily users, 10 timeline views each, 100 posts a view, 1 new post per user, 1 KB a post, kept 5 years, peak three times average.

SumWorkingResultSo
Reads500M × 10 / 86,40058,000/s, peak 174,000/stimelines are prepared and cached
Writes500M / 86,4005,800/s, peak 17,400/spast one database: split
Storage500 GB a day × 365 × 5913 TB, 2.7 PB with 3 copiespartition posts
Bandwidth58,000 × 100 KB5.8 GB/s, 46 Gb/s; peak 139 Gb/scompress, send fewer posts first
Machines191,000 / 700273, plus one spare: 274at an assumed 1,000/s each

Two ratios, not one

5B views500M posts=10:15B×100 posts read500M=1,000:1\frac{5\text{B views}}{500\text{M posts}} = 10 : 1 \qquad \frac{5\text{B} \times 100\ \text{posts read}}{500\text{M}} = 1{,}000 : 1
Ten requests read for each one written, but a thousand posts. The second ratio is why preparing timelines in advance pays.

Example 2

A URL shortener

Given: 100 million new links a month, 100 reads for each write, 500 bytes a record, kept 10 years.

SumWorkingResultSo
Writes100M / 2.6M s40/s (38.6)any database
Reads× 1004,000/s, peak 12,000/sa cache in front; links rarely change
Links100M × 12 × 1012 billionlength of the code
Storage12B × 500 B6 TB, 18 TB with copiesone large database still holds it
Bandwidth12,000 × 500 B6 MB/s, 48 Mb/snothing depends on it

How long is the code?

626=56.8 billion627=3.5 trillion12 billion needed62^{6} = 56.8\ \text{billion} \qquad 62^{7} = 3.5\ \text{trillion} \qquad 12\ \text{billion needed}
Base 62 is a to z, A to Z and 0 to 9. Six characters are enough to count to 12 billion (21% used). Seven leave codes sparse, so random ones rarely collide and are hard to guess. Full design: URL shortener.

Example 3

Video streaming

Given: 100 million daily users, 1 million viewers at once at peak, 5 Mb/s, 10,000 new videos a day of 1 GB, 5 qualities, 1 hour watched per user a day, kept forever.

SumWorkingResultSo
Bytes out1M × 5 Mb/s5 Tb/sa content network, not our servers
New storage10,000 × 1 GB × 550 TB a day, 18 PB a yearobject storage, cold tier for old videos
Uploads10 TB / 86,400116 MB/s, 930 Mb/seasy; transcoding is the work
Places5 Tb/s / 100 Gb/s50 PoPs at full useat an assumed 100 Gb/s each

Little's law on the viewers

100M×1 h24 h=4.2M on average,×3=12.5M at peak;⇒;62.5 Tb/s\frac{100\text{M} \times 1\,\text{h}}{24\,\text{h}} = 4.2\text{M on average}, \qquad \times 3 = 12.5\text{M at peak} ;\Rightarrow; 62.5\ \text{Tb/s}
So the bandwidth is 12.5 times larger, and 625 PoPs of 100 Gb/s. If one million is right, people watch under five minutes a day on average. Ask which fact to keep.

Five qualities do not weigh five times the top one. With bitrates of 8, 5, 2.5, 1 and 0.5 Mb/s the whole set is 17 / 8 = 2.1 times the largest file: about 21 TB a day instead of 50. The sum above is a safe upper bound; say so.

Where the numbers push the design

Viewers receive video from a content network. Inside our system, an upload service writes videos to object storage, a transcoding worker makes five qualities, and the content network fetches from object storage.
930 Mb/s comes in, terabits go out. The outgoing side never touches our servers.

Example 4

Chat

Given: 500 million daily users, 50 messages each of 100 bytes, 5% carry an image of 200 KB, groups of 10 on average, kept 5 years, 100 million people connected at once.

SumWorkingResultSo
Messages25B / 86,400290,000/s, peak 870,000/ssplit by conversation
Deliveries× 9 if all go to groups of 10up to 2.6M/s, peak 7.8M/sfan-out is the real load
Gateways100M / (100,000 × 0.7)1,429, plus one: 1,4301,000 would be full, with no spare
Memory100,000 × 20 KB2 GB a gatewaymemory is not the limit
Text25B × 100 B2.5 TB a daya store made for many writes
Images1.25B × 200 KB250 TB a dayobject storage
100,000 connections a gateway and 20 KB a connection are assumptions to test.

One message, nine deliveries

The write is counted once and the delivery nine times. Estimate both.

Keep everything, or not?

252.5 TBday×1,825=461 PBor250×30+2.5×1,825=12 PB252.5\,\tfrac{\text{TB}}{\text{day}} \times 1{,}825 = 461\ \text{PB} \qquad\text{or}\qquad 250 \times 30 + 2.5 \times 1{,}825 = 12\ \text{PB}
Keeping all for five years against keeping images for 30 days and text for five years. The second is 38 times smaller. A product rule beats any machine.

Example 5

A shop

Given: 50 million daily users, 20 page views each, 100 million products of 10 KB, 5 images of 500 KB each, 5 million orders a day, 10 times the average in a flash sale.

SumWorkingResultSo
Pages1B / 86,40011,600/s; sale 116,000/scache product pages
Orders5M / 86,40058/s; sale 580/sone database in total, but see below
Product data100M × 10 KB1 TBone database
Images100M × 5 × 500 KB250 TBobject storage and a content network
Search index2 to 3 × the data, assumed2 to 3 TBa few search nodes

Count people instead of guessing 10 times

2M shoppers10 s between requests=200,000/sagainst10×11,600=116,000/s\frac{2\text{M shoppers}}{10\ \text{s between requests}} = 200{,}000/\text{s} \quad\text{against}\quad 10 \times 11{,}600 = 116{,}000/\text{s}
Two million waiting shoppers is an assumption too, but one that marketing can check.

Compare

Five systems, five limits

SystemPeak requestsStorageBytes outLimit
Timeline174,000/s2.7 PB with copies139 Gb/sreads and fan-out
URL shortener12,000/s18 TB with copies48 Mb/sread rate, mildly
Videofew18 PB a year5 to 63 Tb/sbandwidth
Chat870,000/s461 PB, or 12 PB69 Gb/s of images inconnections, media kept
Shop116,000/s250 TB of images9 Gb/s of page textone hot product
Video counts viewers, not requests. Chat: 870,000 × 5% × 200 KB = 8.7 GB/s. Shop: 116,000 × 10 KB = 1.2 GB/s.

What each one taught

  • Timeline

    Say which ratio you mean: requests or items.

  • Shortener

    A famous product can be a small system.

  • Video

    Check given facts against each other.

  • Chat

    How long to keep data is the biggest lever.

  • Shop

    Totals hide a hot spot.

  • All

    Stop when no decision is waiting.

Which limit is it?

Several may be yes. Start with the first that forces a part.

Word for word

Saying it aloud

A photo app in two minutes

  1. Interviewer

    A million people upload two photos a day. Size it.

  2. You

    Two million uploads a day is 20 a second by the shortcut, about 70 at peak. So uploads need no special design.

  3. You

    At 500 KB each that is 1 TB a day, 365 TB a year. So object storage, and I would ask if originals are kept.

  4. You

    If each person views 100 photos, 100 million a day is 1,200 a second, 3,500 at peak, times 500 KB is 1.7 GB a second, 14 Gb/s. So a content network and smaller images.

  5. Interviewer

    And the metadata?

  6. You

    Two million rows of 1 KB is 2 GB a day, 730 GB a year. So one database. I am done unless you want servers.

Check the facts with a second method

Python
users, hours = 100_000_000, 1average = users * hours / 24peak = average * 3print(f"viewers at once: {average:,.0f} average, {peak:,.0f} peak")print(f"bytes out: {peak * 5 / 1e6:.1f} Tb/s (given: 1M viewers, 5 Tb/s)")
The check that caught the video facts.
Edit and run it in your browser

Summary

The whole topic in one minute.

For every system: clarify users and behaviour, compute reads and writes, take the peak, then storage, bandwidth and machines, and stop when nothing else decides anything.

The limit differs: timelines need precomputed reads and split storage, short links need a cache, video needs a content network and a check of concurrent viewers, chat needs gateways and deletion of media, and a sale needs protection for one hot row. Always check given facts against each other.

  • Same sums, different limit: find the limit.
  • Reads, writes, deliveries: count what really happens.
  • Check facts with a second method.
  • Retention and product rules save more than machines.
  • A fine total can hide one hot row.

Sources