Latency vs Throughput

Latency vs throughput explained: percentiles (p50, p99), tail latency, Little's Law, and how to reason about both in system design.

Beginner 6 min read · Updated

Latency is how long one operation takes, measured in time (milliseconds or microseconds). Throughput is how many operations a system completes per unit of time (requests per second, MB per second). They are related but distinct: a highway's latency is the drive time, its throughput is cars per hour. You can widen the highway to carry more cars without making any single trip faster.

Both are core non-functional requirements. High latency makes a system feel slow and hurts user satisfaction, and in real-time products such as video streaming, online games or high-frequency trading even a few extra milliseconds can be damaging. Throughput decides how much load the system can carry as demand grows.

What latency is made of

In the simplest terms latency is a delay: the time from when a request is sent until the response arrives. Seen from the client, that total (also called response time) has two parts:

  • Network latency: the time for the request to travel from the client to the server and for the response to travel back, the time spent "on the wire". It depends on physical distance, the number of hops (routers, proxies) the data passes through, and the speed of each link.
  • Server-side latency: the time the server takes to understand the request, do the work (calculations, database reads, calls to other services) and build the response. It depends on hardware, how efficient the software is, and how complex the request is.
Nearby usernetworkserver processing60 msnetworkFar-away usernetwork90 msserver60 msnetwork90 ms
Response time as the client sees it: network time out and back plus the server's processing time. Optimizing one part can't fix the other.

Managing latency means working on both: getting closer to users and fewer hops for the network part, faster code, queries and caches for the server part.

Measure latency with percentiles, not averages

Latency is never one number. Most requests are fast; a few are slow because of garbage-collection pauses, cache misses, a slow disk or a retry. An average hides those slow requests, so latency is measured in percentiles:

  • p50 (median): the slowest of the fastest 50% of requests. Half of requests finish within this time; it's the typical experience.
  • p95 / p99: 95% or 99% of requests finish within this time. This is what your unluckiest users see, and they are often your most active ones.
  • p99.9 and max: the long tail, where timeouts and retries live.

By definition p99 is always greater than or equal to p50. A real example from a database service (Firestore on Google Cloud) at one moment:

p5028 msp9544 msp9945 ms
Request latency percentiles for one database at one moment: the median is 28 ms, but 1% of requests take longer than 45 ms.
Servicep50p99What it means
Healthy API40 ms120 msTight distribution; tail close to median
Same median, bad tail40 ms2,000 ms1 in 100 requests is painfully slow: likely lock contention, GC or a slow dependency

Tail latency

Tail latency is the latency of the slowest requests: the 99th, 99.9th or even 99.99th percentile. Sort the latencies of millions of operations from fastest to slowest and the tail is the long stretch of slow ones at the end.

It matters because it matches the worst user experiences. An average describes general performance but hides the occasional slowdowns people actually notice, so engineers work to cut the tail, not just the average. That is often hard and expensive: it can mean tuning server software, upgrading hardware, changing the architecture, improving load balancing, or adding failover for peaks and outages. Weigh the effort against the benefit.

Tail latency matters more as systems grow. One page often fans out to many backend calls in parallel, and it is only as fast as the slowest of them. If each backend has a 1% chance of being slow, a page that calls 100 backends hits at least one slow call about 63% of the time (1 − 0.99^100). At scale, every user sees your p99.

User requestAggregatorwaits for allProfile12 msFeed18 msAdsp99 hit: 900 ms
A fan-out request waits for its slowest dependency, so backend tail latency becomes the user's typical latency.

Tactics that cut tail latency: timeouts with a fallback (show the page without ads), hedged requests (send a second copy to another replica if the first hasn't answered by the p95), avoiding head-of-line blocking, and keeping garbage-collection pauses short. See retries and timeouts.

Reducing latency

  1. Use a CDN. A content delivery network keeps copies of content in many locations worldwide, so data travels a shorter distance.
  2. Load balance. Spreading traffic over many servers prevents congestion on any one of them, keeping response times low. See load balancing.
  3. Cache. Keeping frequently used data in memory, close to where it's needed, cuts the time to fetch it. See caching.
  4. Pick the right data center location. Put servers near most of your users: for users in the US, a data center in San Francisco beats one in Singapore.
  5. Optimize the server path. Add indexes, remove unnecessary calls, and parallelize independent work. See database optimization.

Throughput and how to raise it

Throughput is the amount of data or number of transactions a system processes in a given period. It directly measures performance and efficiency: higher throughput means the system handles more load, and it decides how well the system copes as demand rises. There are two ways to raise it:

  • Reduce the time per request (lower latency), so each worker finishes more requests per second.
  • Process more requests at once (more concurrency), by adding parallel capacity.

Concurrency is usually where the big gains are. Three standard moves:

Scale reads with replication

Copy the data onto several servers so many reads can run at the same time. The primary stays the source of truth and sends updates to the replicas; read requests are spread across the replicas, so the system keeps answering quickly under heavy read load. See replication.

updatesRead requestsReplica 1Replica 2Replica MPrimary databasesource of truth
Read requests spread over replicas; the primary database pushes updates to all of them.

Scale writes with partitioning (sharding)

Split the database into smaller parts, each on its own server. Write requests are spread across the partitions, so no single server takes the whole write load and total write throughput grows with the number of partitions. See sharding.

Write requestsPartition routerby keyPartition 1Partition 2Partition N
Writes are routed by key to different partitions, each handling only its share.

Scale data flow with queues and consumers

A message queue sits between producers and the processes that do the work. Requests are handled asynchronously, and consumers can be scaled out to add processing capacity. This works best when requests can be processed independently of each other.

ProducerProducerProducerMessage queueConsumerConsumerConsumer
Many producers write to a queue; adding consumers raises how many messages are processed per second.

Little's Law ties them together

For any stable system, concurrency = throughput × latency (L = λW). This simple law is very useful for sizing:

  • A service handling 2,000 requests/s with 50 ms latency has on average 2,000 × 0.05 = 100 requests in flight. Size thread pools and connection pools around that.
  • If latency degrades to 500 ms at the same throughput, in-flight requests jump to 1,000. That is how a slow database exhausts connection pools and turns a slowdown into an outage.

The throughput–latency trade-off

Latency stays flat while a system is lightly loaded, then rises sharply as utilization approaches 100%, because requests start queuing. Running a server at 95% CPU maximizes throughput per dollar but makes latency unpredictable. Most latency-sensitive services target 50–70% utilization at peak to leave headroom.

TechniqueThroughputLatency
Batching (writes, network calls)Up: fixed costs amortizedUp: items wait for the batch to fill
CachingUpDown
Async processing via a queueUp: absorbs burstsDown for the caller, up for the work itself
CompressionUp on slow networksUp slightly for CPU time
More parallel workersUp, until a shared resource saturatesUnchanged or worse under contention

Latency numbers worth knowing

OperationApproximate time
L1 cache reference1 ns
Main memory reference100 ns
Read 1 MB sequentially from memory~10 µs
Random read from SSD~100 µs
Round trip within a data center~0.5 ms
Read 1 MB sequentially from SSD~1 ms
Disk (HDD) seek~10 ms
Round trip between continents100–200 ms

The ratios matter more than the exact values: memory is about 1,000× faster than SSD random reads, and a cross-region round trip costs as much as hundreds of in-region calls. More in back-of-the-envelope estimation and caching.

Where it’s used

Amazon

Measures page latency at the 99.9th percentile because its most valuable customers, with long histories and big carts, tend to have the slowest requests.

Google search

Uses hedged and tied requests across replicas to keep tail latency low in huge fan-out queries.

Kafka

Trades a little latency for big throughput gains by batching messages per partition and compressing batches.

Cloud databases

Managed databases such as Cloud Spanner and Firestore report p50, p95 and p99 latency so you can see the tail, not just the average.

In an interview

  • State latency targets as percentiles ("p99 under 200 ms for reads"), not averages.
  • Split latency into network and server time and say which part your design attacks (CDN and region choice vs caching and indexes).
  • Raise throughput with concurrency: replicas for reads, shards for writes, more consumers behind a queue.
  • Use Little's Law to size pools; mention fan-out and tail latency in feed or search designs.

Further reading