# What happens after you hit send

Alfonso Campodonico · 2026-10-19 · https://alfonsocampodonico.com/posts/what-happens-after-you-hit-send

> One chat prompt, followed from your computer to a GPU cluster and back.

## Why follow one request

You type a question into a chatbot, and an answer starts arriving a few hundred milliseconds later. This post follows that one request through the stack, from the infrastructure most people never see to the token-by-token prediction at the end.

People keep asking me how chatbots "work". Most explainers start at the transformer and skip everything before it. That skipped half is the part I run for a living, so I wanted one picture with both.

The short version: the network is fast and boring. Almost all the time goes into one loop on the GPUs: run the model once, get one token, append it, run it again. Batching and the KV cache make that loop affordable, and they're where the infrastructure and the model meet.

## How it works, in one minute

Your question makes two trips: one through ordinary infrastructure, and one through the model.

1. **Out to the edge.** Your computer sends the question over HTTPS. The edge ends the encryption, filters bad traffic and picks a healthy server.
2. **Through the API.** A gateway checks your key and your quota, a safety check reads the question, and a router picks a GPU cluster.
3. **Into numbers.** The model splits your text into tokens, gives each one an ID, and looks each ID up as a vector of a few thousand numbers.
4. **Up through the layers.** The vectors rise through dozens of layers. Each token reads the ones before it, and its meaning sharpens on the way up.
5. **One token at a time.** At the top, the model scores every possible next token and picks one. It appends it and runs again, reusing what it already worked out.
6. **Straight back.** Each token streams to your screen the moment it exists, so the answer appears word by word.

That's the whole trip, in about 110 seconds:

<div class="mt-8 aspect-video overflow-hidden rounded-2xl bg-black shadow-xl">
<iframe src="https://www.youtube-nocookie.com/embed/0YdR5XOBVKY" title="How AI chat works." class="size-full" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
</div>

## The deep dive

The rest of this post takes the trip again, one stop at a time. Each stop has a console you can type into.

The example throughout: "Why is the sky blue?", answered with "Sunlight scatters off…". The stack is generic. Every provider builds its own, and I'll say where they differ.

*Interactive diagram on the page: One message, from send to stream.*

## The question: your computer, a chat box, HTTPS out

The chat box wraps your message, and the conversation so far, in a small JSON body. It POSTs it over HTTPS and asks for a stream back:

```sh
curl -N https://api.example.com/v1/chat \
  -H "Authorization: Bearer $API_KEY" \
  -H "Accept: text/event-stream" \
  -H "Content-Type: application/json" \
  -d '{"stream": true, "messages": [{"role": "user", "content": "Why is the sky blue?"}]}'
```

The request is a few hundred bytes. The connection stays open, because the answer won't arrive in one piece.

## The edge: TLS ends, most bad traffic stops

DNS or anycast sends you to a point of presence near you. Three things happen there:

- **TLS termination.** The encrypted connection ends at the edge. The hop to the origin is usually re-encrypted on a separate connection.
- **WAF and CDN.** Malformed requests get dropped, per-IP rate limits apply and bot checks run. This is cheap filtering, done before anything expensive sees the request.
- **Load balancer.** It picks a backend that's passing health checks and pins the long-lived connection to it.

None of this is specific to AI. It's the same edge any busy API sits behind.

## The API layer: who you are and where you go

- **Gateway.** It authenticates the key or session and checks org quotas and rate limits. Those limits are often counted in tokens, not requests, because a token is the unit of cost.
- **Safety classifiers.** Smaller models screen the input before the big one sees it. Whether this happens, and what runs, varies by provider. Some also screen the output as it streams.
- **Router.** It picks a model pool and a region, based on the model you asked for and the spare capacity. Some routers also prefer a replica that has recently seen the same prompt prefix, so they can reuse its cache.

*Interactive diagram on the page: The request, hop by hop.*

## The GPU cluster: N GPUs holding one model

The model runs on a Kubernetes GPU node pool. Each node has a handful of GPUs linked by NVLink, most often 8, and an inference server pod[^servers] asks for the N it needs, for example with `nvidia.com/gpu: 8`.

A large model doesn't fit comfortably on one GPU. A 70-billion-parameter model at 16 bits is about 140 GB of weights. Data-centre GPUs have from 80 GB (an H100) to 288 GB (a B300 or an MI355X). On the smallest the weights don't fit at all. On the largest they fit, but one GPU's memory bandwidth then sets how fast every token comes out. Bigger models don't fit anywhere. So the weights are sharded across N GPUs with tensor parallelism: every weight matrix is split N ways, each GPU computes its slice, and the slices are combined with an all-reduce after each block. Each GPU reads only its slice, so every token gets N GPUs' worth of memory bandwidth. That all-reduce happens many times per token, which is why tensor parallelism stays inside one node, on NVLink. A model too big for one node is also split by layers across nodes (pipeline parallelism).

Starting a replica takes minutes, not seconds: 140 GB of weights has to come off object storage onto the GPUs, and the server warms up before it takes traffic. You don't scale this from zero when a request arrives. Capacity is warm and waiting.

The inference server doesn't run your request alone. It uses continuous batching: at every step, the scheduler adds new requests to the running batch and removes finished ones. Your prompt joins a batch that's already generating text for other people.

If you run Kubernetes for a living, this part looks familiar: a node pool, a device plugin, pods that ask for whole devices. What's different is the size of one pod. It holds N GPUs and well over a hundred gigabytes of weights, so you plan capacity ahead instead of autoscaling on demand.

*Interactive diagram on the page: Sharding the model across GPUs.*

## Tokenize: text becomes integers

The model never sees text. First the server applies a chat template: it wraps the system prompt, the history and your message in special tokens that mark who said what. The template is different for every model family.

Then a tokenizer splits the text into pieces from a fixed vocabulary, from tens of thousands to a few hundred thousand entries, and maps each piece to an integer:

```python
>>> import tiktoken
>>> enc = tiktoken.get_encoding("o200k_base")
>>> enc.encode("Why is the sky blue?")
[13903, 382, 290, 17307, 9861, 30]   # "Why", " is", " the", " sky", " blue", "?"
```

Those are real IDs from one public tokenizer. The IDs in the animation are illustrative. Every model has its own vocabulary, so the same sentence gets different numbers.

## Embeddings: each ID looks up a vector

Each ID selects one row from a learned table. The row is a vector of a few thousand numbers[^dims], and it's the model's starting point for what that token means.

This step is a lookup. Nothing is computed yet. Word order isn't in the vector either: most current models add position inside attention, with rotary embeddings (RoPE).

*Interactive diagram on the page: The embedding table.*

## The transformer: vectors rise through N layers

The vectors pass up through a stack of layers, all the same shape, from a few dozen to over a hundred. Each layer does two things:

- **Attention.** Each token reads the tokens before it. It compares a query against their keys and takes a weighted mix of their values. That's how "blue" can take something from "sky". Tokens can't read ahead.
- **MLP.** Each position is reshaped on its own, through a wide feed-forward network. Most of the parameters live here.

*Interactive diagram on the page: Through the layers.*

The first pass over your prompt is called prefill. Every prompt token goes through every layer in parallel, so the GPUs are busy doing maths. On the way, each layer stores the keys and values for every token in the KV cache. It's never recomputed.

The KV cache is large. A Llama 3 70B-class model (80 layers, 8 KV heads of 128 dimensions) stores 2 × 80 × 8 × 128 × 2 bytes per token: about 320 KiB. An 8,000-token conversation needs roughly 2.6 GB of GPU memory, just for its cache.

*Interactive diagram on the page: Inside the model.*

## Next token: predict, sample, append, repeat

At the top of the stack, the last position's vector is projected onto the whole vocabulary. That gives one score, a logit, per token. Softmax turns the scores into probabilities. The sampler then picks one:

- **Temperature** scales the logits first. Lower values sharpen the distribution, higher values flatten it.
- **Top-p** keeps the smallest set of tokens whose probabilities add up to p, then samples from those.

Say "Sun" comes out at 0.62 (illustrative). It's appended to the sequence, and the model runs again. This time only the new token goes through the layers, and its attention reads everything earlier from the KV cache. One forward pass, one token. That repeats until an end-of-sequence token or a length limit.

Prefill and decode are the same model doing very different work:

| | Prefill | Decode |
| --- | --- | --- |
| Runs | Once per request | Once per output token |
| Tokens per pass | The whole prompt | One per request |
| Bottleneck | Compute | Memory bandwidth: every step reads all the weights and the KV cache |
| Shows up as | Time to first token | Time between tokens |
| What batching buys | Little: it's already parallel | Almost everything: one weight read serves the whole batch |
| The difference that bites | A long prompt can stall decode for everyone in the batch | The KV cache caps how many requests fit |

That last row is the bit I'd point an infra engineer at. Batching makes decode affordable. The KV cache decides how big the batch can be. Servers split long prompts into chunks so prefill doesn't stall decode, and they manage the cache in pages, like virtual memory[^paged].

## Streaming back: one event per token

Each token is turned back into text and sent the moment it exists, as a server-sent event (SSE) on the connection that's been open since the start:

```sse
data: {"delta": "Sun"}

data: {"delta": "light"}

data: {"delta": " scatters"}
```

The event format varies by provider. The events retrace the path: the gateway counts output tokens for billing and quotas, output classifiers may look at them, and the edge passes them through. The browser appends each fragment and re-renders, so the answer appears word by word.

Two things bite here:

- **Buffering proxies.** A proxy that buffers responses turns a stream into one late blob. With nginx, that means `proxy_buffering off` or an `X-Accel-Buffering: no` header.
- **Disconnects.** If you close the tab, the server has to notice and drop the request. Otherwise it keeps generating tokens nobody reads, holding a batch slot and its KV cache.

*Interactive diagram on the page: Predict and stream.*

## The whole round trip

*Interactive diagram on the page: Where the time goes.*

Put together, with illustrative numbers that move with the model, the hardware and the load:

- **Your computer to the gateway and back:** tens of milliseconds.
- **Queueing and prefill:** tens to hundreds of milliseconds, growing with prompt length and load.
- **Each further token:** roughly 10 to 50 ms.

The first two add up to the time to first token. The third, multiplied by the length of the answer, is most of the wait. A 300-token answer at 30 ms per token takes 9 seconds. The network barely shows.

That's the trip: tens of milliseconds of infrastructure, a few hundred of prefill, then one token at a time until the answer is done.

[^servers]: Open-source inference servers at the time of writing: [vLLM](https://github.com/vllm-project/vllm), [SGLang](https://github.com/sgl-project/sglang), [TensorRT-LLM](https://github.com/NVIDIA/TensorRT-LLM) and [llama.cpp](https://github.com/ggml-org/llama.cpp). Large providers often run their own.
[^dims]: For example, 4,096 dimensions in an 8B-class model and 8,192 in a 70B-class model, in the Llama 3 family.
[^paged]: vLLM introduced this as PagedAttention: [Kwon et al., 2023](https://arxiv.org/abs/2309.06180).
