liveBook · Manning

Chapter 6: Large language model services: A practical guide

What you will learn in chapter 6 of LLMs in Production

This introduction defines production as putting an LLM to work for real users and previews the chapter’s path from serving and cloud deployment to production challenges and edge devices.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction defines production as putting an LLM to work for real users and previews the chapter’s path from serving and cloud deployment to production challenges and edge devices.

Key terms: production, live or operational environment, end users, service or API, on-demand requests, Kubernetes cluster, production challenges, edge devices

6.1 Creating an LLM service with RAG and more

Introduces why an LLM API should be planned before deployment, what a basic service enables, and the service features the section will examine.

Key terms: LLM API, API architecture, integration challenges, LLM service, batch, stream, communication latency, API, batching, rate limiters

6.1.1 Model compilation

This section explains why compiling an LLM improves production inference, how common optimizations work, and how to use TensorRT or ONNX Runtime to prepare a model for deployment.

Key terms: compiling, lowering, intermediate representation, IR, TorchScript, MLIR, kernel, kernel tuning, GPU, batch size

6.1.2 LLM storage strategies

This section compares ways to store and access an LLM for serving, focusing on startup speed and tradeoffs in reliability, complexity, security, and cost.

Key terms: object storage, artifact registry, bucket, boot times, fusing, FUSE, baking, Docker image, container, mounted volume

6.1.3 Adaptive request batching

This section explains how adaptive request batching groups LLM inference requests to improve GPU utilization and throughput, and when its latency cost is worthwhile.

Key terms: adaptive request batching, dynamic batching, maximum batch size, batch delay, GPU, BentoML, @bentoml.Runnable.method(batchable=True), Triton Inference Server, dynamic_batching {}, throughput

6.1.4 Flow control

This section explains how rate limiters and access keys control traffic to an LLM API, compares four rate-limiting approaches, and discusses how to apply them without unnecessarily disrupting users.

Key terms: rate limiters, DDoS, quotas, bursty workloads, fixed window, sliding window log, token bucket, leaky bucket, access keys, authentication

6.1.5 Streaming responses

This section explains why an LLM service should stream generated text and identifies the components used in a simple streaming implementation.

Key terms: streaming, generated text, latency, tokens per second, TPS, reading speed, asyncio, FastAPI, StreamingResponse, TextIteratorStreamer

6.1.6 Feature store

The section demonstrates how to set up a Feast feature store for a Q&A service and retrieve either current or point-in-time features.

Key terms: feature store, data governance, point-in-time joins, Feast, feature view, entities, schema, source, tags, inference time

6.1.7 Retrieval-augmented generation

This section explains how RAG retrieves relevant document chunks to ground LLM responses and demonstrates preparing a Pinecone index for that retrieval.

Key terms: retrieval-augmented generation (RAG), embeddings, vector database, similarity search, semantic search, nearest neighbors, Pinecone, Pinecone index, WikiDataIngestion, Wikipedia dataset

6.1.8 LLM service libraries

This section introduces LLM-specific serving libraries, explains what they simplify and where their support varies, and uses vLLM to illustrate starting a local service.

Key terms: vLLM, OpenLLM, Text-Generation-Inference (TGI), streaming, batching, GPU parallelization, pip install vllm, /generate endpoint, production infrastructure

6.2 Setting up infrastructure

This section introduces Kubernetes as infrastructure for scalable LLM services and explains the pods, control plane, and custom resources needed to follow the deployment discussion.

Key terms: Kubernetes, k8s, container orchestration, automatic scaling, load balancing, service discovery, containers, pods, nodes, control plane

6.2.1 Provisioning clusters

This section explains how to provision a cluster for an LLM service, enable GPU-aware node auto-provisioning, and distinguish the resource controls that affect capacity and cost.

Key terms: cluster, nodes, gcloud, eksctl, az cli, node auto-provisioning, NAP, cluster autoscaling, GPU resourceType, T4

6.2.2 Autoscaling

This section explains why LLM services need autoscaling, how to scale Kubernetes pods using GPU or other custom metrics, and how to tune scaling to balance reliability and cost.

Key terms: autoscaling, replicas, bursty workloads, horizontal pod autoscaler, HPA, DCGM, Prometheus, KEDA, custom metrics API, target parameter

6.2.3 Rolling updates

Explains how Kubernetes rolling updates replace an LLM deployment’s pods and how GPU constraints shape the update settings and rollout precautions.

Key terms: rolling updates, rolling upgrades, pods, zero downtime, roll back, spec.strategy, maxSurge, maxUnavailable, replicas, GPU resources

6.2.4 Inference graphs

This section explains how inference graphs connect model and API components, what deployment flexibility they offer, and when their added complexity is worthwhile.

Key terms: inference graph, sequential inference graph, encoder, LLM, VectorDB, API, Seldon, SeldonDeployment, Kubernetes CRD, orchestrator

6.2.5 Monitoring

This section explains how to monitor an LLM service for operational failures and silent quality decline without putting costly monitoring work in the inference path.

Key terms: queries per second (QPS), latency, response code counts, CPU utilization, GPU utilization, GPU temperature, silent failures, data drift, performance decay, ML monitoring

6.3 Cost engineering, security, latency, and other production challenges

This introduction shifts from getting an LLM service running to the recurring challenges of deploying and maintaining it in production.

Key terms: deploying models, maintaining them in production, updating, large loads, poor latency, acquiring resources

6.3.1 Model updates and retraining

The section explains how to respond to declining LLM performance by diagnosing failures, choosing targeted fixes, and planning model updates rather than automatically retraining.

Key terms: silent failures, data drift, edge cases, incoming prompts, RAG, finetuning, prompts, knowledge distillation, student model, teacher model

6.3.2 Load testing

This section shows how to load-test an LLM service, measure both capacity and streaming responsiveness, and use Locust results to plan for peak traffic.

Key terms: load testing, staging environment, autoscaling, latency, throughput, queries per second, QPS, time to first token, TTFT, Locust

6.3.3 Troubleshooting poor latency

This section shows how to troubleshoot slow LLM services by measuring bottlenecks and reducing network, hardware, and inference latency.

Key terms: latency, throughput, gRPC, Protocol Buffers, protobufs, REST, Seldon V2 Inference Protocol, MLServer, grpcio, .proto files

6.3.4 Resource management

The section explains why scarce GPU capacity needs active management and introduces SkyPilot and Run:ai as tools for making it more available to jobs.

Key terms: GPU shortage, high-performance computing, resource management, SkyPilot, sky CLI, resource requirements, GPU-backed Jupyter notebook, port forwarding, Run:ai, GPU oversubscription

6.3.5 Cost engineering

This section explains how to reduce LLM serving costs and compare deployment options using cost per token under load.

Key terms: output tokens, inference times, compute time, text embeddings, semantic search, vector store, neural information retrieval, RAG, smaller model, parameters

6.3.6 Security

This section explains the main security risks of production LLMs, why prompt-injection defenses are imperfect, and how to limit the damage if an attack succeeds.

Key terms: LLM agent, tooling, plugins, sandboxed, prompt injection, context-aware filtering, keyword search, second LLM, monitoring, sanitization

6.4 Deploying to the edge

This section outlines practical hardware and model-format choices for running LLM inference on memory- and speed-constrained edge devices.

Key terms: edge devices, memory, speed, inference, Raspberry Pi, Coral, USB-TPU, Optimum, .tflite, TensorFlow

6.5 Summary

The section recaps practical choices for serving LLMs, managing their infrastructure, and addressing production and edge-deployment challenges.

Where this is used later

Concepts explained in this chapter

← Chapter 5: Training large language models: How to generate the generator Chapter 7: Prompt engineering: Becoming an LLM whisperer →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.