Skip to content
AI

AI System Design Starts With the Request, Not the Model

AI system design connects model serving, retrieval, safety and cost; I explain the request path and the production checks I would prioritize before scaling.

Topic
AI
Reading time
8 min
Length
1,854 words
Published
Nov 11, 2026
01:47 pm IST
In this article
  1. What does an AI system actually need?
  2. Measure the first token separately from the finished answer
  3. Prefill, decode and the memory behind every conversation
  4. How does PagedAttention improve LLM serving?
  5. Continuous batching solves a different waste problem
  6. Planning capacity for an existing AI application
  7. Better GPU utilization does not establish answer quality

AI system design is the architecture around an AI model: how requests enter, retrieve context, generate answers, pass safety checks and stay within budget. For a production app, I'd treat the model as one component. Not the whole system. Caching, routing and inference scheduling can matter just as much as which model I pick.

I find it more useful to ask what happens to each request than to start by asking which model to use. A request-by-request architecture connects those application decisions to the serving machinery underneath. That's where I'd start, rather than drawing a model box between a frontend and a database and treating the diagram as the design.

What does an AI system actually need?

A generative AI request typically crosses an entry gateway, input checks, a cache, model routing, context assembly, inference and output checks before it reaches the user. Tracing and evaluation run across that whole path. I'd account for each responsibility, but I wouldn't assume each one needs a separate service to deploy.

The gateway authenticates the caller, applies rate limits and records the request. Those limits need to account for tokens, because requests are not equal pieces of work: a short answer and a long document response do not consume equivalent resources. Input guardrails check for sensitive data, abuse and obvious attempts at prompt injection.

A response cache can skip generation if a sufficiently similar question already has an answer. A router can send easier work to a smaller model and harder work to a larger one. Context assembly retrieves the relevant material. An agentic workflow may then call tools repeatedly before it has an answer to return.

For the newsroom features I work on, I'd draw a clear boundary between context assembly and generation. An editorial summary and an intelligent-search answer deserve separate evaluation sets in my design, even if they share a model at first. When something fails, I want to distinguish missing material from poor generation or an unsuitable route. Otherwise, what exactly am I fixing?

Predictive systems put the emphasis elsewhere. With scoring and classification, feature pipelines, training and model registries come into focus. I'm concentrating here on generative applications, where token generation, retrieval and inference capacity drive many of the architecture decisions. That's the request path I want to work through.

Measure the first token separately from the finished answer

The familiar web-system components still have a place: queues, databases, load balancers and caches remain useful. The shape of the work changes, though. An LLM generates its output token by token. Put all of that behind a single response-time measurement and some important distinctions disappear.

Time to first token measures how long the user waits before any output begins. Time per output token measures the pace once it starts. Throughput measures the total tokens generated across users, while cost per request connects input and output tokens to their respective prices. I'd want all of those measurements, not just one.

I'd also keep them separate. A system that starts quickly but streams painfully slowly has a different problem from one that waits before producing a fluent response. A healthy aggregate throughput number doesn't establish that an individual request feels responsive, either. I wouldn't use it as a substitute for that measurement.

The trade-off is real. Packing more requests onto a GPU can improve throughput and lower cost while making an individual response slower. I'd choose an acceptable user experience first, then optimize capacity inside that boundary. A throughput graph alone isn't something I'd celebrate if the response has become unpleasant to wait for.

Prefill, decode and the memory behind every conversation

Inference has distinct phases, and I'd keep those separate in the design discussion too. During prefill, the model processes the prompt tokens together. This phase is compute-bound and contributes to the wait for the first token. During decode, output is generated sequentially, and memory bandwidth becomes a central constraint.

The KV cache stores attention keys and values for earlier tokens, so the model doesn't have to recompute them at every generation step. That speeds up generation. It also occupies GPU memory and grows with the conversation. Accepting a larger prompt is therefore only part of the story: long context has a serving cost as well.

The architecture-based calculations put Llama 3.1 8B at 128 KB of KV cache per token using 16-bit numbers, or approximately 0.5 GB for a 4,000-token conversation. I'd treat these as estimates derived from the architecture, not as a promise about how much capacity a deployed server will actually have.

Before discussing hardware, I'd use a small calculation to make the reservation assumptions visible. This Python arithmetic compares a reserved 32,000-token allowance with the cache occupied by a 4,000-token conversation. It uses the same per-token estimate above, so the comparison stays focused on the reservation rather than changing the assumptions halfway through:

kv_kb_per_token = 128
conversation_tokens = 4000
reserved_tokens = 32000

conversation_kv_kb = kv_kb_per_token * conversation_tokens
reserved_kv_kb = kv_kb_per_token * reserved_tokens
reservation_multiple = reserved_kv_kb / conversation_kv_kb

The reservation multiple is eight. That's useful for a capacity-review illustration, but I wouldn't turn this arithmetic into an admission controller. It leaves out model weights, working memory and serving overhead. The point is narrower: make the cost of reserving context that isn't being used visible before deciding what hardware is needed.

How does PagedAttention improve LLM serving?

PagedAttention tackles KV-cache allocation. A sequence's cache no longer has to occupy one contiguous region of memory; instead, the cache is partitioned into blocks. A block table maps logical blocks to physical blocks. Physical memory is then allocated as generation grows, rather than requiring that contiguous region for the sequence.

In vLLM's original serving experiments, existing systems wasted 60%–80% of memory through fragmentation and over-reservation. PagedAttention brought that waste below 4%. With less memory wasted, more sequences could be batched together. That's the connection I care about here: allocation affects how much work fits in memory.

The throughput improvement in those experiments reached up to 24 times that of HuggingFace Transformers. I wouldn't put that multiplier into a production budget. It's an experimental result from particular LLaMA models, GPUs and request lengths sampled from ShareGPT. My workload would still need its own comparison before I'd use that result for planning.

PagedAttention also supports sharing prompt blocks between output sequences, using reference counting and copy-on-write. That matters when a workflow generates several alternatives from the same prompt. I'd investigate it if the product genuinely needs those alternatives. I wouldn't add sampling complexity just to give a serving optimization something to optimize.

Continuous batching solves a different waste problem

Memory allocation and request scheduling are related, but they aren't the same problem. Static batching keeps a group together until its requests finish. If short responses finish before a long one, their slots can sit idle. Continuous batching admits waiting requests into those freed slots at generation steps instead of leaving them unused.

I'd be quite explicit about that distinction in an infrastructure review. PagedAttention reduces allocation waste. Continuous batching reduces idle capacity caused by uneven completion lengths. Those are different sources of waste, and neither technique removes the underlying work of generating the answer. I'd want the discussion to stay clear about which one we're measuring.

The architecture guide's simulation illustrates this scheduling effect, but it remains a simulation with a fixed decode-step duration. I wouldn't carry its throughput increase straight into a GPU purchase decision. For my benchmark, I'd preserve the mixture of short and long responses expected in the application rather than treating the simulated increase as the answer.

Planning capacity for an existing AI application

I'd start with a request inventory, not an inference-server migration. For each user-facing operation, I'd record the context it needs, whether it calls tools and what counts as a usable answer. This is where I'd separate an editorial summary from an open-ended assistant conversation, before deciding whether they need the same infrastructure changes.

  • Trace the entire request. I'd record time spent waiting, retrieving context and generating output, alongside token usage and cost. The first job is to locate the delay. I'd rather do that than choose an optimization and then look for somewhere to apply it.
  • Build a representative evaluation set. I'd include ordinary requests as well as difficult cases, then judge quality alongside latency. A cheaper route would have to preserve the behavior the feature promises; a lower cost alone wouldn't meet that requirement for me.
  • Test serving changes against the same workload. I'd compare first-token latency, streaming pace and throughput while keeping the request mix consistent. I want the serving change to be what I'm comparing, not a different mixture of requests.
  • Define fallback behavior. I'd decide which features can return a simpler answer and which should fail clearly when their required context or model is unavailable. I wouldn't leave that choice implicit in the capacity plan.

For retrieval-heavy features, I'd look at the retrieved material before changing model capacity. My interest in vector-search index builds is separate from inference scheduling. Before blaming generation, I'd want evidence that the relevant documents actually reached the prompt. That's the boundary I'd check first when context appears to be the problem.

I'd introduce model routing cautiously, too. My preference for selective agent upgrades follows the same principle: change the workloads that benefit. I wouldn't move everything just because an aggregate result looks attractive. I'd want the decision tied to the work being routed, rather than to the appeal of the aggregate number.

Better GPU utilization does not establish answer quality

PagedAttention doesn't check whether an answer is correct. Continuous batching doesn't determine whether retrieved material belongs in the response. Prompt injection remains an attack surface as well: instructions hidden in retrieved documents or web pages can attempt to redirect the model. None of those questions is answered by a better GPU-utilization result.

I'd keep my safety review separate from my capacity review. I'd test what happens when retrieved text contains instructions, when private material enters context and when the response has to follow a required format. Input and output checks belong in the design. Their presence, though, isn't something I'd accept as proof of safety.

Streaming needs an explicit product decision too. If a feature requires the complete answer to be checked before anyone sees it, I'd accept buffering rather than promise immediate display. For lower-risk output, I'd evaluate incremental delivery separately. What worries me is a checking policy that doesn't agree with what the interface promises the user.

If a hosted model API already meets the application's needs, I'd leave GPU scheduling with the provider. I'd still measure request latency, token cost and answer quality; leaving scheduling elsewhere doesn't change what I want to measure. Self-hosting would enter my plan only when workload evidence and operational requirements justify owning that additional layer.

I'd start by tracing the request path, making its budgets explicit and building an evaluation set. Then I'd use that diagnosis to choose the work: retrieval when context is wrong, routing when expensive generation is unnecessary, serving when inference is the measured bottleneck. Before adding GPUs, I'd identify which of those problems the request trace actually shows.

Sources

https://bytemuni.com/artificial-intelligence-machine-learning/llms-generative-ai/ai-system-design-guide/

This is the source this article is based on. Many articles on this blog are drafted with AI and checked against their source automatically; the editorial policy explains how, and how to report a mistake.

Frequently asked

Do I need to self-host a model to apply AI system design?

No. Gateways, token-aware limits, retrieval, caching, routing, guardrails and evaluation remain relevant around a hosted model. I'd consider self-hosting only when measured requirements justify taking responsibility for inference infrastructure.

What is the difference between a response cache and a KV cache?

A response cache stores answers that can be reused without generating them again. A KV cache stores attention keys and values for earlier tokens during generation. They save different kinds of work.

Does vLLM guarantee 24 times higher throughput?

No. Up to 24 times higher throughput was reported against HuggingFace Transformers in vLLM's original experiments with specific models, hardware and request distributions. I'd benchmark the intended workload rather than assume that result transfers.

Should I prioritize RAG or inference optimization?

I'd start with the measured failure. If relevant material is missing from the prompt, I'd investigate retrieval and context assembly. If generation is the bottleneck, I'd investigate inference capacity, memory use and scheduling.

Deepak Kumar

Written by

Deepak Kumar

Sr Software Engineer at India Today Group | Aaj Tak · MERN Stack · Generative AI

I build LLM systems in production — retrieval, evaluation harnesses and guardrails, plus the unattended agent pipelines that write this blog and my books. I write here about what those systems actually do once real traffic hits them. Hiring an LLM engineer in India? Here is how I work.

Weekly newsletter

Liked this? Get the next one by email

One short email a week with new articles on React, Node.js, TypeScript and AI engineering. No spam. Unsubscribe in one click.

By subscribing you agree to the privacy policy · About the newsletter.

Further reading

Related tutorials from ByteMuni, my developer publication.

Message me