Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path
Latency Budget Builder
Assemble a chat request stage by stage — network, gateway, retrieval, rerank, prefill, decode — and watch the waterfall: time to first token, full response time, a stacked bar of where the milliseconds went, and which stage to attack first when the budget blows.
A chat request has two latencies: the wait before the first token appears, which users feel, and the streaming that follows, which they mostly read through. This builder lays out every stage of a retrieval-augmented LLM request as a waterfall, so you can see which stage owns the time to first token (TTFT) and what the whole response costs.
What it computes
prefill_ms = prompt_tokens ÷ prefill_tok_per_s × 1,000
decode_ms = output_tokens ÷ decode_tok_per_s × 1,000
TTFT = network + gateway + retrieval + rerank + prefill_ms
total = TTFT + decode_ms
- network is the client-to-edge round trip, gateway covers auth, routing and rate limiting, retrieval is the vector and keyword search, and rerank is a cross-encoder pass over the shortlist. All four are entered in milliseconds.
- prefill is the model reading the whole prompt before it can emit anything, so it scales with prompt size.
- decode is generating the answer one token at a time. It is left out of TTFT because the output streams.
The bottleneck readout names the largest of the five stages before streaming. The verdict under TTFT has four bands: up to 500 ms “feels instant”, up to 1,000 ms “feels responsive”, up to 2,000 ms “noticeably slow to start”, and anything above “users will assume it broke”. The bar shows each stage’s share of the full response.
A worked example
The defaults model a RAG chat turn: a 60 ms round trip, 15 ms of gateway, 80 ms of retrieval, 50 ms of rerank, a 4,000-token prompt prefilled at 4,000 tokens per second, and a 400-token answer decoded at 60 tokens per second.
| Stage | Calculation | Time |
|---|---|---|
| Network | input | 60 ms |
| Gateway | input | 15 ms |
| Retrieval | input | 80 ms |
| Rerank | input | 50 ms |
| Prefill | 4,000 ÷ 4,000 × 1,000 | 1,000 ms |
| Time to first token | sum of the five | 1,205 ms |
| Decode | 400 ÷ 60 × 1,000 | 6,667 ms |
| Full response | TTFT + decode | 7.9 s |
TTFT lands at 1,205 ms, in the “noticeably slow to start” band, and the bottleneck is Prefill, with 1,000 of those 1,205 ms. Decode is 84.7% of the full response, but streaming hides most of it. Halve the prompt to 2,000 tokens, or double prefill speed to 8,000 tokens per second, and prefill drops to 500 ms, putting TTFT at 705 ms: “feels responsive”. Grow the prompt to 20,000 tokens instead and prefill alone takes 5 seconds.
Assumptions and limits
- Stages run in series. The model adds every stage. If your app overlaps work, for example running keyword and vector search in parallel inside retrieval, enter the overlapped time, not the sum.
- Constant token rates. Real prefill slows per token as context grows, because attention cost rises with length, and decode speed varies with load and batch size. Prompt caching makes the cached part of a prompt far cheaper to prefill; the tool can only approximate that through a higher prefill rate.
- No queueing stage. Time spent waiting for capacity at the model provider is not modeled. Fold it into the gateway number, or production will surprise you.
- One round trip. A new connection needs extra round trips for the TCP and TLS handshakes, so a cold first request can cost two or three times the RTT.
- Visible tokens only. A reasoning model generates its thinking before the answer. If you hide that thinking, its decode time belongs in TTFT, which the tool does not add.
How to use the result
- Attack the bottleneck first. Prefill: cache the stable prefix (system prompt, tools, history) and send fewer retrieved chunks. Network: serve closer to users and cut round trips. Retrieval: approximate indexes and fewer candidates. Rerank: a shorter shortlist or a smaller cross-encoder.
- Turn a TTFT target into a prompt budget. Subtract the fixed stages from the target and multiply by the prefill rate. At the defaults, a 1,000 ms target leaves 795 ms for prefill, or 3,180 prompt tokens; a 500 ms target leaves room for 1,180.
- Budget the tail, not the mean. Enter p95 or p99 stage times. Summing tail values is pessimistic, since stages rarely all hit their tail on one request, and that is the safe side to err on.
- Watch the total for non-streaming callers. Agents, tool calls and JSON parsers wait for the whole answer, so for them the 7.9 s total matters more than TTFT, and decode speed or a shorter answer is the lever.
When to use it, and when not
Use it while designing an LLM feature, before you can trace one: to see whether a TTFT target is reachable with the prompt you plan to send, to argue for prompt caching or a smaller retrieval set with numbers, and to decide which team’s milliseconds matter. A 50 ms win in the gateway is worth little when prefill takes 1,000.
It is the wrong tool once you have traces. A real span waterfall shows overlap, queueing and retries that this sum cannot. It also fits poorly for agents that loop over several model calls, where the budget is the sum of many waterfalls, and for voice, where speech recognition and synthesis add stages the tool does not have.
Trade-offs and limits
Each thing the model leaves out lands on TTFT, and some are large. At the defaults, where TTFT is 1,205 ms:
| Left out | Assumption | TTFT |
|---|---|---|
| Nothing (the tool) | warm connection, visible tokens only | 1,205 ms |
| Cold connection | TCP plus a TLS 1.3 handshake: 2 more round trips | 1,325 ms |
| Ten more retrieved chunks | 500 tokens each, 5,000 tokens of prefill | 2,455 ms |
| Hidden reasoning | 500 thinking tokens at 60 tok/s, illustrative | 9,538 ms |
Hidden reasoning is the one that surprises teams. The thinking is decoded, not prefilled, so it runs at decode speed. At these rates 500 tokens of it cost almost seven times the rest of the TTFT. Show a progress indicator, or stream a summary of the reasoning, if the user would otherwise watch a blank screen.
Common mistakes
- Measuring TTFT at the server. Server-side timing starts after the request arrives and stops before the first byte travels back. Users wait for both trips; measure in the client.
- Buying faster decode for a slow start. At the defaults, doubling decode speed cuts the full response from 7.9 to 4.5 seconds but does not change TTFT at all. If users complain about the wait, the bottleneck stage is prefill.
- Retrieving “just in case”. Every extra chunk is prefill time on every request. Ten more 500-token chunks add 1,250 ms at 4,000 tokens a second, doubling the default TTFT.
- Budgeting only the happy path. A timeout and retry, or a fallback to a second model, repeats the gateway, prefill and often retrieval. One retry after a 2 s timeout puts the user past 3 seconds even with every stage on budget.
Check yourself
Set the prompt to its 200-token minimum and leave everything else at the defaults. What is TTFT, and what is the bottleneck now?
Prefill is 200 ÷ 4,000 × 1,000 = 50 ms, so TTFT is 205 + 50 = 255 ms, “feels instant”. The bottleneck moves to Retrieval at 80 ms, so the next win is in search, not the model.
Keeping the 4,000-token prompt, what prefill speed brings TTFT to 500 ms or less?
The other stages take 205 ms, leaving 295 ms for prefill: 4,000 ÷ 0.295 = 13,559 tokens a second. On the slider, 13,750 gives a TTFT of 496 ms; 13,500 gives 501 ms, just over.
An agent waits for a full 1,000-token answer at 60 tokens a second. What is its total, and what does doubling decode speed save?
Decode is 1,000 ÷ 60 = 16.7 s, so the total is 17.9 s. At 120 tokens a second decode is 8.3 s and the total 9.5 s. TTFT stays 1,205 ms in both cases; for a non-streaming caller decode is the lever.
The first request opens a fresh connection with TCP and TLS 1.3. How much does that add at a 60 ms round trip?
TCP’s handshake takes one round trip and TLS 1.3 one more before the request can go, so the first request needs three round trips instead of one: 120 ms more, for a TTFT of 1,325 ms. Connection reuse removes it for later requests.
How it works
- TTFT = network + gateway + retrieval + rerank + prompt tokens ÷ prefill rate.
- Total = TTFT + output tokens ÷ decode rate; streaming hides the decode.
- The bottleneck is the largest of the five stages before streaming starts.
- Up to 500 ms feels instant; over 2 s users assume it broke.
Frequently asked questions
What counts toward time to first token?
Everything that happens before the first output token is streamed: the network round trip, gateway work such as auth and rate limiting, retrieval and reranking in a RAG app, and prefill, where the model reads the entire prompt. Decode is excluded, because once tokens flow the user is reading. With this tool’s defaults those stages add up to 60 + 15 + 80 + 50 + 1,000 = 1,205 ms. TTFT is the blank-screen wait, and it is the latency users notice most in a chat interface.
Why does a big prompt hurt TTFT so much?
Prefill processes every prompt token before the first output token can exist, so prefill time grows with prompt length. At 4,000 tokens per second, a 4,000-token prompt costs one second and a 50,000-token RAG prompt costs 12.5 seconds of dead air, more than every other stage combined. Two fixes help most: prompt caching, so the stable prefix is not reprocessed on every turn, and retrieval discipline, sending a few relevant chunks instead of many marginal ones, which tends to help answer quality as well.
How do I measure prefill and decode speed for my model?
Time a few real requests with streaming on. Decode speed is the output tokens divided by the time between the first and the last token. For prefill, take the TTFT measured at the API, subtract the network round trip, and divide the prompt tokens by what remains. Try both a short and a long prompt, because queueing and fixed overheads distort a single small request. Measure at your real traffic level, since both rates fall when the provider or your own GPUs are busy.
Should I budget the average or the p99?
Budget the tail. A user sends many requests in a session, so a slow p99 is something regular users meet, not a rare event. Build the waterfall from p95 or p99 stage times, especially retrieval and any queueing, which inflate most under load. Adding up per-stage tail values is pessimistic, since the stages rarely all hit their worst case on the same request, but that is the safe side to err on. If the tail waterfall fits the target, the median will too.
What is a good time to first token for a chat app?
This tool’s bands are a reasonable guide: up to 500 ms feels instant, up to 1 second feels responsive, up to 2 seconds is noticeably slow to start, and beyond that users start to assume something broke. They line up with long-standing usability guidance that about one second is the limit for keeping a user’s flow of thought uninterrupted. Voice interfaces need to be faster still, because silence in a spoken conversation is far more noticeable than a blank text box.
When does full response time matter more than TTFT?
Whenever nothing is shown until the answer is complete. Agents that call tools, pipelines that parse JSON and batch jobs all wait for the last token, so for them decode dominates: at the defaults, decode is 6,667 of the 7,872 ms total. The levers there are shorter outputs, a faster or smaller model, and techniques such as speculative decoding. In a streaming chat interface the full time matters less, because the user starts reading as soon as the first tokens arrive.