AI Engineering

Reducing LLM Latency With Streaming and Batching Today

Cut LLM latency through streaming, batching, and speculative steps. Practical AI engineering techniques that make responses feel faster without swapping models.

By Laxaar Engineering Team Nov 29, 2026 9 min read
Reducing LLM Latency With Streaming and Batching Today

Slow LLM responses kill user trust faster than almost any other product flaw. A user who waits four seconds for a chatbot reply before seeing the first word will hit refresh, close the tab, or decide the product is broken. The frustrating truth is that most LLM latency problems aren't solved by switching to a faster model — they're solved by changing how your application requests, streams, and batches responses in the first place.

Perceived latency and actual latency are two different engineering targets. Actual latency is the wall-clock time from request to complete response. Perceived latency is what users feel, which is heavily shaped by when the first token arrives and how fluidly content renders. You can cut perceived latency by 60-70% on the same model, the same infrastructure, just by streaming tokens rather than waiting for the full response. That's an architecture decision, not a model decision.

At Laxaar, we've run into this pattern on nearly every AI product we've shipped. Teams over-invest in model selection and under-invest in the request pipeline around the model. This post covers the concrete techniques that move the needle on LLM latency today.

What you'll learn

Why time-to-first-token matters more than total latency

Time-to-first-token (TTFT) is the gap between sending a request and receiving the first chunk of the response. It's the single most important latency metric for interactive AI applications because it determines when the user sees anything. Generation time per token matters too, but users tolerate steady streaming far better than a blank loading state followed by a wall of text.

TTFT is largely determined by prompt length and model prefill speed. The model must process every token in your input before generating the first output token. A system prompt that's 3,000 tokens long adds measurable prefill time on every single request. That cost compounds in multi-turn conversations where context grows with each exchange.

The practical fix: keep system prompts tight, use prompt caching to amortize repeated prefix costs, and stream the response as soon as the first token is ready. Don't wait for the full completion.

How streaming responses work and when to use them

Streaming is a technique where the server sends tokens to the client incrementally as they're generated rather than buffering the full response. Most LLM APIs support server-sent events (SSE) or chunked HTTP transfer for this purpose.

Here's a minimal streaming call using the OpenAI SDK in TypeScript:

import OpenAI from 'openai';

const client = new OpenAI();

async function streamCompletion(prompt: string) {
  const stream = await client.chat.completions.create({
    model: 'gpt-4o',
    messages: [{ role: 'user', content: prompt }],
    stream: true,
  });

  for await (const chunk of stream) {
    const delta = chunk.choices[0]?.delta?.content ?? '';
    process.stdout.write(delta);
  }
}

The key detail: stream: true changes the response from a single JSON blob to an async iterable of partial tokens. Your UI can start rendering immediately.

Streaming helps most for: chat interfaces, document generation, any feature where users read content as it arrives. It helps least for: batch processing pipelines where downstream code needs the complete response before doing anything, structured-output extraction where partial JSON is useless, and function-calling flows where the tool arguments must be complete before dispatch.

Don't stream blindly. Streaming adds connection overhead and complicates error handling. If your use case is programmatic (extract JSON, classify text, route a request), waiting for the full completion is cleaner and often faster end-to-end because you avoid partial-response parsing logic.

Batching strategies for throughput-heavy workloads

Batching is the opposite of streaming — it's about grouping multiple requests together so the GPU processes them in parallel. A single A100 GPU running a 70B model can often handle 8-16 concurrent requests at similar per-token latency to a single request, because the bottleneck is memory bandwidth, not compute.

For background jobs (document summarization pipelines, nightly report generation, embedding ingestion), batching is the right default. Most managed APIs like OpenAI's Batch API offer 50% cost reductions in exchange for up to 24-hour turnaround, which is a good trade for offline workloads.

For self-hosted models, continuous batching (also called in-flight batching) is the technique used by inference servers like vLLM. Requests that arrive mid-generation get slotted into the current batch rather than waiting for a new batch cycle. This keeps GPU utilization high without increasing per-request latency for interactive traffic.

The trade-off: large batches improve throughput but increase queuing latency for individual requests. If you're mixing interactive and batch workloads on the same infrastructure, use separate queues with priority routing rather than one shared pool.

Speculative decoding and parallel prefill tricks

Speculative decoding is a technique where a smaller "draft" model generates several tokens ahead and a larger "verifier" model accepts or rejects them in parallel. When the draft model's guesses are correct (which happens roughly 70-80% of the time for common phrases), the verifier processes multiple tokens in a single forward pass, effectively multiplying throughput.

This is an infrastructure-level optimization you'll encounter in managed inference providers and in frameworks like vLLM and TensorRT-LLM. You don't implement it yourself — but you should ask your inference provider whether it's enabled, because the speedup for generation-heavy tasks can reach 2-3x with no prompt changes.

Parallel prefill is a related trick for multi-document contexts. Instead of stuffing all documents into one sequential prompt, you can prefill document embeddings or KV-cache entries in parallel. This is largely provider-managed but worth knowing when evaluating hosted inference options for RAG workloads.

Context trimming as a latency lever

Every token in your prompt costs prefill time. Most production prompts carry more context than necessary.

Common culprits:

  • System prompts with verbose instructions that could be tightened to a third of their length
  • Full conversation histories when only the last 3-4 turns are relevant
  • Retrieved RAG chunks that include boilerplate text around the relevant passage
  • Tool schemas with long descriptions when the model already knows the tool well

A structured approach to context trimming: profile your average prompt length per request, identify the top contributing sections, and run ablation tests to see how much context you can remove before output quality degrades. Teams at Laxaar typically find 30-40% of prompt tokens are removable without measurable quality loss.

One concrete technique: use summarization to compress older conversation turns. Keep recent turns verbatim, replace older turns with a single summary paragraph. This caps context growth in long-running sessions.

def trim_conversation(messages: list[dict], max_recent: int = 4) -> list[dict]:
    system = [m for m in messages if m['role'] == 'system']
    turns = [m for m in messages if m['role'] != 'system']

    if len(turns) <= max_recent:
        return messages

    older = turns[:-max_recent]
    recent = turns[-max_recent:]

    # summarize older turns (call a cheap small model here)
    summary_text = summarize_turns(older)
    summary_msg = {'role': 'system', 'content': f'Earlier conversation summary: {summary_text}'}

    return system + [summary_msg] + recent

This pattern keeps TTFT stable as conversations grow, rather than letting it balloon linearly with turn count.

Caching: semantic and prefix-based

Caching is the highest-leverage latency reduction for repeated or similar requests. Two types matter in AI engineering:

Prefix caching stores the computed KV-cache state for a repeated prompt prefix so the model doesn't re-process it on every request. OpenAI's API applies this automatically for prompts sharing a common prefix of 1,024 tokens or more. Anthropic's prompt caching feature is opt-in and explicit. For self-hosted models, vLLM implements prefix caching natively.

To benefit from prefix caching: always put your system prompt and any static context at the start of the prompt, and make sure it's byte-identical across requests. Even a timestamp injected into a system prompt breaks the cache.

Semantic caching stores full responses keyed by embedding similarity rather than exact match. A user asking "What's your return policy?" and another asking "How do returns work?" receive the same cached answer if their embeddings are close enough.

Semantic caching tools like GPTCache or custom Redis-with-pgvector setups reduce LLM calls for FAQ-style applications by 40-60% in practice. The trade-off: you need a similarity threshold, and a threshold set too loosely returns wrong answers for subtly different questions.

A comparison of latency reduction techniques

TechniqueLatency ImpactComplexityBest For
Streaming (SSE)TTFT cut 60-80%LowInteractive chat, document generation
Prefix cachingTTFT cut 30-50%Low (static prompts)High-traffic apps with shared context
Context trimmingTTFT cut 20-40%MediumLong conversations, large RAG chunks
Semantic cachingFull call avoidedMediumFAQ, repetitive queries
Continuous batchingThroughput 3-5xHigh (infra)Background pipelines, self-hosted models
Speculative decodingGeneration 2-3xHigh (infra)Self-hosted, generation-heavy tasks

Start from the top of that table. Streaming and prefix caching are free or near-free to implement and deliver the biggest perceived-latency gains for most applications. Infrastructure-level techniques like speculative decoding matter more once you're running your own inference stack.

Frequently Asked Questions

What's the difference between TTFT and generation latency?

TTFT (time-to-first-token) is the delay before the first output token arrives. Generation latency is the per-token speed after that. For interactive apps, TTFT dominates user perception because it's the blank-screen wait. Generation latency matters more for programmatic pipelines where the full response is consumed at once.

Does streaming increase infrastructure costs?

Streaming maintains an open HTTP connection per request for longer than a non-streaming request, which can increase connection load on your API gateway and backend. For most apps the overhead is negligible. At high request volumes (thousands per second), you'll want persistent connections or HTTP/2 multiplexing to avoid connection-count limits. Streaming doesn't increase LLM token costs.

When should we use batching instead of streaming?

Use batching when requests don't have a human waiting on the result in real time: background summarization, scheduled report generation, offline embedding ingestion, data labeling pipelines. Streaming is for anything with a user in the loop. Mixing both in the same queue reduces priority for interactive requests, so separate them.

How do we know if our prompt is too long?

Track p95 TTFT per endpoint and correlate it with average input token count. If TTFT scales linearly with token count and your p95 is above one second for interactive flows, your prompt is likely a primary cause. Profile which sections contribute most tokens, then ablation-test removals against output quality benchmarks before deploying cuts.

Is semantic caching safe for accuracy-sensitive applications?

It depends on the similarity threshold and domain. For high-variance domains (legal, medical, financial), semantic caching is risky because subtly different questions can have materially different correct answers. For FAQ-style, product-support, or instructional content with stable answers, it's safe with a tight cosine similarity threshold (0.95 or above) and a periodic invalidation schedule.

Does model size affect which latency technique to prioritize?

Yes. For large models (70B+), generation latency per token is the dominant cost, so speculative decoding and continuous batching help most. For mid-size models (7B-13B), TTFT from long prompts is often the bottleneck, so prefix caching and context trimming win. Streaming benefits all model sizes for interactive applications.


Latency in AI products is an architecture problem before it's a hardware problem. Streaming gets you perceived speed gains immediately. Prefix caching and context trimming reduce the real prefill cost that dominates TTFT. Batching and speculative decoding improve throughput at the infrastructure layer. The teams we work with at Laxaar that apply these techniques systematically ship products that feel fast even on mid-tier hosted models, which is a meaningful competitive edge.

If you're building an AI product and want a second opinion on your request pipeline, our AI engineering team reviews production architectures regularly. You can also explore our custom software development services for end-to-end AI product builds, or get in touch directly to discuss your specific latency targets.

Working on something like this?

Get a fixed scope, timeline, and price within one business day — no obligation.

LLM LatencyStreaming ResponsesAI Infrastructure
Grow your business with us

Take your business to the next level.

Tell us what you're building. We'll come back inside one business day with a fixed scope, timeline, and team — or an honest “this isn't a fit”.

ENGINEERING PHILOSOPHY

Code is useless if it's not comprehensible to those who maintain it. We write code the next person can actually understand.