Latency vs throughput vs bandwidth is about three different numbers. Latency is how long one request takes. Throughput is how many requests (or how much data) the system actually completes per second. Bandwidth is the most a network link can carry per second. Bandwidth is the ceiling; throughput is what you really get; latency is what each user feels.
In this article we follow one example the whole way: a live cricket streaming app on the night of a big final. Lakhs of viewers watch the video, refresh the live score every few seconds and post in the match chat. Each feature cares about a different number: the score must arrive fast (latency), the chat must keep up with millions of messages (throughput), and the video needs enough capacity for every viewer (bandwidth). Every idea comes with runnable Java code, plus Python and C++.
Key takeaways
Latency is time per request, measured in milliseconds, and should be reported as percentiles (p50, p95, p99), not averages.
Throughput is work done per second (requests, messages or bytes) and is limited by the slowest part of the system.
Bandwidth is link capacity in bits per second; throughput can never go above it.
Small requests are limited by latency; large transfers are limited by bandwidth.
Little's Law ties them together: requests in flight = throughput x latency.
1. What Are Latency, Throughput and Bandwidth?
| Term | Question it answers | Unit | Cricket app example |
|---|---|---|---|
| Latency | How long does one request take? | ms or µs | Score update reaches the phone in 40 ms |
| Throughput | How much work is finished per second? | req/s, msgs/s, MB/s | Chat service saves 12,000 messages per second |
| Bandwidth | What is the most the link can carry? | Mbps, Gbps | A video server has a 10 Gbps network card |
A simple way to remember them is the Hyderabad Metro. The number of trains and coaches decides how many riders the line could carry each hour: that is bandwidth. The number of riders it actually carries, after slow boarding and crowded platforms, is throughput. The time one rider takes from Miyapur to LB Nagar is latency. Adding more coaches raises capacity, but it does not make any single trip shorter.
Bandwidth is capacity, throughput is what is achieved, latency is one trip
2. The Streaming App We Will Tune
Here is the design we start from. Video segments come from a CDN edge in Hyderabad, which fetches from the origin servers in Mumbai on a cache miss. The live score and chat go through an API gateway to a score service (backed by Redis and a database) and a chat service that pushes messages to a queue.
Components of the live cricket streaming app
The requirements show why one number is never enough: p99 score latency below 200 ms, chat throughput of 20,000 messages per second at the peak, and enough bandwidth for 25 lakh video viewers. We will look at each number in turn, then at how they affect each other.
3. Latency: Where Does the Time Go?
Latency is the time from sending a request to getting the full response, also called the round-trip time (RTT) when we talk about the network alone. For one request it is made of four network delays plus the server's own work:
The four network delays plus server processing make up latency
| Delay | What causes it | How to reduce it |
|---|---|---|
| Transmission | Pushing all the bytes onto the link; depends on size and bandwidth | Send fewer bytes, use a faster link |
| Propagation | The signal travelling the distance; light in fibre covers about 200 km per ms | Move servers closer to users (CDN, regions) |
| Queuing | Waiting in router and server queues when they are busy | Keep spare capacity, avoid bursts |
| Processing | Routers forwarding packets and the server running your code, queries and calls | Caching, indexes, faster code |
A new connection also pays for set-up before the first byte of the real request is sent: a DNS lookup, a TCP handshake (one round trip) and a TLS 1.3 handshake (one more round trip). Later requests on the same connection skip all three.
The first request pays for DNS, TCP and TLS; a reused connection does not
Latency budget in Java
The program below adds up the latency of one score request from a viewer in Hyderabad, first to a server in Mumbai (about 700 km of fibre) and then to a server in the US-East region (about 13,000 km).
Output
Server in Mumbai (700 km)
Round trip (RTT) : 7.0 ms
First request : 71.4 ms
Reused connection : 37.4 ms
Server in US-East (13000 km)
Round trip (RTT) : 130.0 ms
First request : 440.4 ms
Reused connection : 160.4 ms
Two lessons come out of these numbers. First, distance dominates: the US server is more than six times slower for the same code, and no amount of tuning can beat the speed of light. Second, connection set-up is expensive: for the US server, reusing the connection saves 280 ms. In Java this means using one shared HttpClient (which keeps connections alive and supports HTTP/2) instead of creating a new client per request, and using connection pools such as HikariCP for the database.
4. Measuring Latency: Why Averages Lie
Latency is not one number; every request takes a different time. Most requests are fast, but a few hit a slow database query, a garbage collection pause or a retry. The average hides those slow ones. Percentiles show them:
| Percentile | Meaning |
|---|---|
| p50 (median) | Half of the requests are faster than this |
| p95 | 95 out of 100 requests are faster than this |
| p99 | 99 out of 100 requests are faster; the slowest 1% are above it |
Output
Average : 98.5 ms
p50 : 50 ms
p95 : 160 ms
p99 : 1800 ms
Max : 2400 ms
Page calls N services, each slow 1% of time:
N = 1 -> page slow 1.0 % of the time
N = 5 -> page slow 4.9 % of the time
N = 10 -> page slow 9.6 % of the time
N = 20 -> page slow 18.2 % of the time
N = 50 -> page slow 39.5 % of the time
The average of 98.5 ms describes nobody: most viewers waited about 50 ms, while one in a hundred waited 1.8 seconds or more. That is why latency targets are written as percentiles, for example "p99 below 200 ms".
The second half of the output shows why the slow 1% matters more than it looks. A match page that calls five services in parallel has to wait for the slowest one:
With fan-out, the page is as slow as its slowest call
If each service is slow only 1% of the time, a page that calls 20 of them is slow 18.2% of the time, almost one page load in five. This is called tail latency. In Java you measure it with Micrometer timers (which publish p50, p95 and p99 to Prometheus), and you limit its effect with timeouts on every call and by calling independent services in parallel with CompletableFuture.
5. Bandwidth: The Size of the Pipe
Bandwidth is the maximum amount of data a link can carry per second. It is quoted in bits per second, while file sizes are usually in bytes, so divide by 8: a 1 Gbps link carries at most about 125 MB per second. Bandwidth exists at every level, not just the network:
| Resource | Rough bandwidth |
|---|---|
| Mobile 4G connection | 10 to 50 Mbps |
| Home broadband | 50 to 300 Mbps |
| Server network card | 10 to 100 Gbps |
| NVMe SSD | A few GB per second |
| Memory (RAM) | Tens of GB per second |
Whether bandwidth or latency matters more depends on how much data you send. A useful rule is transfer time = latency + size / bandwidth:
Small payloads are latency-bound; large ones are bandwidth-bound
Output
Score update, 2 KB
50 Mbps: 40.3 ms (latency-bound)
1000 Mbps: 40.0 ms (latency-bound)
Video segment, 4 s of 1080p (2.5 MB)
50 Mbps: 440.0 ms (bandwidth-bound)
1000 Mbps: 60.0 ms (latency-bound)
Match highlights download, 500 MB
50 Mbps: 80040.0 ms (bandwidth-bound)
1000 Mbps: 4040.0 ms (bandwidth-bound)
One 10 Gbps server can stream to 2000 viewers
25 lakh viewers need 12500 Gbps -> use a CDN
For the 2 KB score update, a link 20 times faster saves only 0.3 ms, because almost all of the time is the 40 ms round trip. For the 500 MB highlights file, the same upgrade saves more than 75 seconds. The last two lines show the bandwidth problem of the whole system: one server can feed only 2,000 viewers at 5 Mbps each, and 25 lakh viewers need 12,500 Gbps. That is why video is served from CDN edges spread across the country, and why the app offers lower bitrates on slow mobile networks (adaptive bitrate streaming).
6. Throughput: What the System Really Delivers
Throughput is the work actually completed per unit of time: requests per second for an API, messages per second for the chat, MB per second for a file transfer. It is always at or below bandwidth, because of protocol headers, lost packets that must be resent and TCP slowing down when the network is busy.
More importantly, a request passes through several components, and the whole system can only go as fast as the slowest one. That component is the bottleneck:
The slowest stage sets the throughput of the whole pipeline
Output
Comment pipeline (before)
Load balancer 50,000 req/s
API servers 12,000 req/s
Redis cache 80,000 req/s
DB writes 2,500 req/s
=> system: 2,500 req/s, bottleneck = DB writes
After batching DB writes
Load balancer 50,000 req/s
API servers 12,000 req/s
Redis cache 80,000 req/s
DB writes 20,000 req/s
=> system: 12,000 req/s, bottleneck = API servers
The load balancer and Redis can handle far more than 2,500 comments per second, but the database writes cannot, so the system as a whole cannot either. Writing comments in batches of 8 moves the limit up to 12,000, and now the API servers are the bottleneck. This is how throughput work goes in practice: measure every stage, fix the slowest one, then measure again, because the bottleneck moves. In a Spring Boot service, the usual limits are the Tomcat thread pool, the HikariCP connection pool size, the database itself and slow downstream calls.
7. How Latency and Throughput Affect Each Other: Little's Law
Latency and throughput are linked by a simple rule from queueing theory, Little's Law:
Requests in flight = throughput x latency
For capacity planning this tells you how many threads or connections you need. At 20,000 requests per second and 50 ms per request, 1,000 requests are being handled at any moment, so a pool of 1,200 threads is enough. But if a dependency such as the player stats service slows down, the same traffic needs far more threads:
A slow dependency fills the thread pool and creates a queue
Output
Latency 50 ms at 20000 req/s
in flight : 1000 (pool has 1200)
pool max : 24000 req/s -> OK
Latency 250 ms at 20000 req/s
in flight : 5000 (pool has 1200)
pool max : 4800 req/s -> queue grows!
BDP (1 Gbps x 100 ms) : 12.5 MB in flight
64 KB window gives : 5.2 Mbps only
At 250 ms, 5,000 requests need to be in flight but only 1,200 threads exist, so the pool can serve just 4,800 requests per second and the rest wait in a queue. The waiting adds more latency, which needs even more threads. This is how one slow service drags a whole system down. The defences are timeouts on every outgoing call, separate pools per dependency, and a circuit breaker such as Resilience4j (covered in the Reliability article).
The bandwidth-delay product
The same idea applies inside the network. To keep a link full, enough data must be "in flight" to cover one round trip: bandwidth-delay product (BDP) = bandwidth x RTT. The last two lines of the output show that a 1 Gbps link with a 100 ms round trip needs 12.5 MB in flight, but a connection limited to a 64 KB TCP window can only reach about 5.2 Mbps. Modern operating systems grow the window automatically, but for long-distance transfers (for example, copying match footage between regions) you may still need larger socket buffers or several parallel connections.
8. The Trade-off: Batching and Busy Servers
Many techniques that raise throughput do it by making individual requests wait a little. The classic example is batching: instead of writing every chat message to the database on its own, collect them for a short time and write them together.
Batching trades a small wait for much higher throughput
Output
Batch | msgs/s per writer | extra wait
1 | 196.1 | 0.00 ms
10 | 1666.7 | 2.25 ms
100 | 6666.7 | 24.75 ms
500 | 9090.9 | 124.75 ms
Server busy | response time (10 ms of work)
50% | 20 ms
80% | 50 ms
90% | 100 ms
95% | 200 ms
Each database call has a fixed cost of 5 ms, so writing one message at a time gives only 196 messages per second per writer. Batches of 100 give 6,666 per second, 34 times more, at the cost of about 25 ms of extra waiting. That is a good trade for chat, but not for the live score, where every millisecond counts. In Java, Kafka producers do exactly this with linger.ms (how long to wait) and batch.size (how much to collect), and JDBC offers addBatch() and executeBatch().
The second table shows the other trade-off: utilization. A server whose work takes 10 ms answers in 20 ms when it is 50% busy, but in 200 ms when it is 95% busy, because requests spend most of their time queuing. Running servers close to 100% gives the most throughput per rupee, but latency becomes high and unpredictable. Most teams keep normal load around 60 to 70% and autoscale before reaching 80%.
9. How to Reduce Latency
For the live score, latency is what viewers notice. The main techniques:
| Technique | What it saves | In a Java stack |
|---|---|---|
| Serve from close to the user | Propagation delay | CDN edges, servers in Indian regions |
| Cache hot data | Database and processing time | Redis or Caffeine, Spring @Cacheable |
| Reuse connections | DNS, TCP and TLS round trips | Shared HttpClient, HTTP/2, HikariCP |
| Call services in parallel | Waiting for calls one after another | CompletableFuture.allOf |
| Move slow work off the request | Time the user waits | Kafka or RabbitMQ consumers, @Async |
| Push instead of poll | Repeated request round trips | WebSocket or Server-Sent Events for score updates |
| Set timeouts everywhere | Tail latency from stuck calls | HttpClient timeouts, Resilience4j TimeLimiter |
The CDN is the biggest win for video and static files, because it removes most of the distance:
A CDN edge serves repeated requests close to the viewer
10. How to Increase Throughput and Use Bandwidth Well
For the chat and the video, the goal is to handle more work and move fewer bytes:
| Technique | Effect | In a Java stack |
|---|---|---|
| Find and fix the bottleneck | Raises the limit of the whole pipeline | Load test with JMeter or Gatling, check each stage |
| Scale out | More servers share the load | Stateless services behind a load balancer, Kubernetes HPA |
| Batch writes | Fewer expensive calls | Kafka linger.ms, JDBC executeBatch() |
| Use queues for spikes | Absorbs bursts, workers drain at a steady rate | Kafka, RabbitMQ |
| Compress responses | Fewer bytes per response | server.compression.enabled=true in Spring Boot |
| Send only what is needed | Smaller payloads | DTOs instead of whole entities, pagination |
| Adaptive bitrate video | Matches the bandwidth each viewer really has | HLS or DASH with several quality levels |
11. Which One Matters Most for Your System?
| System | Most important | Why |
|---|---|---|
| Live score, multiplayer games, trading | Latency | Every millisecond changes what the user sees or wins |
| Chat, payments at peak, order processing | Throughput (with a latency limit) | Must keep up with the incoming volume |
| Video streaming, large downloads | Bandwidth and throughput | Huge data per user, multiplied by many users |
| Nightly reports, data pipelines | Throughput | The job must finish on time; single-record latency does not matter |
Real requirements combine them, for example: "p99 latency below 200 ms while handling 20,000 requests per second." A design that meets one number by breaking the other is not finished.
12. Common Mistakes
Reporting average latency. It hides the slow requests users complain about; use p95 and p99.
Buying more bandwidth for a latency problem. Small API calls are limited by round trips, not by link speed.
Mixing bits and bytes. 100 Mbps is about 12.5 MB per second, not 100 MB.
Load testing one stage only. The bottleneck may be the database or a downstream service, not the API you tested.
Running servers at 90%+ utilization. Throughput looks great until latency suddenly jumps.
Creating a new HTTP client or DB connection per request. Every request then pays for the full connection set-up.
13. Interview Questions on Latency vs Throughput vs Bandwidth
What is the difference between latency, throughput and bandwidth? Latency is the time for one request, throughput is the work completed per second, and bandwidth is the maximum the link can carry. Throughput is at most the bandwidth and is limited by the slowest component.
Can a system have high bandwidth but high latency? Yes. A satellite link may offer 100 Mbps, but its round trip can be 600 ms, so small requests still feel slow.
Why use p99 instead of the average? The average hides slow requests. With fan-out, the slow 1% affects a large share of page loads.
How do you size a thread pool? Use Little's Law: threads needed = requests per second x latency in seconds, plus headroom, and protect the pool with timeouts.
How does batching affect latency and throughput? It raises throughput by sharing fixed costs across many items, but each item waits longer before it is processed.
Summary
| Number | What it measures | How to improve it |
|---|---|---|
| Latency | Time per request (use p50, p95, p99) | Move closer, cache, reuse connections, parallel calls, timeouts |
| Throughput | Work completed per second | Fix the bottleneck, scale out, batch, use queues |
| Bandwidth | Maximum capacity of a link | Bigger links, CDN, compression, smaller payloads |
The streaming app tuned for latency, throughput and bandwidth
Bandwidth is the ceiling, throughput is what you achieve, and latency is what each user feels.
Measure latency with percentiles; tail latency grows with every service a page calls.
Transfer time = latency + size / bandwidth: small requests are latency-bound, big transfers are bandwidth-bound.
Throughput is set by the slowest stage; fix it and measure again.
Little's Law (in flight = throughput x latency) explains thread pool sizing and why one slow service can stall a system.
Batching and high utilization raise throughput but add latency; choose based on what the feature needs.
Previous topic: Reliability. Next: CAP Theorem.