01. Foundations: cheatsheets

3 lessons, one page each when printed.

System Design · 01. Foundations · 8 min · Beginner

How a Request Travels

Follow one page load from the address bar to the screen.

In short

One page load used four round trips (DNS, TCP, TLS, HTTP) and took 300 ms in our setup. The network took 73% of that.

The path is always the same: name to address, connect, secure, request, work, response, draw. Later lessons shorten it: caches skip work, CDNs shorten distance, and load balancers spread the server's job.

Key ideas

  • A round trip is one message out and one answer back. Most of the delay in a page load is waiting for round trips, not computing. (step 1)
  • Inside the data centre the database is a short hop away, often well under 1 ms, so the query time dominates there, not the network. (step 5)
  • To speed up a request, first remove round trips: cache DNS, reuse connections, serve from a server near the user. (step 8)

Good to know

  • DNS answers carry a TTL (time to live), often minutes to hours, so most lookups never leave your device. (step 2)

Watch out

  • Nothing useful has been sent yet, and 120 ms are gone. Reusing an open connection (keep-alive) avoids paying this again. (step 3)
  • Around 100 ms feels instant, and 300 ms is noticeable. Every extra file the page needs adds more waiting. (step 7)
DNS resolverBrowserWeb serverDatabase

Key numbers

Total time
300 ms
Round trips
4

Terms

DNS lookup
Asking a resolver which IP address belongs to a name such as shop.example.
IP address
The number that identifies a machine on the network, like 203.0.113.7.
Round trip
One message out and the answer back; its time is the round-trip time (RTT).
TCP handshake
A three-message exchange that opens a reliable connection before data is sent.
TLS
The encryption layer behind https; TLS 1.3 sets it up in one round trip.
HTTP request
A message such as GET /cart that asks a server for a resource.
HTTP status code
A number in the response that tells the result, such as 200 OK or 404 Not Found.
Keep-alive connection
Reusing an open connection for later requests so the handshakes are paid only once.
Rendering
The browser turning HTML, styles and scripts into pixels on the screen.

System Design · 01. Foundations · 8 min · Beginner

Latency & Throughput

How long one request takes, and how many you can finish each second.

In short

Latency is the wait of one request (20 ms here); throughput is the number finished per second (50 per worker). Adding workers raises throughput but not latency.

Past capacity, queues make latency blow up. Judge a service by p99, size it with Little's law, and use batching when you can spend a little latency for much more throughput.

Key ideas

  • Latency is about one request. Ask: "how long did I wait?" (step 2)
  • Throughput is about many requests. Ask: "how many can you finish per second?" (step 3)
  • Watch p99 (and p99.9), not the average. At scale, the slow tail is what many users meet. (step 6)

Good to know

  • More workers (parallelism) buys throughput. Less work per request buys latency, and usually throughput too. (step 4)
  • Use it to size pools: workers or connections needed ≈ requests per second × seconds per request. (step 7)

Watch out

  • Latency = waiting time + work time. Near full capacity, waiting time explodes, so keep a safety margin of unused capacity. (step 5)
  • Batching suits logs, events and bulk imports. It does not suit a click that must answer instantly. (step 8)
UsersWorkerWaiting lineWorker 2Worker 3Worker 4

Key numbers

p50 latency
20 ms
p99 latency
500 ms
Throughput
200/s
Queue length
0

Terms

Latency
The time one request takes from being sent to being answered.
Throughput
How many requests a system completes each second.
Queueing delay
Time a request spends waiting for a free worker, which grows quickly near full capacity.
Percentile (p50, p99)
p99 is the time that 99 out of 100 requests beat; p50 is the median.
Tail latency
The slowest few percent of requests, which many users still meet at scale.
Little's law
Requests in the system = arrival rate × average time in the system.
Batching
Grouping many small operations into one call to share the fixed cost, at the price of some waiting.
Requests per second (RPS, QPS)
The usual unit for throughput of a web service.

System Design · 01. Foundations · 10 min · Beginner

Napkin Math

Estimate traffic, storage and servers before you design anything.

In short

From 10 million daily users we got 2,315 reads a second on average, 6,944 at the peak, about 110 TB of photos a year, a 60 GB cache and 26 app servers.

The recipe: write down assumptions, use round numbers, convert per day to per second, multiply by a peak factor, count storage and bandwidth, divide by what one machine can do, then check the result a second way.

Key ideas

  • You want the right order of magnitude (10, 100, 1,000), not the exact digit. (step 1)
  • Photos and video dominate storage. Count them first; the rest is usually small by comparison. (step 5)
  • Always round up and add a spare. Capacity at 100% means queues and slow p99. (step 8)

Good to know

  • Memory beats SSD, SSD beats a network call, and a network call beats an ocean. Design to touch the faster ones more. (step 2)
  • Trick: 1 million requests a day is about 12 a second. Memorise that and scale from it. (step 3)
  • Caching a small slice cuts load a lot. This is the same hit-rate effect you meet in the Caching lesson. (step 7)

Watch out

  • Events (a sale, a live match) can spike 10 times or more. Pick the factor for your product and say it out loud. (step 4)
  • Bytes versus bits is a classic slip: 1 GB/s is 8 Gbit/s. (step 6)
  • The common errors: a missing x1,000 (KB vs MB), bits versus bytes, and forgetting the peak factor. (step 9)
10M daily users26 app serversCache60 GBPhoto storage110 TB/yrDatabase1,389/s

Key numbers

Peak QPS
6,944/s
Storage per year
110 TB
App servers
26

Terms

Napkin math
A quick estimate with round numbers, used to find the size of a system before designing it.
Order of magnitude
How many digits a number has: 10, 100 or 1,000 times; the goal of a rough estimate.
Latency numbers
Round figures for how long memory, SSD, network and disk operations take.
QPS (queries per second)
How many requests a system receives or serves each second.
Peak factor
The multiple of the average traffic you design for, often 2 to 3 times.
Storage estimate
Items per day × size of each item × days kept × copies.
Bandwidth
Data moved per second, in bits: bytes per second times 8.
80/20 rule
A small share of the data, about 20%, serves most of the reads, about 80%.
Capacity headroom
Running servers well below full load so bursts and failures do not cause queues.