Latency vs Throughput: Definitions and Optimization Strategies
Fast recall
Quick revision
Core answer
Whether you understand that latency and throughput are often in tension and that optimizing one can harm the other without careful design.
Treating them as the same thing or assuming that faster individual requests always means better throughput.
Explain the latency-throughput trade-off using queuing theory, mention percentile latency (p99) vs average, and give concrete Java-level examples for each axis.
Interview-ready guide
Interview answer
Latency and throughput measure different things and are optimized differently — which means a change that reduces latency may increase throughput, reduce it, or have no effect, depending on where the bottleneck is.
The definitions
- Latency is how long one request takes — the user's wait from sending the request to receiving the response; measured in milliseconds per request; P99 latency is the experience of the worst-affected 1% of users
- Throughput is how many requests the system handles per unit of time — requests per second; the ceiling is determined by the bottleneck resource (CPU, I/O, threads, connection pool)
Latency optimization — reduce per-request work
- Eliminate unnecessary operations on the critical path: a database query that joins five tables when only two columns are needed; a synchronous HTTP call to a dependency that could be async; JSON deserialization of a large payload when only one field is used
- Caching: serve responses from Redis in microseconds instead of database queries in milliseconds; the first request is slow, every subsequent one is fast
- Reduce serialization overhead: Jackson ObjectMapper is expensive to construct; singleton ObjectMapper with specific features disabled; faster serializers like Jackson Afterburner or custom serializers for hot paths
Throughput optimization — remove the bottleneck
- Throughput is limited by the bottleneck resource; increasing throughput means identifying and removing that bottleneck
- If the bottleneck is the thread pool (threads saturated): add more threads (if I/O-bound) or reduce per-request CPU work; or switch to reactive/non-blocking I/O (WebFlux) which eliminates thread-per-request
- If the bottleneck is the database: add read replicas, add indexes, implement caching; the database often becomes the bottleneck before the application does
The trade-offs
- Batching increases throughput at the cost of latency — batching 100 writes in one database transaction reduces I/O but each write waits until the batch is full
- Parallelism reduces latency (fan-out multiple I/O calls) at the cost of more threads —
CompletableFuture.allOf()runs multiple downstream calls in parallel; each call uses a thread
Latency vs Throughput: Definitions and Optimization Strategies
Direct Answer
Latency is time per request; throughput is requests per second. Optimize latency by reducing per-request work (caching, async I/O); optimize throughput by maximizing concurrency and batching.
Common Mistakes & Pitfalls
Treating them as the same thing or assuming that faster individual requests always means better throughput.
Check your understanding
Answer these without looking back at the article.
- Why do you measure p99 latency instead of average?
- How does Little's Law relate latency and throughput?
- How do you prevent high throughput from degrading latency?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.