Zero Labs
Industry News / AI

What really happens when you click ‘Send’ on ChatGPT

Source · Towards AI By Rinit Jain

From the publisher’s feed, collected in the ZeroLabs newsroom.

A journey through modern AI Infrastructure — from one GPU to a Kubernetes clusterYou type a question into an AI application and press Send. A moment later, the response starts appearing. That interaction looks simple. The infrastructure behind it is not.TL;DRAn LLM is a large block of numbers that has to physically fit in GPU memory. Everything else follows from that.Your text becomes tokens, and tokens — not messages — are what the infrastructure schedules, caches and bills.A request runs in two phases with completely different hardware behaviour: prefill (reads the prompt, compute-heavy) and decode (generates one token at a time, memory-bandwidth-heavy).One GPU serves many users through batching. The limit is usually not compute, it’s the KV cache consuming VRAM.When a model is too big for one GPU it gets sharded; when traffic is too high it gets replicated. These are different problems.Because requests cost wildly different amounts, normal load balancing breaks and you need LLM-aware routing.Once there are hundreds of GPUs, Kubernetes operates the fleet.A single request can pass through an API gateway, a load balancer, a model server, an inference engine, a GPU scheduler, several layers of memory and — at scale — a Kubernetes cluster containing hundreds or thousands of GPUs.The AI InfrastructureThe interesting part is that every layer exists for a reason.A model needs memory.A GPU needs work.Many users need to share the same GPU.Large models need multiple GPUs.Multiple model instances need intelligent routing.And once there are hundreds of machines, something has to operate the whole fleet.This article builds that stack from the bottom up, starting with one model and one GPU, and gradually turning it into a production LLM platform.The Stack at a GlanceBefore diving in, here is the system we are going to build:User → API → Load Balancer → Model Server → Inference Engine → GPU → Prefill → KV Cache → Decode → Tokens back to UserAt larger scale, that becomes:User → Gateway → LLM-aware Router → Kubernetes → Model Server Fleet → GPU ClusterThe rest of the article is essentially an explanation of every box in those two lines.1. Start With the ModelAn LLM is not a magical object living somewhere in the cloud.At its core, it is a neural network architecture together with a very large collection of learned numerical parameters called weights.A model might contain 7 billion, 13 billion, 70 billion, or hundreds of billions of parameters.A useful first approximation is:Model weight memory ≈ Number of parameters × Bytes per parameterFor example, a 70-billion-parameter model represented using 16-bit values requires roughly:70 billion × 2 bytes ≈ 140 GBThat number immediately creates a problem.A model this large cannot simply be loaded into the VRAM of a small GPU.And this is where the physical infrastructure starts to matter.2. CPU, RAM, GPU and VRAMA server running an LLM usually contains both a CPU and one or more GPUs. They are optimized for very different kinds of work.CPUThe CPU is the general-purpose processor.It handles tasks such as:network communicationtokenizationrequest processingschedulingapplication logicoperating-system taskscoordination between different componentsRAMRAM is the machine’s main memory.It is used by the operating system and applications and can hold model files, request data, buffers, and other runtime state.GPUThe GPU is the accelerator that performs the majority of the neural-network computation.LLMs perform enormous numbers of operations such as matrix multiplications. These operations contain large amounts of parallel work, which GPUs are designed to exploit.VRAMThe GPU has its own high-bandwidth memory, commonly called VRAM. (Video Random Access Memory) (on datacenter GPUs this is HBM — high-bandwidth memory — stacked next to the die).This is where the GPU keeps the data it needs to work on quickly, including:model weightsintermediate dataruntime buffersKV cacheA useful mental model is:RAM is the server’s main working memory. VRAM is the high-speed working memory directly attached to the GPU.They are not interchangeable.Having 256 GB of system RAM does not turn a 24 GB GPU into a 256 GB GPU.The Four Resources That MatterWhen evaluating infrastructure for LLM inference, four resource dimensions matter enormously:1. Compute capacityHow much arithmetic the accelerator can perform.2. Memory capacityHow much data can fit into GPU memory (VRAM).3. Memory bandwidthHow quickly data can move between GPU memory and the GPU’s compute units.4. Network bandwidthHow quickly data can move between GPUs or between machines.These are separate constraints.A GPU can have enormous compute capacity but still perform poorly if its memory cannot feed the compute units fast enough. Similarly, a model distributed across multiple GPUs can be limited by the communication between those GPUs, even when each individual GPU has sufficient compute and memory.Think of compute as the number of workers, memory capacity as the size of the workspace, memory bandwidth as how quickly materials reach those workers, and network bandwidth as how quickly different factories can exchange materials.For a single-GPU workload, the first three are particularly important. Once inference becomes distributed, communication bandwidth becomes another critical part of the performance equation.3. Getting the Model Onto the GPUA simplified path looks like this:Model Repository / Storage ↓ RAM ↓ GPU VRAM ↓ GPU ComputeThe model files may initially be stored on local SSDs, network storage, or an object store.When the inference server starts, the model is loaded into memory and eventually placed in the GPU’s working memory.Once loaded, the model can process requests.But the GPU still does not know what to do with a sentence such as:“Explain how a nuclear reactor works.”The text first has to become something the model understands.4. Text Becomes TokensLLMs do not directly operate on words.They operate on tokens.A tokenizer converts text into token IDs.For example, a sentence might conceptually become:"Explain how tokenization works" ↓["Explain", " how", " token", "ization", " works"] ↓[849, 1268, 4037, 2065, 4375]The exact tokenization depends on the model and tokenizer. A token is roughly ¾ of an English word on average, but that ratio collapses for code, JSON, and non-Latin scripts.Those IDs are then fed into the model.This distinction becomes important later because inference systems do not primarily reason about “messages”.They reason about tokens.Token count affects:computationmemory consumptionlatencyKV-cache usagethroughputcost5. The Model ServerNow we need a program that can accept requests and run the model.That program is the model server.A model server typically handles:Request ↓Tokenization ↓Scheduling ↓Model execution ↓Generated tokens ↓ResponseWithout a model server, every application would need to implement model loading, GPU execution, batching, request management, streaming, and concurrency itself.The model server turns the model into a service.For example:POST /generate{ "prompt": "Explain how a nuclear reactor works"}The server receives that request, executes the model and returns generated tokens.One important distinction:The model is the thing being executed. The model server is the software that manages that execution and exposes it as a service.6. Where Does vLLM Fit?Several inference engines exist today. vLLM is one of the most widely used open-source engines for serving LLMs, and it is designed around the realities of the workload: large models, many concurrent requests, expensive GPU memory, dynamic request lengths and heavy cache management.Its documented feature set includes PagedAttention, continuous batching, prefix caching, quantization and disaggregated prefill/decode — all of which we will touch on below.vLLM does not replace the GPU or the model. It is the inference engine that manages how requests use them.7. A Request Has Two Very Different PhasesOnce the request reaches the model server, inference is not simply prompt → answer. It runs in two phases, and understanding the difference is the single most important idea in LLM infrastructure.Prompt ↓PREFILL ↓First output token ↓DECODE ↓Next token ↓Next token ↓Next token ↓...Prefill processes the input tokens and builds the internal state needed for generation. Because all prompt tokens can be processed together, prefill exposes a lot of parallelism and tends to be compute-bound — it can saturate the GPU’s arithmetic units.Decode generates the answer one token at a time, and each new token depends on everything generated so far. There is very little parallel work per step, but the model’s weights must be read from VRAM on every single step. Decode is therefore memory-bandwidth-bound — the GPU spends most of its time waiting for data, not calculating.That one difference explains most of what follows: why batching works, why GPU utilisation is hard, why latency has two separate metrics, and eventually why some systems run prefill and decode on entirely different machines.Now attach a 10,000-token document to that same prompt. Prefill has 10,000 tokens to chew through before a single output token appears, while decode is unchanged. This is why a request with a 20,000-token prompt behaves nothing like a request with a 100-token prompt.9. Measuring the user experienceBecause the two phases are different, latency needs more than one number. Three metrics do most of the work:TTFT — Time To First Token How long the user waits before anything appears on screen. Driven by queueing and prefill.TPOT — Time Per Output Token The average time to produce each subsequent token. Driven by decode.ITL — Inter-Token Latency The delay between individual streamed tokens. Driven by decode and scheduling.Mapped onto the request:Request │ └────────────────┐ first token ↑ TTFT token → token → token → token ↑ TPOT / ITLA system can have a perfectly reasonable total completion time and still feel slow because TTFT is high. It can also produce the first token instantly and then stream the rest sluggishly. In production, both matter.10. Now add a second userSo far this has been easy: one user, one request. Production services have hundreds or thousands of requests in flight.We clearly do not want one GPU per user — that would require an absurd number of GPUs. Instead, a single model instance serves many users. The same weights stay loaded in VRAM while the inference engine continuously schedules work from multiple requests.This is batching. Instead of processing requests one at a time, the engine combines work from multiple sequences and executes it together, which suits a highly parallel device far better than feeding it one request’s worth of work.Modern engines go further with continuous batching: rather than forming a fixed batch and waiting for every request in it to finish, requests enter and leave the active workload dynamically.11. Batching creates a memory problemBatching improves GPU efficiency, but every active request consumes memory. The weights already occupy VRAM. Now every active sequence also needs runtime state — and the largest part of that state is the KV cache.Transformer attention produces queries, keys and values for each token. During generation, the keys and values from previous tokens get reused on every step, so instead of recomputing them the engine stores them. That stored state is the KV cache.Without it, generating each new token would mean reprocessing the entire context from scratch. With it, the system keeps the useful intermediate state and reuses it.12. Why the KV cache changes the memory equationModel weights are static. The KV cache is dynamic — it grows with the number of active users and with how long each of their contexts becomes.So VRAM has to accommodate something closer to:VRAM ≈ model weights + KV cache + runtime buffers + overheadThis produces an important consequence:A model can fit on a GPU and still not leave enough free memory to serve a realistic number of concurrent long-context requests.Capacity is not determined by model weights alone. This is also why memory allocation strategy matters: sequences have wildly different lengths, and reserving one large contiguous region per sequence wastes space. vLLM’s PagedAttention instead organises the KV cache into fixed-size blocks that can live anywhere in GPU memory, which removes most of that waste.The mechanics of KV cache growth, block management, eviction and PagedAttention get their own article — see Related reading.13. A second cache appears: prefix cachingImagine an application where every request begins with the same 8,000-token system prompt. Without any caching, the system performs the same prefill computation over and over.Prefix caching reuses the KV cache blocks already computed for a shared prefix:Request A: [Shared prefix][Question A] → computed and cachedRequest B: [Shared prefix][Question B] → reuses cached prefixThat removes a large amount of repeated prefill work. But it introduces a question that becomes central later: which server already holds the useful cached state?14. What if the model does not fit on one GPU?Back to the 70B model needing roughly 140 GB for its weights. A single 24 GB GPU cannot hold it. There are four responses:Quantization — represent the model with fewer bits (FP16 → INT8 → INT4). Fewer bits means less memory per parameter, at some cost to accuracy.A larger GPU — use an accelerator with enough VRAM.Offloading — keep some state in CPU memory and move it when needed. This makes otherwise impossible configurations fit, but data movement is slow relative to VRAM.Sharding — split the model across multiple GPUs.That last option opens up distributed inference, and there is more than one way to split a model:Tensor parallelism — splits the individual operations inside each layer across GPUs. Used when a model is too large for one GPU and the GPUs have a fast interconnect.Pipeline parallelism — splits the model by depth, giving each GPU a contiguous group of layers. Used when the model has to span multiple machines.Data parallelism — splits nothing. The model is replicated, and each copy handles different requests. Used for throughput, not capacity.Expert parallelism — distributes the experts of a Mixture-of-Experts model across GPUs. Only applies to MoE architectures.Context parallelism — distributes the context dimension itself. Used for very long context.The trade-off across all of them is the same: more GPUs reduce the memory burden per GPU, but the GPUs now have to communicate, and that communication becomes its own performance constraint.How each strategy actually works, and how to choose between them, is a full article of its own — see Related reading.15. Sharding vs replicationThese two are often confused. They solve different problems.Replication creates multiple complete copies of the model, each able to serve requests independently. It is a capacity and availability strategy.Sharding splits one model across multiple GPUs that together execute a single model instance. It is a model-size and execution strategy.Replication creates more copies. Sharding creates one distributed copy.16. One model becomes a fleetSuppose one model server handles 50 concurrent requests, and traffic rises. Now we deploy several: Load Balancer / | \ Server A Server B Server C | | | GPU(s) GPU(s) GPU(s)Each server holds its own copy of the weights. This buys throughput, redundancy, fault tolerance and headroom for traffic spikes — and raises a new question: which server should receive each request?17. Why traditional load balancing breaksA normal web service might use round robin: request 1 to A, request 2 to B, request 3 to C. That works when requests are broadly similar.LLM requests are not. Consider: Request A Request BInput tokens 500 20,000Output tokens 50 8,000Both count as “one request” to a normal load balancer. Their compute and memory requirements are nowhere close to equal.An LLM-aware router instead cares about active sequences, queue depth, token workload, GPU utilisation, KV cache occupancy, prefix-cache locality, model identity and available capacity. That is a fundamentally richer problem than counting HTTP connections.Prefix caching makes it richer still. If Server A already holds the cached prefix for a request while Server B merely has more free capacity, sending it to B throws away real work.The best server is not necessarily the one with the most spare compute. It may be the one that already has the right state.This is the idea behind LLM-aware routing systems such as LLM-D, a Kubernetes-native stack for distributed LLM inference. Rather than treating model servers as interchangeable HTTP backends, it makes routing decisions using inference-specific signals, and supports concepts like inference pools, cache-aware scheduling and prefill/decode disaggregation.Routing algorithms and LLM-D each get their own article — see Related reading.18. Kubernetes enters the pictureWe now have many models, many model servers, many GPUs, replicas, distributed shards, networking, health checks, autoscaling and failures. Managing that manually is impractical.Kubernetes is an orchestration system for running containerised workloads across a cluster of machines. It does not perform the neural network computation — it manages the infrastructure around it.Pods and nodes. A Pod is Kubernetes’ smallest deployable unit, containing one or more containers. For inference, a Pod typically runs a model-serving container such as vLLM, placed on a GPU node.Scheduling. Clusters contain a mix of CPU-only nodes, different GPU generations, and machines with different interconnects. GPUs are exposed to Kubernetes through vendor device plugins, so a Pod can request them as schedulable resources. For sharded inference, GPU topology matters as much as GPU count — four GPUs in one tightly connected server behave very differently from four GPUs scattered across machines.Self-healing. Pods are replaceable. A Deployment maintains a desired number of replicas, and if one dies Kubernetes creates a replacement, assuming the cluster has room. Because Pods come and go, clients talk to a Service, which provides a stable network endpoint over a changing set of Pods.Autoscaling — with a catch. Kubernetes can run more replicas as traffic grows. But creating an LLM-serving Pod means scheduling a GPU node, pulling a large container image, loading model files, and moving weights into VRAM. That can take minutes, not seconds. As a result LLM autoscaling cannot rely on CPU utilisation; useful signals include request queueing, token throughput, active sequences, latency and KV cache utilisation.Kubernetes for AI workloads is a full article on its own — see Related reading.19. The full requestWe can now follow one request end to end. The user sends:“Explain how nuclear reactor” — with a 10,000-token document attached.Step by step:The request arrives at the API gateway.Routing happens. The platform picks a model and a serving instance.Tokenization. The text becomes token IDs.The request enters the inference scheduler, which decides when this sequence gets GPU time.Prefill runs over the 10,000 prompt tokens.KV state is produced and stored in the cache.Decode begins and the first output token is generated.Decode continues, reusing the KV cache on every step.Other users run simultaneously, their work continuously batched alongside yours.Tokens stream back. Rather than waiting for the full answer, the server pushes each token to the client as it is produced — usually over a streaming HTTP connection such as server-sent events. That is why the response appears word by word instead of arriving all at once.20. The five layersIt helps to separate the stack into five layers, top to bottom:Application — chat app, API, authentication. What the user actually interacts with.Orchestration — Kubernetes, Pods, Services, autoscaling. Operates the fleet.Distributed inference — sharding, replicas, inter-GPU communication, routing. Determines how the model is spread and how requests are distributed.Inference — model server, scheduler, batching, prefill/decode, KV cache. Determines how requests use the hardware.Hardware — CPU, RAM, GPU, VRAM, network. Provides the physical resources.The platform is the combination of all five.21. A debugging frameworkReturn to the four resources from Section 3. When an LLM deployment is slow, the useful question is: which resource is actually limiting it?If GPU memory is full, adding CPU cores will not help.If GPU compute is saturated, enlarging the KV cache will not help.If distributed workers spend their time waiting on each other, adding more compute just creates more communication.If decode feels slow while prefill is fine, look at memory bandwidth, not FLOPs.Optimization starts by identifying the actual bottleneck, not by adding hardware.22. Revision: How One Request Became an Infrastructure StackWe started with:“Explain how a nuclear reactor works.”That innocent sentence led us through:Text ↓Tokens ↓API ↓Model Server ↓vLLM ↓Scheduler ↓Prefill ↓KV Cache ↓Decode ↓Batching ↓GPUThen one GPU became insufficient:One GPU ↓Sharding ↓Multiple GPUsThen one model server became insufficient:One Replica ↓Multiple Replicas ↓Load BalancingThen normal load balancing became insufficient:Load Balancing ↓Cache-aware / LLM-aware Routing ↓LLM-DAnd finally, the number of machines became large enough that we needed a system to operate them:Many GPU Nodes ↓ Kubernetes ↓Pods + Services + Scheduling ↓Autoscaling + Networking + RecoveryThat is modern LLM infrastructure.Kubernetes based LLM Inference StackA ProblemThe architecture now looks complete. The model is in VRAM, the engine schedules requests, prefill reads the prompt, decode generates tokens, the KV cache holds useful state, batching shares the GPU, and Kubernetes manages the fleet.But we have conveniently avoided one thing: what happens when the model genuinely cannot fit on a single GPU?A model may need hundreds of gigabytes while an individual GPU has far less. Even when it does fit, serving many users may require more GPUs than one machine provides.So a choice has to be made. Do we make the model smaller? Split it across GPUs? Replicate it? And if we split it, how do those GPUs cooperate without spending all their time talking to each other?That is the next layer of the stack: quantization, sharding, replication and parallelism.The series1. What really happens when you click ‘Send’ on ChatGPT — A journey through modern AI Infrastructure2. What Do You Do With a Model That’s Too Big for Your GPU? — Quantization, Sharding and Parallelism Explained (Next Article)3. How Does One GPU Serve Hundreds of Users at the Same Time? — Inside an LLM inference server4. The KV Cache Explained: Why Long Conversations Get Expensive — How LLMs remember context without recomputing everything5. Why Is Your LLM Recomputing the Same Prompt 1,000 Times a Day? — Prefix caching, radix trees and block hashing explained6. Why Traditional Load Balancing Breaks for LLMs — Building an LLM-aware router7. Kubernetes for LLM Inference: How AI Workloads Run Across a GPU Cluster8. LLM-D Explained — How modern AI infrastructure routes, schedules and scales LLM inference9. Inside a Modern AI Inference Platform — The full stack end-to-endSourcesvLLM documentationNVIDIA — Mastering LLM Techniques: Inference OptimizationKubernetes — Schedule GPUsLLM-D documentationWhat really happens when you click ‘Send’ on ChatGPT was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.