Estimates That Decide Something
An estimate belongs in the round only when its result changes a decision: a cache or none, one machine or many, how many nodes, how long a key. Before the arithmetic, say which decision it feeds. After it, say what it decided.
An estimate that decides nothing gets one sentence saying so, and the minute it would have taken goes to the design. This lesson takes the numbers the practice question agreed in the last lesson and turns them into decisions, out loud.
An Estimate Earns Its Place
The test is the one a clarifying question passes, applied to arithmetic: name the decision first. If no decision comes to mind, the estimate is habit, and the interviewer watches the minutes go on it.
The URL shortener's Scope in Chapter 7 is the model. The reads decide the read path. The storage decides that the data is partitioned, and the count of links decides how long the key is. The writes and the bandwidth decide nothing, and the page says so in a sentence each instead of working them out at length or dropping them in silence.
Four Quantities and What Each Decides
Four quantities cover most rounds, and each one leads to a different part of the design.
- Requests a second, with writes and reads counted apart. They lead to different parts of the design, so a single total hides the one that matters.
- The read-write ratio. A read-heavy system points to caches and replicas (Chapter 2). A write-heavy one points to partitioning for writes and to logs (Chapters 3 and 6).
- Storage over the retention, with copies. It decides one machine or many (Chapter 3, lesson 1).
- Bandwidth. It rarely decides anything for small records. For media it often does: an hour of streamed HD video is about 3 gigabytes, and the video problem in Chapter 19 is sized by numbers like that one.
Rounding for the Room
A day has 86,400 seconds. Round it to 100,000. The error is 16 percent, and it changes no decision in a design built on round numbers. With the room's day, a million a day is about 10 a second. With the exact day it is about 12, and nothing on the board moves between the two. The estimator near the end of this lesson has a switch between the two days, so you can watch whether any decision moves.
Peak is the other convention. Assume twice the average unless the problem says otherwise, and say the word assume, so the interviewer can move it. Machines are sized for the peak. The average sets the storage and the bill.
Say each step as one operation, and follow the result at once with what it means. Twenty million a day, over a hundred thousand seconds, is about 200 a second: a listener can hold that. A formula with a decimal in it is gone before the next sentence starts. The figures in this course may show the full arithmetic; the spoken version keeps one step to a sentence.
The Sheet, and What It Leaves Out
Every reference value in this course comes from one sheet of sourced numbers, so the arithmetic agrees from the first problem to the last. A handful of them carry most estimates.
The latency ladder comes first. A read from main memory takes about 100 nanoseconds. A random read from an NVMe drive takes about a tenth of a millisecond, a thousand times longer. A round trip between two zones of one region takes 1 to 2 milliseconds. A round trip from the eastern United States to western Europe takes about 85 milliseconds, so a click that needs three of them, one after another, spends about a quarter of a second before any work is done.
Then the capacities. One in-memory cache node handles about 100,000 simple operations a second and holds about 100 gigabytes. A 10-gigabit network link carries about one and a quarter gigabytes a second.
The ladder's origin is Jeff Dean's 2007 talk and its list of "Numbers Everyone Should Know", and the course cites it as history. The values above are today's, read from current sources.
The sheet also has gaps, on purpose. It gives no throughput for one relational database, because no published run the course found states both its hardware and its method, and a number without both is a guess. When a decision rests on a capacity the sheet lacks, state it as an assumption and agree it. The URL shortener assumes 2 terabytes per storage node that way, and so does this lesson.
One Estimate, Spoken
The practice question's estimate, as the room hears it, is four short steps.
The writes first. Twenty million comments a day, over about 100,000 seconds, is about 200 a second. At a peak of twice the average, that is 400. Nothing in this design is sized by that yet, and one sentence says so.
Then the reads. Thirty reads for each comment is about 6,000 reads a second, and 12,000 at peak. One cache node handles about 100,000 simple operations a second, so the peak is about an eighth of one node's rate. The read rate does not set the size of the cache. Its memory does, and Chapter 2's caching lesson sizes it that way.
Then the storage. Each day adds 20 million comments at about a kilobyte each, which is 20 gigabytes. A year of that is about 7 terabytes. Three years is about 22. With three copies, it is about 66 terabytes. Assume 2 terabytes per storage node, and that is about 33 nodes, so the data is partitioned from the first design on.
Bandwidth comes last and gets one sentence. At peak, 12,000 reads a second at a kilobyte each is 12 megabytes a second, against more than a gigabyte a second on one link. It decides nothing, so you skip it and say why. You might say: "Bandwidth is about 12 megabytes a second at peak, far under one link, so I'll leave it there."
Two of the four estimates decided something: the reads moved the cache's sizing from its rate to its memory, and the storage put partitions into the first design. The other two took a sentence each. The next lesson gives those 66 terabytes a shape, and picks the store and its key.
- "A precise estimate is a better estimate." The interviewer judges whether the number moved a decision. Precision past the first digit costs time and decides nothing more.
- "Every Scope needs requests, storage and bandwidth." It needs the ones that decide. Working out all of them by habit is the URL shortener's first Scope pitfall in a wider form: minutes spent on numbers that change nothing.
- "The average rate sizes the system." Machines are sized for the peak. The average sets the storage and the bill.
- "I should know what one database can handle." No number for that is reliable without its hardware and its workload, and the interviewer knows it. State the capacity as an assumption and let the interviewer move it.
- "Bandwidth never matters." It decides nothing for kilobyte comments and decides the whole cost curve for video.
- Name the decision an estimate feeds before you compute it, and say what the result means right after.
- Round a day to 100,000 seconds and assume a peak of twice the average, out loud.
- Take every reference value from the numbers sheet, and state any capacity it lacks as an assumption the interviewer can change.
- Drop an estimate that decides nothing, in one sentence that says why.
Knowledge Check
For the comments question, which estimate can you state in one sentence and then drop?
- The storage over three years, about 66 TB with copies
- The bandwidth at peak, about 12 megabytes a second
- The peak reads, about 12,000 a second against one node
- The memory needed to cache the most-read comments
A problem has one million new records a day. About how many is that a second?
- About 700 a second, dividing by the 1,440 minutes in a day
- About 10 with the room's day, or about 12 with the exact one
- About 100 a second, with the day rounded to 10,000 seconds
- About 42,000 a second, dividing by the 24 hours in a day
Why are machines sized from the peak rate while storage is sized from the average?
- Storage is cheaper than machines, so it can be sized more loosely
- Machines must carry the busiest minute; storage adds up every write
- Peak traffic is all reads, and reads never add anything to storage
- The average is the more accurate number, and storage plans years ahead
A decision rests on one relational database's write capacity, and the numbers sheet has none. What do you do?
- State a capacity as an assumption and let the interviewer move it
- Quote the figure a vendor's benchmark page gives for its product
- Leave the decision open until the deep dives, when it may come up
- Assume the database can take any load, since it is the source of truth
Twenty million comments a day at about 1 KB each, kept three years with three copies. About how much storage is that?
- About 22 TB, each comment counted once over the three years
- About 7 TB, which is one year of comments with every copy
- About 66 TB, which at 2 TB a node is about 33 storage nodes
- About 660 TB, which needs hundreds of storage nodes
You got correct