Deployed Lab

Module 1 · AI workloads on your platform · Chapter 02 · Free

The reference serving stack: from request to token

20 min1 clickable picture1 hands-on lab1 predict, 2 quick quizzes, 5-question final quiz5-min video review
In 30 seconds

The picture: the stack is a relay race. Each runner owns one leg, and the baton is the request, with its request id.

What this chapter gives you
The cold open

Copperline is a made up B2B SaaS company. Ana, the support lead, reports that its support copilot took 8 seconds to answer a simple refund question. All figures here are illustrative.

The model may have been fine. With no layer timings, the team had no way to know, and no fix to make.

The plan for this chapter
  1. The front door: client, gateway, and router.
  2. The waiting room and the engine room: queue, serving engine, GPU node.
  3. The side systems: registry, vector database, cache, observability.
  4. The picture: one request walked through the whole stack.
  5. A latency budget in numbers, then a symptom matching lab.

Next: the front door, where a request earns the right to cost you GPU time.

Step 1: The front door, client, gateway and router

The client sends a request. The API gateway is the first platform layer it meets, and it owns the rules of entry.

Think of a hotel: the front desk checks your booking, then directs you to the right floor. Where the picture breaks down:

Two habits make this layer pay off. First, set the gateway timeout above the honest total budget, or slow but valid answers die at the door. Second, log the request id at entry and pass it on unchanged. Without that one thread, every later layer keeps its own diary and nobody can join them up in an incident.

Next: the request is admitted. Now it waits, and waiting is a design choice.

Step 2: The waiting room and the engine room

The request queue sits between the router and the serving engine. It owns admission and order.

Streaming changes what the user feels. The engine can send the first token early, while the rest still generate, so a long answer can feel fast to start and slow to finish. That is why your traces need two numbers, not one: time to first token, and total time. A stack that only records total time hides a queue problem behind a healthy looking stream, and a stack that only records first token hides a decode problem the same way.

Chapter 5, "Serving engines: what vLLM and its peers actually do", goes deep on the engine. Chapter 6, "Batching and streaming: the latency budget of a token", goes deep on the wait. For model basics, see the latency and cost chapter of the AI engineering course.

Next: the layers nobody demos, and the ones that bite you at 3 a.m.

Step 3: The side systems every serious stack needs

Four systems sit beside the request path. Remove any one and the stack still demos well, then fails in production.

Notice the split. The registry, vector database, and cache hold state the request depends on, so their failures change answers or versions. The observability pipeline holds no user facing state at all, yet it decides whether the other failures take minutes or days to find. Budget for it like a serving layer, not like paperwork, and test it by tracing one real request end to end before launch day, not during the first incident.

Predict first:

In the worked example below, queue wait and decode dominate. That is the common lesson of a first trace: the wait and the generation, not the plumbing, eat the budget. Your own stack may differ, which is the point of measuring.

Next: the picture, one request through every layer.

Step 4: The picture, one request through the stack

Press Next to walk the refund question. Notice that every hop adds time, and every layer can add its timing to the trace.

The reference serving stack A request flows from client through gateway, router and queue to the serving engine on a GPU node. A vector database feeds retrieval, and tracing watches every hop. Clientsupport app Gatewayauth, limits Routermodel choice Queueadmit, order Enginebatch, stream GPU nodedrivers, memory Vector DBretrieval Tracingrequest id
  1. The client sends the question. The gateway checks auth and rate limits, then stamps a request id on it.
  2. The router picks the copilot model and its GPU pool, based on tenant and task.
  3. The queue admits the request and holds it until the engine has room. This wait is real latency, and it is timed.
  4. The vector database returns the refund passages. They join the prompt before generation starts.
  5. The engine batches the request, manages the KV cache, and runs prefill and decode on the GPU node, streaming tokens back.
  6. The observability pipeline records each layer timing under the one request id, so a slow answer has an address.

Next: the same 8 seconds, split into a budget you can act on.

Step 5: Worked example, a latency budget for 8 seconds

Priya replays Ana's refund question with tracing on. All figures are illustrative, for one copilot request.

1. Gateway and network in: 0.3 seconds. Running total: 0.3.

2. Queue wait: 2.4 seconds behind a batch of document jobs. Running total: 0.3 + 2.4 = 2.7.

3. Retrieval: 0.8 seconds for the vector search and passage fetch. Running total: 2.7 + 0.8 = 3.5.

4. Prefill: 1.1 seconds to process the prompt and retrieved passages. Running total: 3.5 + 1.1 = 4.6.

5. Decode: 3.2 seconds to generate the answer tokens. Running total: 4.6 + 3.2 = 7.8.

6. Network back: 0.2 seconds. Total: 7.8 + 0.2 = 8.0 seconds.

The model work, prefill plus decode, is 1.1 + 3.2 = 4.3 seconds. The queue alone is 2.4. Priya's first fix is not a faster model: it is a separate priority lane so support requests do not queue behind batch document jobs.

Next: the lab, where symptoms arrive and you name the owner.

Step 6: Hands-on lab, match the symptom to the layer

Why this exercise: incidents arrive as symptoms, not layer names. Naming the owner first cuts the search from six layers to one.

Do this:

Lab: Priya replays Ana's slow refund question with tracing on, and the chapter's budget appears: gateway and network in 0.3 seconds, queue wait 2.4, retrieval 0.8, prefill 1.1, decode 3.2 for a 400 token answer, network back 0.2. This lab runs in your browser and needs JavaScript enabled.

What to notice

Next: a field note, then the mix-ups.

Field note, November 2026

Production teams commonly trace AI requests with the same request id pattern used for ordinary services, extended with token counts and per layer timing. The habit worth copying is boring on purpose: one id, every layer, no gaps. Claims about how much time any one layer takes vary widely by workload, so measure your own stack rather than borrowing a number.

Mix-ups to avoid

Chapter quiz

Five questions. Score 70% or more to mark this chapter complete.

Review this chapter in 5 minutes

Watch the whole chapter recapped: six layers and their owners, four side systems, one request id, and the eight second latency budget.

Decision rule: for any slow or wrong answer, split the request by layer under one request id, then fix the owning layer first.

Review

Glossary

API gateway
The entry layer: auth, rate limits, timeouts, request ids. Example: rejecting an unauthenticated call.
Router
The layer that picks model and pool per request. Example: premium tenants to the large model.
Request queue
Where admitted requests wait, in priority order. Example: support ahead of batch jobs.
Backpressure
Delaying or shedding load before a layer drowns. Example: pausing batch intake at noon.
Serving engine
Software that batches requests, manages KV cache, and streams tokens. Example: engines in the vLLM category.
KV cache
Stored attention state that avoids recomputing the prompt per token. Sized in the next chapter.
Model registry
The versioned source of truth for model weights and configs. Example: version 14 named as current.
Vector database
A store of document embeddings searched at request time. Example: returning the refund passages.
Request id
One identifier stamped at the gateway and logged by every layer. Example: req-8f31 in every trace.
Latency budget
A total time split into per layer allowances. Example: 8.0 s split six ways in this chapter.

Next: "Reading a model like an operator: weights, KV cache and context".