Back to writing
ArchitectureAILatencyPerformanceScalability

Latency in AI: Speed Is an Architectural Decision

Wictor VargasWictor Vargas6 min

Latency in AI: speed is an architectural decision.

In the previous article, I wrote about security and why a prompt is not a guardrail.

Almost every layer I have discussed in recent months has something in common: routing, governance, validation, approval, observability.

They all add time.

And at some point, someone asks:

Why does the assistant take so long to answer?

Today I want to talk about that.

Because latency in AI is not solved by switching models.

It is solved by designing where every second goes.

The model is not the only culprit

When an AI system is slow, the first suspect is the model.

Sometimes it really is the biggest cost. But when I open traces from systems in production, the time is usually spread out:

  • Rewriting the question before searching
  • Generating the embedding
  • Searching the vector index
  • Reranking the results
  • Assembling a context that is too large
  • The model call
  • One or more tool calls
  • A second model call with the results
  • Validating the output

Each step looks small in isolation.

Added up and run in sequence, they become a wait of many seconds.

In an agent with several steps, that multiplies.

Latency is an experience, not a metric

Before optimizing, it is worth separating two different times:

  • Time to first response: how long the user waits until something happens
  • Time to complete response: how long the task takes to finish

For a conversation, the first matters more. An answer that starts quickly and finishes in eight seconds feels faster than one that appears all at once in five.

For batch processing, only the second matters. And often it does not even need to be fast.

You also need to look at the tail, not just the average. A system with a two-second average and a 99th percentile of thirty seconds has a problem that no average dashboard shows.

The right question is not "what is the latency?".

It is "what latency does this task need, and for whom?".

A time budget

The most useful tool I know for dealing with this is simple: a latency budget per task.

It works like a cost budget:

  1. Define the maximum acceptable time for the task
  2. Distribute that time across the steps
  3. Measure each step in the trace
  4. Treat a budget overrun as a defect, not a curiosity

With a budget, decisions become explicit.

If context retrieval takes half the time, maybe reranking does not fit. If validation adds two seconds, maybe it should run in parallel with streaming. If the agent can take ten steps, it needs a time limit, not just a step limit.

The architecture's levers

With the budget defined, there are a few levers that usually pay off more than switching models.

1. Streaming

Showing the answer while it is being generated changes the perception of speed.

But streaming requires decisions: what happens when validation rejects an answer that has already started to appear? For risky tasks, it may be better to stream progress through the steps instead of the final text.

2. Parallelism

Many steps are sequential out of habit, not necessity.

  • Searches across several sources can run at the same time
  • Independent tool calls can run in parallel
  • Classification and retrieval can happen together

The critical path of a task is rarely as long as the sum of its steps.

3. The right model for each step

This is where routing comes back into the conversation. Intermediate steps, such as rewriting a question or classifying an intent, rarely need the most capable model.

A smaller model in those steps saves both cost and time.

4. Smaller context

Large context costs processing time.

Retrieving fewer, more relevant chunks, and keeping the beginning of the prompt stable to take advantage of vendors' prompt caching, usually reduces latency and cost at the same time.

5. Work off the user's path

Not everything has to happen while the user waits.

Indexing, document enrichment, summaries, and evaluations can run before or after, asynchronously. Long tasks can become a background process with a notification when they finish.

Semantic caching: fast, but dangerous

One of the most cited techniques for reducing latency is semantic caching.

Instead of looking for an identical question, the system looks for a similar question that was already answered and returns the stored answer.

When it works, the answer comes back in milliseconds.

But it carries risks that almost nobody puts in the design:

  • Similar is not the same: "how do I cancel my plan" and "how do I cancel his plan" can sit close together in vector space
  • Stale answers: the policy changed, but the cache keeps returning the old version
  • Leaks between users: an answer containing one customer's data is returned to another

That last point connects directly to data governance. A cache is a copy, and copies have to respect permissions and lifecycle.

That is why semantic caching should only be used with clear rules:

  • Restricted to answers without personal data, or scoped per user
  • A high similarity threshold, evaluated with real cases
  • Expiration tied to the version of the knowledge base
  • A record in the trace that the answer came from the cache

Speed that delivers the wrong answer is not performance.

It is a fast defect.

Where to start

A pragmatic path:

  1. Measure each step in the trace, not just the whole request
  2. Define a latency budget per task, with time to first response and total time
  3. Look at percentiles, not just the average
  4. Turn on streaming in conversational interactions
  5. Parallelize what has no real dependency
  6. Use smaller models in intermediate steps
  7. Introduce caching with governance rules from day one

In many systems, these changes cut the wait in half without switching the main model.

Final reflection

It is easy to treat latency as an infrastructure problem, solved with more capacity or a faster model.

In AI, it is the result of many decisions: how much context to retrieve, how many steps to chain, what to validate, what to store, and what to wait for.

Each of those decisions trades time for quality, cost, or security.

Speed is not an attribute of the model.

It is the result of how the system was designed.

It is architecture.

Wictor Vargas
Written by Wictor Vargas

AI & Systems Architect. A new article every 15 days.

Enjoyed the article?Share it with someone taking AI to production.
Biweekly newsletter

Continue this reading in your inbox

Join the newsletter and receive new articles every 15 days on architecture, AI, governance, and the decisions that connect technology to business.

Read next