Courses / AI Engineering: LLMs, RAG and Agentic System Design / Chapter 23
Module 10 · Evals, security and production · Chapter 23 of 24
Running LLM systems in production
Builds on Generative AI and how LLMs work, Working with model APIs, AI agents and multi-agent systems, Evaluating LLM and agent systems and Securing LLM applications and agents. Next up: Mock interview.
Part 1 · Latency: where the time goes
Three numbers for a reply
A reply that takes eight seconds feels broken even when it is right, and the time is spread over steps that behave very differently. This chapter measures where it goes, then covers cost, caching, gateways, tracing and rollouts.
Three numbers describe the latency of one model call. Time to first token (TTFT) is how long the user waits before anything appears. Decode speed is how many output tokens arrive per second after that. Total time is the whole call. Streaming does not shorten the total, but it moves the first words to the TTFT, so a long answer feels faster.
Inside the server, a call has three parts. Load time applies when the model is not in memory and has to be read in first. The prompt phase, also called prefill, reads all input tokens in one pass, so its cost grows with the prompt but is spread over many tokens at once. The decode phase produces output tokens one at a time, each needing a pass through the model, so its cost grows with the answer. Outside the server there is the network, any queue in front of a busy server, and your own code.