Skip to Content
Software EngineeringSystem DesignFrameworkBack of the envelope

Back of the envelope

Sources

Unit

  • Thousands = Kilo (3 zeros)
  • Millions = Mega (6 zeros)
  • Billions = Giga (9 zeros)
  • Trillions = Tera (12 zeros)
  • Quadrilions = Peta (15 zeros)

  • Milli = 10^(-3)
  • Micro = 10^(-6)
  • Nano = 10^(-9)
  • Pico = 10^(-12)

Latency Numbers Programmer Should Know 

<1 ns / sub-nanos -------------------------------------------------------------------- A clock cycle L1 cache reference 0.5 ns 1 - 10 ns -------------------------------------------------------------------- Branch mispredict (~20 clock cycle) 5 ns L2 cache reference 7 ns 14x L1 cache 10 - 100 ns -------------------------------------------------------------------- L3 cache reference 10 - 100 ns Mutex lock/unlock 25 ns Main memory reference 100 ns 20x L2 cache, 200x L1 cache 100 - 1000ns -------------------------------------------------------------------- md5 hash on 64bit int 200 ns Compress 1K bytes with Zippy 3,000 ns System call generally few hundreds ns 1 - 10us (about thousands times slower than CPU register access) -------------------------------------------------------------------- context switching between Linux threads generally few micros (if without paging) Coping 64KB between 2 main memory location generally few micros as well 10 - 100us -------------------------------------------------------------------- nginx network proxy for http request 50 us reading 1MB sequentially in main memory 50 us reading 8K page in SSD 100 us 100 - 1000us -------------------------------------------------------------------- intra-zone network round trip few hundreds us writing a page to SSD 1,000 us 10x slower than SSD read typical Memcache/Redis get ops 1,000 us 1 - 10 ms -------------------------------------------------------------------- inter-zone network round trip 5 ms seek time of HDD 5 ms 10 - 100 ms -------------------------------------------------------------------- US east coast to Europe Read 1 GB sequentially from memory 100 - 1000 ms -------------------------------------------------------------------- encrypt a password 300 ms TLS handshake 250 - 500 ms US west coast to Singapore Read 1 GB sequentially from SSD > 1s -------------------------------------------------------------------- Transferring 1GB over network 10 s within the same cloud regions

Cache sizes 

  • Cacheline: 64 bytes (x86 machine)
  • L1: D/I cache - 32KB or 64KB per core
  • L2: 256KB or 512KB (could be per core or shared up to 2 cores)
  • L3: May vary from 8MB to 32MB (could be shared across all cores or may be sliced to multiple instances to be associated per core or dual/quad cores)

Geographic distance

(in KM) 4K 6K 10K 10K SF ---- NY ------ Amsterdam ---------- Taiwan -------..>SF |________________________________________________________|
LS = light speedsingle way latency minimum
4K / LS13 micros
6K / LS20 micros
10K / LS33 micros

Common network bandwidth 

  • The maximum amount of data that goes through the cable per second is called the bandwidth.
  • Bandwidth is usually measured in bits per second not bytes per second.
  • The standard supported network speed is single-lane 100 gigabits per second (Gbps), 25 Gbps, and 10 Gbps signaling.
  • Anything else (that is, 400 Gbps, 50 Gbps, 40 Gbps, and so on) comprises multiple parallel lanes.

Useful Calculations

x Million users * y KB (per user) = xy GB
  • example: 1M users * a documents of 100KB per day = 100GB per day.
x Million users * y MB (per user) = xy TB
  • example: 200M users * a short video of 2MB per day = 400TB per day.

Approximation

1 day is about 100K seconds

1 month is about 3M seconds

  • 1 million requests per month ~= 10 10^5 / (3M) = 0.13 = 0.3 requests per seconds
  • 1 billion requests per month ~= 10 10^8 / (3M) = 1003 = 300 requests per seconds

Usage

Users cnt

  • Facebook: 2.27B
  • YouTube: 2B
  • Instagram: 1B
  • Pinterest: 332M | Twitter: 330M | Onedrive: 250M
  • TikTok: 3.7M

Page visit

  • Facebook: 26.12B
  • Twitter: 6.34B
  • Pinterest: 1.32B

Cost of Operations

  • Read sequentially from HDD: 30 MB/s
  • Read sequentially from SSD: 1 GB/s
  • Read sequentially from memory: 4 GB/s
  • Read sequentially from 1Gbps Ethernet: 100MB/s
  • Cross continental network: 6–7 world-wide round trips per second.
MonthStorageConnectionsRequests/secThroughput
SQL DB600TB30K25k-
Cache300GB10K100k-
WebServer--5 - 10k-
Queue/Stream--1 - 3k1 - 50MB/s (Write), 2 - 100MB/s (Read)
Scrapers--1k-
Last updated on