CertPrep
Domain 6 · Lesson 6.2 · 6 min read

Latency Engineering

Exam skillLatency Engineering

Analyzing the latency profile of a Claude application against a latency target, distinguishing time-to-first-token from total latency, and applying streaming, parallel tool execution, cache checkpointing, and effort-level tuning.

Break a Claude application's latency into its parts, tell time to first token from total latency, and apply the matching technique (streaming, parallel tool execution, cache checkpoints, effort tuning, model routing, shorter outputs) measured end to end.

What you need to know

"It is slow" can mean two different things. Time to first token (TTFT) is how long before anything appears; total latency is how long until the work is done. Users of a chat judge the first; users waiting on an agent task judge the second. Each has different causes and different fixes, so start from the target and the breakdown.

What drives each

ComponentAffectsMain levers
Processing a long input before generationTTFTCache the stable prefix; send less input
Thinking before the answerTTFT of visible textEffort level; skip thinking for simple requests; summarized thinking display
Generating outputTotal latencyShorter outputs where full length is not needed; faster model tier
Sequential model calls in an agent loopTotal latencyFewer turns; parallel tool calls; cached prefix on every call
Tool and retrieval timeTotal latencySpeed up, cache or parallelize the slow tool; rerank fewer candidates
Waiting to display until donePerceived TTFTStreaming

Streaming

Streaming shows text as it is generated. It fixes a product that waits for the full response before displaying anything: if the first token arrives in 1.1 seconds but the page shows nothing for 9, streaming meets a "first text in 1.5 seconds" target. It does not reduce total generation time, cost or content.

Parallel tool execution

When Claude requests several independent tools in one turn, run them concurrently in the harness and return all the results together in the next message. Executing three 1.2-second lookups one after another wastes the parallelism the model already offered. Asking Claude to call one tool per turn adds round trips.

Cache checkpoints

A long, reused prefix (a 120,000-token contract, a stable system prompt and tool list) is processed much faster when it is read from the cache. This cuts TTFT for follow-up questions and speeds every call in an agent loop that re-sends the same prefix. Streaming does not shorten that processing; caching does.

Effort and thinking

Effort sets how much reasoning the model does. The highest effort on simple requests (renaming a variable) can mean 25 seconds of thinking before any output. Lower effort for request types that evaluation shows do not need deep reasoning, and keep higher effort where it improves results. With thinking enabled, the first visible text arrives after the thinking, which is why a streamed interface can stay blank for seconds.

Model choice

Faster tiers usually return the first token sooner and generate faster. Route simple queries to a faster model where evaluation shows quality holds, keep complex ones on the current model, and measure latency per route. But measure per completed task: a faster model that causes more follow-up questions can make users' total time longer.

Designing to two targets

When a product has a first-response target (3 seconds) and a completion target (12 seconds), use different techniques for each: stream a short acknowledgment or plan quickly, then shorten the critical path with parallel tool calls and fewer turns.

In the exam

Latency items give a target and a breakdown. Decide whether the target is TTFT or total, find the largest component, and pick the technique that acts on it. Distractors stream to cut total time, cache to cut generation time, raise effort, disable thinking everywhere, move everything to the smallest model, or truncate output.

Check your understanding

Question 1

Agents request three independent lookups in one turn; the harness runs them one after another, 1.2 seconds each. Which change cuts latency?

Show answer

Answer: B. Concurrent execution cuts 3.6 seconds to about 1.2; the model already asked for the calls in parallel.

Question 2

A Q&A service sends a 120,000-token contract with every question; TTFT is 6 seconds against a 2-second target. Users ask several questions per contract. What helps most?

Show answer

Answer: C. TTFT here is input processing; a cached prefix skips most of it for later questions.

Question 3

Users say a chatbot "takes forever to start", but total latency meets its target. What should the team add?

Show answer

Answer: A. A slow start with acceptable total time shows up only in time to first token.

Apply it: Meet Granite's chat latency target

Exercise · about 25 minCase: Granite Federal Bank

Granite's chat assistant has a p95 time to first token of 1.9 seconds against a 1.5-second target. Each request sends a 7,000-token system prompt and tools (cached on only 30% of requests because a timestamp sits at the top of the system prompt), then calls get_accounts and get_recent_transactions, which the harness runs one after the other (0.5 seconds each), before answering. All requests use a Tier L model at high effort.

  1. Decide which parts of the request contribute to TTFT, and in what order they happen.
  2. Propose changes, each tied to a component.
  3. Say which change you would test first and why.
  4. Define how you will measure success without hurting quality.
Check your work
Show model answer

1. Path to first text. Input processing of the 7,000-token prefix (mostly uncached), the first model turn (thinking at high effort, then the two tool requests), the tool calls (1.0 seconds sequentially), then the second turn's processing and thinking before the first visible token.

2. Changes.

  • Move the timestamp after the cache breakpoint, so the prefix is cached on nearly every request (input processing).
  • Run the two tool calls concurrently (1.0 seconds becomes about 0.5).
  • Lower effort for balance and transaction questions, which evaluation shows do not need deep reasoning (thinking time).
  • Stream the answer, if not already, so the first text appears as soon as it is generated.
  • Evaluate a Tier M model for simple balance questions, routed by intent.

3. First test. The timestamp move: it is a one-line change with no quality risk, and it shortens input processing on every request.

4. Measurement. p95 TTFT and total latency per intent, before and after each change separately; the quality SLI (sampled rubric pass rate) and containment per intent must stay within their bands; a model-tier change ships only if quality holds on its route.

Key termsEffortLatencyStreamingTool use

Sources