CodeBaobab
COURSE 20 OF 21

LLM Serving and Inference Economics

Find out where the latency and the money actually go, then change the number instead of guessing at it.

Background reading
Free course preview

Introduction to LLM Serving and Inference

LLM inference is the work of running a trained model to answer a request. Serving is the production system that queues requests, manages memory and computing resources, streams tokens, and keeps response time and cost within their limits.

A request has two phases. During prefill, the model reads the prompt and prepares the information needed for generation. During decode, it generates new tokens one at a time.

Prefill has enough parallel work to keep the compute units busy. Decode does much less arithmetic per step but must repeatedly move model weights and the growing key-value (KV) cache from memory, so it is usually limited by memory bandwidth.

Do not answer “the model is slow” as if it were one problem. High TTFT points toward queueing or prefill; high TBT points toward the decode loop and its memory traffic.

Continue learning

Continue with Pro

Get Pro on codebaobab.com.

See Pro plans
Complete course

What you will learn next

  1. 01Latency Metrics That Mean Something
  2. 02Batching and Scheduling
  3. 03Memory: Where the Concurrency Limit Comes From
  4. 04Speculative Decoding
  5. 05Caching Layers
  6. 06Building an Inference Capacity Model
  7. 07Separating First-Token and Decode Latency
  8. 08Reusing a Shared Prompt Prefix
  9. 09Choosing Between Throughput and Tail Latency
  10. 10Review
  11. 11References