Composite scenario, not a real company. Assembled from common industry patterns; every number is illustrative and its assumptions are listed at the end.
This case belongs to Models, routing and inference for AI Architects.
Context
- A B2B project-management product adds an assistant panel to every page: summarise the board, explain a field, draft a status update.
- Each message sends instructions (2,000 tokens), 12 tool descriptions (3,000) and the page (up to 9,000).
- The reply returns in one piece, with a spinner until then. Support tickets say the assistant "hangs".
Problem statement
| Profile | Input tokens | Answer tokens | Wait, nothing on screen |
|---|---|---|---|
| Typical | 8,000 | 400 | 15.63 s |
| Long (stands in for the slow tail) | 14,000 | 800 | 30.17 s |
Goal: first visible text within 2 seconds for both profiles, and a typical complete answer within 10 seconds.
Constraints
- Page context can be trimmed, not dropped; quality cannot be traded for speed without a check.
- Replies used to be checked in full before display; the team must decide which intents may stream.
- Only the Orchestrator and Model gateway can change, not the provider.
Why the traditional approach fell short
| Approach | Where it breaks |
|---|---|
| Help centre search and field tooltips | Near-instant, which sets the expectation for every help feature, but the same article for everyone and blind to the board |
| Report templates | A fixed status update that cannot adapt to what changed this week |
A 15 to 30 second wait loses against a search box.
Options considered
| Option | Verdict | Reason |
|---|---|---|
| A. Non-AI help: tooltips, help search, a status template | Kept for definitional questions | Instant, no model risk; cannot see the board |
| B. Stream the reply, change nothing else | Rejected as the whole answer | First text at 2.33 s typical but 3.53 s long, and the full answer is as slow as before |
| C. Stream, shrink prefix and context, cache the prefix, shorten answers, small model for first-turn intents | Accepted | Targets first text and the tail |
Default choice: C. B improves only how the wait feels; the tail comes from input size and output length.
Solution architecture
Figure 1. The original request, as a timeline of one non-streamed call
How to read this: the notes carry the time budget, and the only message the user sees is the last arrow.
Figure 2. Components after the redesign
How to read this: the Orchestrator decides what goes into the prompt and which tier answers, and the reply flows back along the same path as a stream.
Figure 3. Runtime path with streaming and a mid-stream failure
How to read this: the loop is the stream, and the alt block is the case where the call fails after the user has already seen text.
How AI solved it, step by step
Step through the redesigned request, then switch to "Without the fix".
Under the hood
The mechanism is the split between prefill and decode (Under the hood: Prefill and decode).
- The PagedAttention paper describes the prompt phase as parallelisable over the whole prompt, and the generation phase as producing tokens one at a time, which "severely underutilizes GPU computation" and is "responsible for most portion of the latency of a single request".
- The DistServe paper names the matching metrics: time to first token for prefill, time per output token for decoding.
- Anthropic's latency documentation (as of 2026-10-22) recommends a faster model, fewer prompt and output tokens, and streaming.
The planning model (formulas under Assumptions) is not a documented provider formula, and its cache term is an assumption: OpenAI's documentation says caching reduces processing before the response starts but does not guarantee lower latency. Measure the rates on your own traffic.
Against the 2 s goal, set Prefill to 1.2 (shrunk prompt, 1.93 s), then 0.6 (cached prefix, 1.33 s).
What went wrong / failure modes
| Failure | What happens | Mitigation |
|---|---|---|
| Streaming fails midway | An error can arrive as an event inside a stream already started (Anthropic streaming documentation) | Keep the partial text, mark it incomplete, offer a retry; this design does not resume |
| Cold-cache requests set the tail | The first request after the cache lapses pays the full prefill: 2.53 s for the long profile on the large tier, above the 2 s target | Measure time to first text by cache state |
| Idle connections | Anthropic notes delays between events while tool input is produced; the WHATWG standard says legacy proxy servers are known to drop HTTP connections after a short timeout and suggests a comment line every 15 seconds or so | Heartbeat comments, a client stall timer |
| Unvetted streamed text | Text is shown before the check | Do not stream replies that need validation first (see guardrails) |
| Wrong tier | A small-tier summary can be weaker | Unknown intents go up; review samples per tier |
Results
Illustrative targets from the budget model, not measurements. Seconds:
| Step | Typical: first text | Typical: complete | Long: first text | Long: complete |
|---|---|---|---|---|
| Original, not streamed (user sees the end) | 15.63 | 15.63 | 30.17 | 30.17 |
| Stream | 2.33 | 15.63 | 3.53 | 30.17 |
| Shrink prefix and context, shorter answers | 1.93 | 10.23 | 2.53 | 19.17 |
| Cache the 3,000-token prefix | 1.33 | 9.63 | 1.93 | 18.57 |
| Small tier for first-turn intents | 0.91 | 3.68 | 1.11 | 6.66 |
With 60% of typical requests on the small tier and 40% on the large, the means are 1.08 s to first text and 6.06 s complete. On the large tier the long profile only just meets the 2 s goal (1.93 s) and still takes 18.57 s to finish.
Tradeoffs and when NOT to use this approach
- Streaming improves the feel of the wait, not the total time, and complicates the client.
- Shorter answers may omit detail; practitioners differ on the trade, so test it with users.
- Do not stream output that code will parse or that must be validated first.
- Skip the small tier if the intent classifier is less reliable than the latency problem is costly.
- Background jobs with no user waiting do not need this.
Design rules extracted
- Budget latency as stages (overhead, prefill, decode) before choosing fixes; measure the tail with a long profile.
- Cut input tokens every request pays for: select tools by intent, cap page context.
- Put the stable prefix first so it can be cached, and track time to first text by cache state.
- Stream user-facing replies, and design the mid-stream failure path on day one.
- Keep a non-AI path for fixed answers.
Assumptions
All numbers are illustrative. First text = 0.7 + uncached input / prefill rate + 1 / decode rate; complete = 0.7 + uncached input / prefill rate + output / decode rate.
- Overhead 0.7 s (0.3 network, 0.4 context assembly). Large tier: prefill 5,000 tokens/s, decode 30/s. Small tier: prefill 15,000/s, decode 90/s.
- Typical: 2,000 + 3,000 + 3,000 page = 8,000 in, 400 out. Long: 5,000 prefix + 9,000 page = 14,000 in, 800 out.
- Not streamed, typical: 0.7 + 8,000 / 5,000 + 400 / 30 = 15.63 s; long: 0.7 + 2.8 + 26.67 = 30.17 s. Streamed first text: 0.7 + 1.6 + 0.033 = 2.33 s; long 3.53 s.
- Shrink: tools 3,000 to 1,000, long page 9,000 to 6,000, answers 400 to 250 and 800 to 500. Typical 6,000 in, long 9,000 in.
- Cache: the 3,000-token prefix adds no prefill time (assumed). Large tier, typical: 0.7 + 3,000 / 5,000 + 0.033 = 1.33 s, complete 0.7 + 0.6 + 8.33 = 9.63 s; long 1.93 s and 18.57 s. Cold cache, long: 0.7 + 1.8 + 0.033 = 2.53 s.
- Small tier, typical: 0.7 + 0.2 + 0.011 = 0.91 s, complete 3.68 s; long 1.11 s and 6.66 s. Means: 0.6 x 0.91 + 0.4 x 1.33 = 1.08 s; 0.6 x 3.68 + 0.4 x 9.63 = 6.06 s.
- The split, token counts, rates, product and users are invented.
Last verified: 2026-10-22