Skip to content
AI engineeringIntermediate10 min

Tokens, latency and throughput

Why serving more users at once makes the server faster overall but each user slower, and how to pick the balance.

Sign in to save this lesson

You will learn to

  • Tell latency (how long one user waits) from throughput (how much work the server finishes).
  • Explain how batching trades per-user speed for total throughput.
  • Choose which metric to optimise for a chat app and for a batch job.

Before you start: The life of an LLM request (prefill and decode).

Think of it like

A bus versus a taxi. A taxi gets one person there fastest. A bus is slower for each passenger because it stops more, but it moves far more people per hour. A model server can run as a taxi, a bus, or anything in between.

Explanation depth
Diagram: Everything is counted in tokensThree users send requests to a batch scheduler, which groups them and runs them together on one model server. A metrics panel shows per-user speed and total throughput.User AUser BUser CBatch schedulerModel serverMetrics→ 1,000 tokensbatch

Step 1 of 6

Everything is counted in tokens

Prompt tokens are read during prefill; output tokens are written during decode. Cost, limits and speed are all quoted per token, so a token count is the unit of work.

Try it: Latency versus throughput

This is a simplified model in which each extra request in the batch slows every decode step by a fixed percentage. Real servers behave less linearly; the default numbers are illustrative.

1,000 tokens

Input tokens per request.

250 tokens

Output tokens per request.

8 requests

How many sequences the server decodes together.

20 ms

Time per output token when the request has the server to itself. Illustrative.

4 %

How much each extra sequence in the batch slows every step. Illustrative.

10,000 tokens/s

How fast the prompt is read. Illustrative.

Time per output token
25.6 ms
20 × (1 + 4% × (8 − 1)) = 25.6 ms
Time to first token
100 ms
1000 ÷ 10000 tokens/s = 100 ms
Full answer, per user
6,474 ms
100 + (250 − 1) × 25.6 = 6474 ms
Speed one user sees
39.1 tokens/s
1000 ÷ 25.6 ms
Server throughput
313 tokens/s
8 × 39.1
Requests finished
74.1 per minute
8 ÷ 6474 ms × 60 000

Assumptions

  • Each extra request in the batch slows every decode step by a fixed percentage (a simple linear model; real engines vary).
  • Prefill runs once per request at a constant speed and does not wait for other requests.
  • Requests in the batch have the same prompt and answer length.
  • All speeds are illustrative inputs, not measurements of a particular model or GPU.

Key takeaways

  • Latency is what one user feels; throughput is what the server delivers in total.
  • Batching raises throughput and lowers each user's speed at the same time.
  • Continuous batching stops short requests waiting behind long ones.
  • Choose the batch size by measuring p95 latency against throughput for your own workload.

The parts

User A:
A chat user waiting for an answer.
User B:
Another chat user, arriving at about the same time.
User C:
A third user.
Batch scheduler:
Decides which requests run together in each step of the model.
Model server:
Runs one decode step for every request in the batch at the same time.
Metrics:
Per-user tokens per second and total tokens per second.

Check your understanding

  1. 1. The server's total tokens per second doubled, but users say it feels slower. What is the most likely explanation?
  2. 2. You run a nightly job that summarises 200,000 support tickets. What should you optimise?
  3. 3. What problem does continuous batching solve?

Finish every step and answer the checks to complete this lesson.

Further reading

Recommended next