Skip to content

System Design: Back-of-the-envelope calculations

Published: at 01:28 AM

In physics, dimensional analysis is a go-to heuristic for checking equations. In computer science, back-of-the-envelope calculations serve a similar purpose for rough estimations. Jeff Dean emphasised the importance of mastering this skill for every programmer in his talk Software Engineering Advice from Building Large-Scale Distributed Systems. Why do we need back-of-the-envelope calculations? The calculation allow us to quickly assess the physical limitations of a running system. If there has a sigficant gap between our expectations(theoretical limitation) and the actual cost, there might be an opportunity to optimize our systems.

Table of Contents

Open Table of Contents

Performance

Latency Comparison Numbers (~2012)

OperationTimeNote
L1 cache reference0.5 ns
Branch mispredict5 ns
L2 cache reference7 ns14x L1 cache
Mutex lock/unlock25 ns
Main memory reference100 ns20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy3 µs
Send 1K bytes over 1 Gbps network10 µs
Read 4K randomly from SSD*150 µs~1GB/sec SSD
Read 1 MB sequentially from memory250 µs
Round trip within same datacenter500 µs
Read 1 MB sequentially from SSD*1 ms~1GB/sec SSD, 4x memory
Disk seek10 ms20x datacenter roundtrip
Read 1 MB sequentially from disk20 ms80x memory, 20x SSD
Send packet CA -> Netherlands -> CA150 ms300x datacenter roundtrip

PostgreSQL Throughput

NoSpecConfigCPUFreqRORWCost ($/month)
2AWS z1d.2xlargeNormal84GHz16231524808300
4AWS c5d.metalNormal963.6GHz625849716242500
5AWS c5d.metalExtreme963.6GHz19985801371275000

Cost Estimation

As an architecture, what we are concerned with should not only focus on performance but also consider cost. Below are the computing costs and storage costs for the cloud-hosted service.

Base Costs:

Please note: For hardware, Reserved pricing is typically about half the cost of On-Demand Pricing.

Compute

Provider(1 vCPU, 2 GB RAM)Compute (8vCPUs, 32 GB RAM)
Render.com$ 25$ 450
Amazon EC2$ 15$ 185

PostgreSQL Storage

Storage(GB per Month)
Reder.com$ 0.3
Amazon Aurora$ 0.23

S3 Storage

Storage Cost (per GB-month)A Operation Cost (per million requests)B Operation Cost (per million requests)Egress Fee (per GB)
Amazon S3$0.023$5.00$0.40$0.09
Cloudflare R2$0.015$4.50$0.36No egress fee

For more vendor pricing, please refer to S3-Compatible Cloud Storage Costs.

The Power of 2

PowerExact ValueApprox ValueBytes
532
664
7128
8256
101,0241 thousand1 KB
1665,53664 KB
201,048,5761 million1 MB
301,073,741,8241 billion1 GB
324,294,967,2964 GB
401,099,511,627,7761 trillion1 TB

Example

Other Lists

Reference