Courses System design · Part 1 · Lesson 2
Numbers Every Engineer Should Know
In system design the numbers do not need to be exact. You need to know roughly how long something takes or how much space it needs. The difference between 1 millisecond and 100 milliseconds is the difference between a good design and a slow one. This lesson gives the numbers worth remembering, and a way to calculate quickly.
How long things take
These numbers are approximate and depend on the hardware. What matters is how they compare:
| Operation | Approximate time | If a memory read took 1 second |
|---|---|---|
| Read from main memory (RAM) | 100 nanoseconds | 1 second |
| Random read from an SSD | 100 microseconds | about 17 minutes |
| Network round trip inside one data center | 500 microseconds | about 1 hour 20 minutes |
| Hard disk (HDD) seek | 10 milliseconds | about 1 day |
| Network round trip between continents | 150 milliseconds | about 17 days |
The last column is the same numbers, only 10 million times bigger. For example, 150 milliseconds ÷ 100 nanoseconds = 1.5 million, and 1.5 million seconds is about 17 days.
Three lessons from this table:
- Memory is much faster than disk. That is why a cache in memory helps so much.
- The network is expensive. Every time one service calls another, at least half a millisecond is added. Ten calls one after another: 5 milliseconds.
- You cannot get around distance. Light has a limited speed too. If the users are in Iran and the server is in the US, every request is many times slower. This is why CDNs exist.
Turning “per day” into “per second”
Questions usually give daily or monthly numbers, but servers are measured in “requests per second”. A day is 86,400 seconds. For mental math, use 100,000. The error is about 15%, which is fine for an estimate.
| Per day | Per second (approx.) |
|---|---|
| 1 million | 12 |
| 10 million | 120 |
| 100 million | 1,200 |
| 1 billion | 12,000 |
Remember that traffic is not even. The busy hour is usually 2 to 10 times the average. Design for the busy hour, not for the average.
Sizes
| Thing | Approximate size |
|---|---|
| A big integer (long) | 8 bytes |
| A UUID | 16 bytes |
| A typical table row | a few hundred bytes to 1 KB |
| A compressed photo | 200 KB to 2 MB |
| One minute of HD video | about 50 MB |
And the steps: each unit is about 1,000 times the one before. Kilobyte, megabyte, gigabyte, terabyte, petabyte.
Calculator
Enter the numbers of your own system. The result updates as you type:
An exercise: with the default numbers (one million users, 2 writes each per day) the result is about 23 writes per second. One ordinary database server handles a few thousand simple writes per second. So this system does not need more than one database yet. Now multiply the users by 100 and see when you reach the limit.
One important rule
These calculations are for making a decision, not for getting an exact number. Whether the result is 23 or 40, the decision is the same: one database is enough. If the result is 20,000, the decision changes. After every calculation, say one sentence: “So this means …”