Back-of-envelope estimation and latency numbers
Turn daily users into requests per second, storage and bandwidth in a few minutes, and learn the latency figures that tell you which designs are plausible.
The problem
A team is adding image hosting to its product. One engineer proposes storing the images in the main PostgreSQL database, because it is already there. Another proposes a 40-node sharded cluster “to be safe”. Neither has a number.
Ten minutes of arithmetic would have settled it. Two million uploads a day at 1.5 MB each is 3 TB of images a day, which rules out the database’s disk within the week. The metadata, at about 500 bytes per image, is 1 GB a day, which rules out the 40 nodes: it fits on one ordinary machine for years.
Both mistakes come from designing without knowing the size of the problem. The careful alternatives, load tests and capacity models, give precise answers, but they take days and need a system that already exists. Early in a design, and in an interview, you need an answer in minutes that is right to within a factor of a few. That is a back-of-envelope estimate. Its purpose is never precision. It is to tell 10 requests a second from 10,000 and from 10 million, because those call for three different architectures.
The numbers to memorise
Powers of two and ten. Computers count in powers of two, people in powers of ten, and the two line up closely enough to convert in your head.
| Power of two | Roughly | Unit |
|---|---|---|
| 210 | a thousand | KB |
| 220 | a million | MB |
| 230 | a billion | GB |
| 240 | a trillion | TB |
| 250 | a thousand trillion | PB |
Two products are worth knowing by heart: a million 1 KB records make 1 GB, and a billion make 1 TB.
Time. A day has 86,400 seconds. Round it to 100,000, and dividing becomes moving a decimal point. The rounding makes rates come out about 14% low, which is well inside the uncertainty of your assumptions.
- 1 million events a day is about 12 a second.
- 1 billion events a day is about 12,000 a second.
- A month is about 2.5 million seconds, and a year about 30 million.
Sizes. These are assumptions to state, not facts: a short text record with its metadata is a few hundred bytes to 1 KB, a compressed photo is a few hundred KB to a few MB, and a minute of 1080p video is tens of MB. A UUID is 16 bytes, and a 64-bit ID or timestamp is 8.
From users to requests per second
The basic formula is:
average requests per second = daily active users × actions per user per day ÷ 86,400
Traffic is not flat, so design for the peak. For a consumer product with a daily rhythm, assuming a peak of two to three times the average is common. A ticket sale or a breaking news alert can be ten times or more for a few minutes. Say which you are assuming.
Work out reads and writes separately. The ratio between them shapes the design: a read-heavy system leans on caches and replicas, and a write-heavy one on partitioning and queues.
Storage and bandwidth
storage = items per day × average size × days retained × copies
Estimate media and metadata separately, because they belong in different systems. For copies, three is a common replication factor in distributed stores, and indexes add more on top.
bandwidth = requests per second × payload size
Keep bits and bytes apart: a 1 Gbps link carries 125 MB a second.
Worked example 1: a photo-sharing service
Assumptions: 100 million daily active users. Each opens the feed 10 times a day. One in five uploads a photo each day. Each photo takes 2 MB including resized versions, plus 500 bytes of metadata.
| Quantity | Working | Result |
|---|---|---|
| Uploads | 20 M a day ÷ 86,400 | about 230 a second |
| Feed requests | 1 billion a day ÷ 86,400 | about 12,000 a second |
| Peak feed requests | 12,000 × 3 | about 35,000 a second |
| Photo storage | 20 M × 2 MB | 40 TB a day, about 15 PB a year |
| Metadata | 20 M × 500 bytes | 10 GB a day, under 4 TB a year |
| Upload bandwidth | 230 × 2 MB | 460 MB a second, about 3.7 Gbps |
Now the conclusions, which are the whole point. Reads outnumber writes by about 50 to 1, so the feed path gets the design effort and a cache. Fifteen petabytes a year belongs in object storage behind a CDN, never in a database. The metadata is small enough for a conventional database that can be sharded later.
Worked example 2: a chat service
Assumptions: 20 million daily active users, each sending 40 messages a day. A message is 200 bytes with its metadata. Three copies are kept. At the busiest moment, one daily user in ten is connected.
| Quantity | Working | Result |
|---|---|---|
| Messages | 800 M a day ÷ 86,400 | about 9,000 a second |
| Peak messages | 9,000 × 3 | about 28,000 a second |
| Storage | 800 M × 200 bytes | 160 GB a day, about 58 TB a year |
| With three copies | 58 TB × 3 | about 175 TB a year |
| Open connections | 20 M × 10% | 2 million |
Conclusions: storage is modest and grows steadily, so a store partitioned by conversation will hold it. The write rate is high but unremarkable. The figure that shapes the design is the 2 million open connections. If one gateway server holds 50,000 of them (an assumption to state), that is 40 servers whose only job is holding sockets, and it raises the real design question: how does a message find the server its recipient is connected to? The chat system case study answers it.
Enter the photo example, then double the photo size and the peak factor in turn, and notice which outputs move and which stay put.
Latency numbers
The second kind of estimate is about time. Whether a design can meet a latency target depends on what each step costs. The list below was popularised by Jeff Dean of Google around 2010, building on an earlier table by Peter Norvig. The version most often quoted includes figures for SSDs.
| Operation | Classic figure | Remember as |
|---|---|---|
| L1 cache reference | 0.5 ns | about 1 ns |
| Main memory reference | 100 ns | 100 ns |
| Read 4 KB at random from an SSD | 150 µs | about 100 µs |
| Round trip inside a data centre | 500 µs | 0.5 ms |
| Read 1 MB sequentially from an SSD | 1 ms | 1 ms |
| Seek on a spinning disk | 10 ms | 10 ms |
| Round trip, California to the Netherlands | 150 ms | 100 to 150 ms |
What the ratios tell you:
- Memory is about a thousand times faster than a random SSD read. That gap is why caches exist.
- Sequential access is far cheaper than random access. That is why logs and LSM trees append.
- Round trips add up. Twenty sequential calls inside a data centre cost about 10 ms before any work is done. Batch them or run them in parallel.
- Crossing a continent costs more than most whole-request budgets. Keep the data a request needs in the user’s region, or serve it from the edge.
When to estimate and when not to
Estimate when a number could change a decision: whether to shard, whether the hot data fits in memory, whether media needs object storage and a CDN, how many servers are needed to hold connections. Do not estimate for its own sake. Five minutes of arithmetic that ends in “so that is a lot of data” is wasted time. And do not carry false precision. Saying “11,574 requests a second” shows you have missed the point. “About 12,000” shows you have understood it.
In the interview
Estimate straight after requirements, and keep it under five minutes. State your assumptions, round hard, and write down average and peak requests per second for reads and for writes, storage over a stated period, and anything particular to the problem, such as open connections. Finish with a sentence that begins “so”: “So this is read-heavy, the media goes to object storage, and one database holds the metadata for now.”
Then use the numbers again. When you add a cache later, say “we estimated 35,000 reads a second at peak, so”. For latency, budget the request aloud: “The target is 200 ms. A cache hit is under a millisecond, two database calls in the same data centre are a few milliseconds each, and there are no cross-region calls on the request path.”
Key takeaways
- A day has 86,400 seconds. Round it to 100,000, and one million events a day becomes roughly 10 to 12 a second.
- Average requests per second is daily users times actions per user, divided by seconds in a day. Design for the peak, which you should state as an assumption.
- Storage is items per day times size times retention times copies. Media dominates, and metadata is usually small.
- Round to one significant figure, state every assumption, and end each estimate with a conclusion that changes the design.
- A memory reference takes about 100 ns, a random SSD read about 100 microseconds, a round trip inside a data centre about 0.5 ms and one between continents 100 ms or more.
- The latency list is order-of-magnitude and hardware has moved on. The ratios between memory, disk and network still guide design.
Try it
Check yourself
0 of 5 answered
Flashcards
These 6 cards are in your review deck. Tap a card to see the answer.
Seconds in a day, and the shortcut
86,400, rounded to 100,000. One million events a day is about 12 a second, and one billion a day is about 12,000 a second.
Formula for average requests per second
Daily active users times actions per user per day, divided by 86,400. Multiply by a stated peak factor to get the rate to design for.
Powers of two to remember
2^10 is about a thousand (KB), 2^20 a million (MB), 2^30 a billion (GB), 2^40 a trillion (TB) and 2^50 is a petabyte.
Storage formula
Items per day times average size times days retained times number of copies. Estimate media and metadata separately, because they live in different systems.
Four latency figures to remember
Memory reference about 100 ns. Random SSD read about 100 microseconds. Round trip inside a data centre about 0.5 ms. Round trip between continents about 100 to 150 ms.
How many bytes a second is 1 Gbps?
125 MB a second. Bandwidth is requests per second times response size. Keep bits and bytes apart.
Interview questions on this
- A ride-sharing app has 2 million drivers a day sending their location every 4 seconds. Estimate the write rate and storage. What does it mean for the design?
- Your API must serve 100,000 requests per second at peak. How many servers do you need?
- You want to cache user profiles for a service with 200 million registered users. How much memory do you need, and how many cache nodes?