What numbers should I remember for back-of-the-envelope math?
- Posted
- Tags
- system-design, architecture, scaling
A short list of numbers (powers of two, seconds in a day, latency orders of magnitude, availability nines, rough per-machine throughput) turns "how big does this need to be?" into a two-minute estimate. The goal is the right order of magnitude, and an argument for each design choice, not an exact answer.
I've been brushing up on system design, and I noticed something about my own answers. I could say "add a cache here" or "shard the database", but when I asked myself why, the honest answer was "because that's what people do". That isn't a compelling argument. What makes it compelling is a number: "reads peak around 10,000 per second, and one database handles a few thousand comfortably, so I need a cache." To say that, I need a few numbers in my head.
The question I had
What numbers should I actually remember for back-of-the-envelope math, and how do I turn them into arguments for my design choices?
What I found
The point is the order of magnitude
A back-of-the-envelope estimate isn't meant to be right. It's meant to be right within about 10x, fast. Is this 10 requests per second or 10,000? Gigabytes or petabytes? That's usually enough to decide between one box, a cache, or a sharded cluster.
So the rules are:
- Round hard. 86,400 becomes 100,000. 2.6 million becomes 2.5 million.
- Say assumptions out loud. "Assume 10 million daily users, each doing 10 reads." If an assumption is wrong, someone can fix it, and the math still holds.
- Write the units. Most mistakes I make are units, not arithmetic.
Powers of two and data sizes
| Power | Roughly | Unit |
|---|---|---|
| 2^10 | a thousand | KB |
| 2^20 | a million | MB |
| 2^30 | a billion | GB |
| 2^40 | a trillion | TB |
| 2^50 | a quadrillion | PB |
2^10 is 1,024, not 1,000 (that's the KiB vs KB difference), but at this level nobody cares.
Sizes of common things:
| Thing | Size |
|---|---|
| ASCII character | 1 byte (UTF-8 can be up to 4) |
| int32 | 4 bytes |
| int64, timestamp | 8 bytes |
| UUID | 16 bytes as binary, 36 as text |
| A URL | about 100 bytes |
| A compressed photo | a few hundred KB to a few MB |
Time
- A day is 86,400 seconds. Call it 100,000 (10^5). That's about 16% high, which is fine.
- A month is about 2.5 million seconds.
- A year is about 30 million seconds.
The shortcut I use the most: 1 million requests a day is about 12 per second. So 100 million a day is about 1,200 per second, and 1 billion a day is about 12,000 per second.
Traffic isn't flat, though. A common rule of thumb is that peak is 2x to 3x the average. That's a convention for estimates, not a law. A ticket sale or a live event can spike far higher.
Latency, in orders of magnitude
These come from the well-known "latency numbers every programmer should know" list. The original is from around 2010, and some rows (SSDs, memory bandwidth) have gotten a lot faster since, so I only trust the order of magnitude. The last column is what helped me remember them: scale everything so a memory read takes 1 second.
| Operation | Roughly | If a memory read took 1 second |
|---|---|---|
| L1 cache read | 1 ns | 0.01 seconds |
| Main memory read | 100 ns | 1 second |
| SSD random read | tens to 100 µs | up to 17 minutes |
| Round trip within a data center | 0.5 ms | 1.4 hours |
| Spinning disk seek | 10 ms | 1.2 days |
| Round trip, California to Europe | 150 ms | 17 days |
The lessons I take from it:
- Memory is fast, disk seeks are slow, and crossing the world is slowest. The last one is set by the speed of light in fiber, so no hardware upgrade fixes it.
- Round trips add up. A page that makes 10 calls in a row to a service in the same data center has spent 5 ms just on the network. Batch them or run them in parallel.
- This is the argument for a cache. Memory is about 1,000x faster than an SSD read and 100,000x faster than a disk seek.
Availability nines
| Availability | Downtime per year | Downtime per month |
|---|---|---|
| 99% | 3.65 days | 7.2 hours |
| 99.9% | 8.8 hours | 43 minutes |
| 99.99% | 53 minutes | 4.3 minutes |
| 99.999% | 5 minutes | 26 seconds |
Two things fall out of this:
- Each nine is 10x less downtime, and usually a lot more cost. 4 minutes a month leaves no time for a person to even notice, so 99.99% means automatic failover.
- Dependencies in a row multiply. If my service calls two others in sequence and each is 99.9%, the best I can promise is about 99.8% (0.999 × 0.999). That's an argument for fewer hard dependencies, or for a fallback when one is down.
Rough throughput per machine
These vary a lot with the workload, so I treat them as starting points, not benchmarks:
| Component | Rough capacity |
|---|---|
| App server | hundreds to a few thousand requests per second, depending on how much work each does |
| Relational database (one node) | a few thousand to tens of thousands of simple queries per second, fewer for writes |
| In-memory cache like Redis (one node) | around 100,000 operations per second |
| 1 Gbps network link | about 125 MB per second |
| 10 Gbps network link | about 1.25 GB per second |
The network row is where I slip most. Links are measured in bits, files in bytes. Divide by 8, or be off by 8x.
Putting it together: a URL shortener
Here's where the numbers turn into arguments. Assumptions, said out loud:
- 100 million new short links a month
- 100 reads for every write
- About 500 bytes per record (the long URL, the short code, a timestamp, a user ID, plus overhead)
- Keep links for 5 years
Writes: 100 million ÷ 2.5 million seconds = 40 per second, about 100 at peak.
One database handles that easily. I don't need to shard for writes.
Reads: 40 × 100 = 4,000 per second, about 10,000 at peak.
That's at the edge of what one database does comfortably. These are simple key lookups and the same popular links get read over and over, so a cache fits better than more database nodes.
Cache size: if the hot set is about 20% of a month's links, that's 20 million × 500 bytes = 10 GB.
That fits in memory on one cache node, and at around 100,000 operations per second, one node has about 10x headroom over peak.
Storage: 100 million × 500 bytes = 50 GB a month, about 600 GB a year, 3 TB over 5 years.
One large database can hold that. Sharding is a decision for later, not day one.
Bandwidth: 4,000 reads × 500 bytes = 2 MB per second.
Barely noticeable on a 1 Gbps link. Bandwidth isn't the constraint here.
Short code length: 5 years × 1.2 billion links a year = about 6 billion links. Using letters and digits (62 characters), 6 characters give 62^6 ≈ 57 billion codes, and 7 give about 3.5 trillion.
6 characters is enough on paper. 7 leaves room for growth and makes random codes much less likely to collide.
Every design choice now has a number behind it. If someone says "what about 10x the traffic?", I can redo one line instead of starting over. That's the part I was missing when I said "add a cache" out of habit. The process I wrote about in my API design post has the same shape: state the requirement, then justify the choice against it.
Takeaway
I don't need to memorize a big table. A day is 100,000 seconds, 1 million a day is 12 per second, memory beats disk by orders of magnitude, each nine is 10x less downtime, and divide bits by 8. With those and hard rounding, every box on my diagram comes with a reason, and the reason is a number someone can check.