Back-of-the-envelope estimation
Powers of two, quick scale heuristics, and latency numbers every engineer must know.
What you will learn
- Convert between powers of two and powers of ten for storage sizes.
- Turn daily and monthly volumes into requests per second.
- Use the latency numbers every programmer should know as orders of magnitude.
The power of quick estimation
In system design interviews and architectural planning, you must quickly verify whether a proposed storage format, network pipe, or database tier will survive real-world scale before writing a line of code.
1. Powers of two and memory capacity
Always remember the rule of thumb:
- (1,024 B):
- (1,048,576 B):
- (1,073,741,824 B):
- (1,099,511,627,776 B):
- (1,125,899,906,842,624 B):
2. Time and throughput heuristics
- (easy mental math: divide by , then multiply by ).
The primer's worked solutions use a handy conversion for monthly volumes: a month has about million seconds, so request per second is about million requests a month, and requests per second is about billion a month.
3. Latency numbers every programmer should know
These figures were compiled by Jeff Dean and Peter Norvig and date from around 2012. Hardware has moved on since, so use them for orders of magnitude, not exact values. They span more than eight orders of magnitude (from to is a factor of ). If an L1 cache reference were scaled up to 1 second:
- L1 cache reference ()
- Branch mispredict ()
- L2 cache reference ()
- Mutex lock/unlock ()
- Main memory reference ()
- Read 4 KB randomly from SSD ()
- Read 1 MB sequentially from memory ()
- Round trip within the same datacenter ()
- Hard disk seek ()
- Send a packet California Netherlands California ()
Latency numbers, on a log scale
- Global Client: 1 × Clients & Users
- Edge CDN: 2 × CloudFront / CDN Edge
- App Servers (in-memory data): 4 × App Compute Server
- Disk-Backed Database: 2 × Primary Relational DB
- Global Client sends requests to Edge CDN
- Edge CDN sends requests to App Servers (in-memory data)
- App Servers (in-memory data) sends requests to Disk-Backed Database
Key takeaways
- : KB, MB, GB, TB and PB are each about a thousand times the last.
- A day is about seconds, so 1 million requests a day is about 12 a second; a month is about 2.5 million seconds, so 1 request a second is about 2.5 million a month.
- A main-memory reference (100 ns) is about 1,500 times faster than a random 4 KB SSD read (150 µs), and a disk seek (10 ms) is slower still; a round trip across an ocean costs about 150 ms.
Sources
- System Design Primer: Powers of two table
- System Design Primer: Latency numbers every programmer should know
- System Design Primer: Design Pastebin (handy conversion guide)
- Latency Comparison Numbers (~2012), Jeff Dean and Peter Norvig
Adapted from The System Design Primer by Donne Martin, licensed under CC BY 4.0. Changes were made.