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)
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.