AI Hints
Home›System Design Tutorial›Measuring Speed
System Design · Lesson 4 of 120

Latency and Throughput

Fast vs much.

⏱ 2 min read▶ Video at 3:28🎓 Free
Watch this lesson in the System Design courseWatch on YouTube ↗Full System Design course

Two numbers describe how fast a system is. Latency is how long one request takes. Throughput is how many requests the system handles each second. They sound alike, but they're different.

Latency and Throughput
From the video: Latency and Throughput
  • Latency: how long one takes
  • Throughput: how many per second
  • Not the same thing

A road analogy

Think of a road. Latency is how long one car takes to drive from one end to the other. Throughput is how many cars pass each minute. Adding more lanes raises throughput, but each car still takes the same time. To lower latency, you need a shorter or faster road.

Latency

  • Time for one carMeasured in millisecondsLower is better

Throughput

  • Cars per minuteRequests per secondHigher is better

Averages hide problems

We usually measure latency with percentiles, not averages. Here are ten response times. Run it. The average looks fine, about one hundred and sixty five milliseconds. But the ninetieth percentile shows that one in ten users waits much longer. That's why engineers watch P ninety nine, the slowest one percent.

latency.pypython
times = [90, 95, 100, 102, 98, 110, 105, 97, 99, 750]  # ms

avg = sum(times) / len(times)
ordered = sorted(times)
p50 = ordered[len(ordered) // 2]
p90 = ordered[int(len(ordered) * 0.9)]

print(f"average: {avg:.0f} ms")
print(f"p50:     {p50} ms")
print(f"p90:     {p90} ms")
Output
average: 165 ms
p50:     100 ms
p90:     750 ms

Summary

Latency is time per request, and throughput is requests per second. Measure latency with percentiles, because averages hide slow users. Next, how slow common operations really are.

Key takeaways
  • Latency in ms
  • Throughput in requests/sec
  • Watch p99, not the average
Next up: Numbers Every Engineer Should Know — how slow is slow