Grokking the System Design Interview
Vote

0% completed

Latency vs Throughput

The Two Definitions

They Are Not Opposites

Why They Still Trade Off

Averages Hide the Slow Requests

How to Improve Each One

A Cache Improves Latency First

The Two Numbers Side by Side

Choosing What to Optimize

You tell the interviewer your design is fast. The interviewer asks: fast for one user, or fast for a million users at once?

Those are two different questions. Latency answers the first. Throughput answers the second. The skill this lesson teaches: know which number a requirement is really about, and what improving it costs the other.

The Two Definitions

Latency is how long one request takes, from the moment it is sent to the moment the response arrives. It is measured in milliseconds. Lower is better.

Throughput is how much work the system completes per unit of time. In an interview it is almost always requests per second (RPS), also called queries per second (QPS). Higher is better.

A supermarket shows the difference. Latency is how long one customer waits at the checkout. Throughput is how many customers the store serves per hour. The short version: latency is about one request, throughput is about all of them.

Latency is the time one request takes from send to response, while throughput counts every request that finishes inside one second
Latency is the time one request takes from send to response, while throughput counts every request that finishes inside one second

They Are Not Opposites

The two are separate axes, and all four combinations exist:

  • Low latency, low throughput. One fast server, no parallel work. Quick requests, few at a time.
  • High latency, high throughput. A batch pipeline that runs six hours over a billion records. Nobody waits, and the volume is enormous.
  • Low latency, high throughput. The goal, and it costs money.
  • High latency, low throughput. An overloaded system. The failure case.

The proof is concurrency, the number of requests being worked on at the same time. One worker that finishes a request in 100 ms completes 10 requests per second. Ten workers complete 100 per second, and each request still takes 100 ms. Throughput grew ten times. Latency did not move.

That relationship has a name. Little's Law says: concurrency = throughput x latency.

It turns capacity questions into arithmetic. To serve 2,000 requests per second at 50 ms each, you need 2,000 x 0.05 = 100 requests in flight at once. That number sizes your threads and instances.

Ten workers multiply throughput by ten while each request still takes 100 ms, which is Little's Law: concurrency = throughput x latency
Ten workers multiply throughput by ten while each request still takes 100 ms, which is Little's Law: concurrency = throughput x latency

Why They Still Trade Off

So why does everyone call them a trade-off?

Because a real system has a capacity limit, and latency gets worse quickly near that limit. Utilization is the share of capacity you are using. Once the servers are busy, a new request waits in a queue before anyone starts working on it. That queue wait is added to every response time.

As utilization nears capacity, throughput flattens while latency rises steeply, which is why teams run at 50 to 70 percent
As utilization nears capacity, throughput flattens while latency rises steeply, which is why teams run at 50 to 70 percent

The curve has three zones:

  • Up to about 70 percent utilization, latency is nearly flat.
  • Between 70 and 90 percent, latency climbs, and each extra unit of load returns less throughput.
  • Past about 90 percent, throughput stops growing and latency rises steeply.

This is why teams run servers at 50 to 70 percent utilization instead of 95. The spare capacity is not waste. It is what keeps response times stable when traffic rises suddenly.

The general form of the trade: you can turn spare capacity into throughput, and latency pays for it. Batching is the clearest example. Batching means collecting many items and processing them in one operation. Writing 100 records in one database call is far cheaper per record, so throughput rises. But the first record now waits for the other 99 to arrive, so its latency gets worse.

Averages Hide the Slow Requests

"Our average latency is 200 ms" tells you almost nothing. An average hides the shape of the data. Most requests are fast, and a few are very slow because of retries, pauses, and locks. Those slow requests barely change the average, and they are exactly what users complain about.

So real systems measure percentiles. Sort all requests from fastest to slowest:

  • p50, the median: half of all requests are faster. The typical experience.
  • p95: 95 percent are faster. One request in 20 is slower.
  • p99: 99 percent are faster. This describes the slowest users, and it is usually the number in a service level objective, a promised performance target.

A p50 of 100 ms with a p99 of four seconds means one request in a hundred is too slow to use.

A latency distribution with a long tail: the average sits near the fast side while p50, p95, and p99 describe the slowest users
A latency distribution with a long tail: the average sits near the fast side while p50, p95, and p99 describe the slowest users

The slow one percent matters more than it sounds, because one page load is rarely one request. Say a screen makes 100 backend calls, each with a p99 of one second. The chance that all 100 are fast is 0.99 multiplied by itself 100 times, about 0.37. So about 63 percent of page loads include at least one slow call. Once one action becomes many calls, the slow tail becomes the normal experience.

So state every latency requirement as a percentile. "p99 under 200 ms for the timeline endpoint" is a requirement. "Fast" is not. The Key Characteristics of Distributed Systems lesson covers these measurements alongside availability and reliability.

How to Improve Each One

To improve latency:

  1. Move the data closer. A CDN, a network of servers placed near users, removes physical distance from the round trip.
  2. Cache. A cache is a small fast store that keeps ready-made answers. A hit skips the slow work entirely.
  3. Cut round trips. Every sequential network call adds its full latency. Fetch in parallel, or combine related calls.
  4. Index and tune queries. Most surprise latency is a query doing extra work.
  5. Do less on the request path. Move anything the user does not need immediately into a background job.
  6. Keep utilization moderate. Often the cheapest latency fix of all.

To improve throughput:

  1. Add machines. Instances behind a load balancer. Horizontal vs Vertical Scaling is the next lesson.
  2. Raise concurrency. More workers, threads, or connections. Little's Law tells you how many.
  3. Batch. Group work to cut per-item overhead, and accept the added waiting.
  4. Queue work. Consumers process jobs at their own rate, and the queue absorbs bursts.
  5. Split the data. Sharding spreads load across machines, so no single database caps the total.
  6. Cache. Yes, again.

A Cache Improves Latency First

A cache appears in both lists, and it is often filed wrongly.

The first effect of a cache is on latency. The answer is closer and already computed, so the request skips the slow work. That is the same reason a CDN is a latency tool.

The throughput gain follows from the same hit. The backend never did that work, so its capacity is free for other requests. One video processed once and served from a cache to a thousand viewers is a thousand times less backend work. So a cache cuts latency directly, and it usually raises throughput as a consequence. If you had to file it under one number, file it under latency.

Most good techniques help both numbers. The ones that truly trade add waiting on purpose. Batching, buffering, and queueing all raise throughput by making single requests wait longer.

The Two Numbers Side by Side

LatencyThroughput
MeasuresTime for one requestRequests completed per second
UnitMillisecondsRPS or QPS
Better isLowerHigher
Report it asA percentile, such as p99Peak load, not average
Improved byCloser data, caching, fewer round tripsMore machines, concurrency, batching
Gets worse whenUtilization nears capacityOne serial step limits all the work

Choosing What to Optimize

  • A user is waiting on the request path: optimize latency, and state the target as a percentile.
  • Nobody waits on the result, such as a nightly report: optimize throughput. Latency is cheap to spend here.
  • The system is overloaded: add capacity or shed load first. Near the limit, both numbers are bad.
  • You are given a scale requirement: convert it into both numbers before you design anything.

💡 In the interview: turn the scale requirement into both numbers before you draw a box. "One million daily users, five feed loads each" is about 58 requests per second on average, and peak is several times that. Then size the fleet with Little's Law. Attach a percentile to every latency target. Expect the follow-up "how would you reduce latency" and answer with a cache or a CDN first. Add that the cache also unloads the database, so throughput rises too. If asked why not run servers at 95 percent utilization, answer with the curve: a small traffic rise would push latency past the target.

Key takeaway: latency is the time one request takes, and throughput is the number of requests finished per second. They are independent axes joined by Little's Law: concurrency = throughput x latency. They trade off near capacity, where queueing adds waiting to every request, and when you batch on purpose. Measure latency with percentiles, because the average hides the slow tail that users notice. And a cache improves latency first, because the answer is close and precomputed; the throughput gain follows because the backend skips that work.

David Davaatulga

David Davaatulga

· 2 years ago

Implementing cache benefits both metrics but I believe that it would benefit latency most similar to CDN (contrary to the course listing it under throughput). Thoughts?

Show 1 reply

On This Page

The Two Definitions

They Are Not Opposites

Why They Still Trade Off

Averages Hide the Slow Requests

How to Improve Each One

A Cache Improves Latency First

The Two Numbers Side by Side

Choosing What to Optimize