ML System Design

Latency vs Throughput vs Cost

Understanding the three way tradeoff between response speed, request throughput, and compute cost in ML serving.

🟡 intermediate5 min readserving
Latency vs Throughput vs Cost is a fundamental tradeoff in ML system design. Latency measures how fast a single request gets a response. Throughput measures how many requests the system handles per second. Cost measures the hardware spend. Optimizing one often hurts another, so engineers must choose the right balance for their use case.

The Three Way Tradeoff

Every ML serving system operates within a triangle of competing constraints:

                    LATENCY
              (Response Speed per Request)
                       ╱╲
                      ╱  ╲
                     ╱    ╲
                    ╱      ╲
    THROUGHPUT ◄──────────────► COST
  (Requests per Second)     (Hardware $)

You can optimize any two, but the third usually suffers:

Want Low Latency + High Throughput?You need expensive hardware (more GPUs, faster networking). Cost goes up.
Want Low Latency + Low Cost?You get limited throughput because cheap hardware cannot handle many concurrent requests.
Want High Throughput + Low Cost?Use large batches on fewer GPUs, but individual request latency increases.

Latency: How Fast Is One Request?

Latency is the time from when a request arrives to when the response is sent back. Measured in milliseconds.

Key contributors to inference latency:

For real-time applications (search, ads, chat), total latency budgets are strict: P99 under 100ms is common.

Throughput: How Many Requests Per Second?

Throughput is the total number of requests the system processes per second (QPS or RPS).

Techniques to increase throughput:

Cost: What Does It Take To Run?

GPU inference is expensive. A single A100 GPU costs roughly $2 to $3 per hour in the cloud.

Cost reduction techniques:

Making The Right Choice

Use CasePriorityTypical Setup
Real-time search/adsLow LatencySmall optimized models, no batching, TensorRT
Overnight batch recommendationsHigh Throughput, Low CostLarge batches, spot instances, bigger models
Chat assistantModerate Latency, Moderate CostStreaming tokens, medium-sized model, autoscaling

Say this out loud

ML serving involves a three way tradeoff between latency, throughput, and cost. Low latency requires fast models and dedicated hardware. High throughput uses batching and horizontal scaling. Low cost uses quantization, smaller models, and autoscaling. The right balance depends on whether the application is real-time, interactive, or batch.

Followups to expect

  1. What is P99 latency and why does it matter more than average latency? P99 is the latency experienced by the slowest 1% of requests. A good average can hide terrible tail latency that affects many users.
  2. How does dynamic batching work? The server accumulates incoming requests for a short window (e.g. 5ms), then processes them as a batch. This balances latency (short wait window) with throughput (batch efficiency).

Check yourself

Question 1 of 3

What happens to per-request latency when you increase batch size to improve GPU throughput?

More in ML System Design

See all →
A Framework for Any ML Design Round5 minFraming a Business Problem as ML5 minOnline vs Offline Evaluation5 min