# Serving Engines (vLLM, SGLang, TensorRT-LLM, llama.cpp)

> Four engines that run AI models for users, what each one is built for, and how to choose between them, for your AI interview.

**In short:** A serving engine is the program that loads an AI model and answers requests from users. vLLM and SGLang suit a team's shared GPU server, TensorRT-LLM builds TensorRT engines for NVIDIA GPUs, and llama.cpp runs a model on one person's own machine.

AI and LLM interview question Q320, Inference, performance and cost. Intermediate, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/serving-engines-vllm-sglang-tensorrt-llm-llama-cpp

## Say it in 30 seconds

A serving engine is the program that runs an AI model for many people at once. You will hear four names: vLLM, SGLang, TensorRT-LLM and llama.cpp. For a team's shared server on GPUs, I would start with vLLM, which batches many requests and manages memory well, and test SGLang beside it. TensorRT-LLM is tuned for NVIDIA hardware and builds engines for it. llama.cpp is the simple choice for one person's own machine. I pick by hardware, traffic and the team's capacity to run it, then test under a realistic crowd of requests.

## Say it in 2 minutes

A model file on its own cannot answer anyone. A serving engine loads it, takes requests, and runs them on the GPU, the graphics chip that does the heavy maths. Think of a hospital bed manager. The doctors are the model, and the bed manager decides who goes into which bed and when. The engine does that job for requests and GPU memory.

Two ideas do most of the work. The first is batching: the engine groups requests and runs them together. The second is memory. Each chat keeps a KV cache, its notes on earlier words, and that cache grows with every word. vLLM manages that memory in small pages, the way an operating system pages memory, and its paper says the design leaves almost no waste. SGLang reuses stored cache memory with RadixAttention.

The four differ by job. vLLM serves many users from GPU servers, and SGLang is built to run complex model programs efficiently. TensorRT-LLM builds TensorRT engines for NVIDIA GPUs. llama.cpp runs a model on one person's machine, with an installer for macOS and Linux, and WinGet on Windows.

So my answer: match the engine to the hardware, the traffic and the team's capacity to run it. Then test under a realistic crowd of requests before launch. Keep the test results with the release notes, so the next upgrade has a baseline.

## What is a serving engine, in plain words?

A serving engine is the program that loads an AI model and answers many people with it at once. It takes each request, groups requests so the GPU stays busy, looks after the memory each chat uses, and sends the answer back a few words at a time.

Think of a hospital bed manager. The doctors are the model. The bed manager decides who goes into which bed, when, and how many patients share a ward. The engine plays that part for requests and GPU memory.

- **Serving engine:** The software that runs a model for users, takes their requests and returns answers.
- **GPU:** The graphics chip that does most of the heavy maths when a model writes.
- **Batching:** Running several requests through the model together, in one pass.
- **KV cache:** The memory that keeps the model's notes on earlier words, so it does not redo them.

You will hear four names in interviews: vLLM, SGLang, TensorRT-LLM and llama.cpp. They all serve models, but each one is built for a different kind of job.

## What are the four engines, and who is each for?

- **vLLM:** An open-source engine for serving many users from GPU servers. It can run an OpenAI-compatible API server, a front door that apps call in the same format as OpenAI's own service.
- **SGLang:** Built to run programs that make several model calls efficiently. Its runtime uses RadixAttention, a way to reuse the KV cache.
- **TensorRT-LLM:** NVIDIA's library. It builds TensorRT engines for NVIDIA GPUs. It is specifically customised for NVIDIA platforms, so it is built for that hardware.
- **llama.cpp:** Runs a model on one person's own machine. Per Hugging Face's llama.cpp guide, you can install it on macOS and Linux, or with WinGet on Windows, then download and run a GGUF model file, a packed model format it reads.

They overlap, so the useful part of your answer is the reason to pick each one.

> "vLLM is a fast and easy-to-use library for LLM inference and serving." (vLLM project)
>
> "NVIDIA TensorRT-LLM provides users with an easy-to-use Python API to define Large Language Models (LLMs) and build NVIDIA TensorRT engines that contain state-of-the-art optimizations to perform inference efficiently on NVIDIA GPUs." (NVIDIA TensorRT-LLM docs)

## Why do engines batch requests and manage memory?

The PagedAttention paper behind vLLM makes the same point: serving at high throughput, meaning many answers per second, needs enough requests batched together. vLLM lists continuous batching, which adds new requests as others finish, among its main features.

The memory is the harder part. Each chat keeps its own KV cache, and that cache grows and shrinks as the chat goes on. If the engine manages it badly, memory is wasted on gaps and duplicate copies, so fewer chats fit on the GPU.

*Diagram, What a serving engine does: Requests from many users reach the engine together. It groups them into batches, manages their memory and runs the model on the GPU. Each answer streams back as its tokens are made.*
1. Requests from many users reach the engine together.
2. The engine groups them into batches and hands each group to the GPU.
3. Each answer streams back as its tokens are made.

A mid-size bank runs a support assistant. At 10 am, 300 chats are open at once. The numbers are made up, but the shape is real.

1. **Waste: memory lost to gaps and copies:** The paper says this memory can be wasted by fragmentation (gaps between pieces) and redundant duplication, which limits the batch size.
2. **Paged memory: small pages as chats grow:** vLLM hands out memory in small pages as each chat grows, inspired by how an operating system pages memory. Waste drops, so more chats share the same GPU.
3. **Keep adding requests as chats arrive:** The engine keeps adding requests to the running batch as they come in, so the GPU stays busy and answers keep flowing.

> **Tip:** Asked how an engine saves memory, name the cause first: the KV cache grows with every token, and waste in that memory limits how many chats fit. Then name the fix.

## How do you pick one?

Three things decide it: your hardware, your traffic, and how much setup your team can carry. Put those first, then test.

- **Team server: GPUs in your data centre.** vLLM, SGLang or TensorRT-LLM, shared by a team behind one address. Expect setup work. TensorRT-LLM is made for NVIDIA GPUs.
- **One person: A laptop or a small box.** llama.cpp. Simple to run on one machine, so it suits one user or a small private tool.

*Diagram, Where each engine fits: Two kinds of setup. A team's GPU server can run TensorRT-LLM, vLLM or SGLang, and one person's machine runs llama.cpp. Each arrow ends at the job it serves.*
1. A team's GPU server gives many people one shared address.
2. llama.cpp gives one person a tool on their own machine.

The trade-off is setup effort against how closely the engine is built for one kind of hardware. TensorRT-LLM is built most closely for NVIDIA hardware, and llama.cpp needs the least setup for one person.

- **NVIDIA GPUs, and time to set it up:** Consider TensorRT-LLM. Check the release notes for how it loads your model.
- **Many users, or many chained model calls:** Shortlist vLLM and SGLang, and test both with your own prompts.
- **One person, or a small private tool:** llama.cpp is the simple choice.

> **Tip:** Engines and their versions change fast. Quote the version you tested, and never promise a speed number before you measure it on your own traffic.

### How would you choose an engine for a bank's assistant?

A mid-size bank wants an internal assistant for 2,000 staff. It must run on NVIDIA GPU servers in its own data centre, and answers must come back quickly at the 9 am rush. These are made-up details, but the constraints are typical.

1. **Check the hardware:** The servers are NVIDIA, so TensorRT-LLM is an option. Check its release notes for how it loads your model, and whether the team can own that work.
2. **Check the traffic:** Staff use the assistant in bursts at 9 am, so batching matters. vLLM and SGLang are the first two to test.
3. **Test both on real traffic:** Replay last month's real peak with the same model, then compare answers, speed and memory use. Measure rather than guess.
4. **Pick and plan a way back:** Lock the engine to one version, keep the previous one ready to switch back to, and watch the first week closely.

A strong answer ends on the test plan, not on the engine name.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] Name the four engines and the job each one is for.
- [ ] Explain batching and the KV cache in plain words.
- [ ] Say why memory, not only compute, limits how many users fit.
- [ ] Say TensorRT-LLM builds engines for NVIDIA GPUs, so it is tied to that hardware.
- [ ] Say llama.cpp suits one machine or a small private tool.
- [ ] Pick by hardware, traffic and team capacity, then test.

**Common traps**

- Trap: "The four engines are all the same, so pick any one." Better: They overlap, but each one fits a different hardware and traffic pattern.
- Trap: "The fastest engine always wins." Better: Speed depends on your model, hardware and traffic. Measure it on your own load.
- Trap: "Run the bank's assistant on a laptop." Better: One laptop cannot serve a whole bank. Use GPU servers with a batching engine, and load-test first.

## Can you spot the risky plan?

**Spot the risky plan:** A team plans to serve 1,200 claims adjusters from one model. Which line is the risky one?

A. Serve the claims model with vLLM on our NVIDIA GPU servers, behind one internal API.
B. Run llama.cpp on a single shared laptop and point all 1,200 adjusters at it.
C. Load-test with last month's real claim peak before we go live.
D. Pin the engine version, and test upgrades in a copy first.

**Answer:** B. One laptop would be overwhelmed by a peak like that. llama.cpp suits one person or a small private tool. Shared use at this scale belongs on GPU servers with a batching engine such as vLLM, tested first.

**Quick check:** An engineer wants a private note-summary tool on her own laptop. Which engine suits this best?

A. TensorRT-LLM on a cloud cluster
B. llama.cpp on the laptop
C. A batching service for 500 users
D. SGLang on a shared GPU farm

**Answer:** B. llama.cpp runs a model on one person's own machine, which is what this needs. The other three are built for shared GPU servers, far more than one laptop needs.

## Can you answer these from memory?

**Flash cards**

- **What is a serving engine?** The program that loads a model and answers many requests on the GPU.
- **What does batching do?** Runs several requests through the model together, so the GPU stays busy.
- **Why does the KV cache limit users?** It grows with every token of a chat, so wasted memory limits how many chats fit.
- **What is vLLM's memory idea?** PagedAttention: it manages KV cache memory in small pages, like an operating system.
- **Which engine builds TensorRT engines for NVIDIA GPUs?** TensorRT-LLM. Its docs say it builds TensorRT engines that run inference on NVIDIA GPUs.
- **Which engine for one person's machine?** llama.cpp. It runs a model on one person's own machine.

## Likely follow-up questions

- Q055 What is the KV cache, and why does it speed up generation? https://designervenkat.online/interview/ai/what-is-the-kv-cache
- Q314 Static vs continuous batching? https://designervenkat.online/interview/ai/static-vs-continuous-batching
- Q317 The latency vs throughput trade-off? https://designervenkat.online/interview/ai/the-latency-vs-throughput-trade-off
- Q319 What is PagedAttention / vLLM? https://designervenkat.online/interview/ai/what-is-pagedattention-vllm
- Q321 What is speculative decoding? https://designervenkat.online/interview/ai/what-is-speculative-decoding
- Q327 GPU basics: why does memory bandwidth limit decoding? https://designervenkat.online/interview/ai/gpu-basics-why-does-memory-bandwidth-limit-decoding

## Learn it in depth

- [Inference Engineering](https://designervenkat.online/learn/ai-engineering/inference-engineering)
