vLLM — Network Protocol Analysis
ZMQ IPC Protocol (Engine Core ↔ API Server)
In multiprocessing mode, the API server and engine core communicate via ZMQ sockets using a custom binary protocol.
Message Format
Messages are serialized using msgpack (via msgspec) for high performance:
EngineCoreRequest → msgpack bytes → ZMQ SEND
ZMQ RECV → msgpack bytes → EngineCoreOutputs
Input Path (API Server → Engine Core)
Socket type: ZMQ PUSH (async)
Message types (EngineCoreRequestType):
ADD_REQUEST— New inference requestABORT_REQUEST— Cancel request(s)UTILITY— Administrative operations (profile, sleep, wake, LoRA, etc.)
Flow:
AsyncLLM.add_request()serializesEngineCoreRequestviaMsgpackEncoder- Sends via ZMQ PUSH socket to engine core's input queue
- Engine core reads from PULL socket in step loop
Output Path (Engine Core → API Server)
Socket type: ZMQ PUB/SUB (async) — one output socket per engine core client
Message format:
[msgpack bytes] EngineCoreOutputs
├── dict[int, list[EngineCoreOutput]] # keyed by client_index
└── contains: sampled tokens, finish reasons, logprobs
Flow:
- Engine core publishes outputs after each
step() AsyncLLM.output_handler()reads from ZMQ SUB socket- Dispatches to
OutputProcessorfor detokenization and assembly
Tensor IPC
For large tensor transfers (model weights, KV cache), vLLM uses shared memory:
Handler: vllm/v1/engine/tensor_ipc.py (TensorIpcSender)
Mechanism: PyTorch tensor IPC via multiprocessing.reductions — shares tensor storage across processes without copying.
HTTP/ASGI Protocol (Client ↔ API Server)
Standard HTTP with JSON request/response bodies. Streaming uses Server-Sent Events (SSE):
data: {"id":"...","object":"chat.completion.chunk","choices":[...]}\n\n
Authentication Middleware
Implementation: vllm/entrypoints/openai/server_utils.py:AuthenticationMiddleware
Pure ASGI middleware that checks Authorization: Bearer <token> headers:
- Extract bearer token from
Authorizationheader - SHA-256 hash the token
- Compare against pre-hashed API key(s) using
secrets.compare_digest()(constant-time comparison) - Skip authentication for: OPTIONS requests, paths not starting with
/v1(e.g.,/health)
Configuration:
--api-keyCLI flag orVLLM_API_KEYenvironment variable- Multiple keys supported:
--api-key key1 --api-key key2
NCCL Protocol (Inter-GPU Communication)
For tensor parallelism and pipeline parallelism, vLLM uses NVIDIA NCCL:
- All-reduce for tensor parallel linear layers
- All-gather for expert parallelism
- Send/recv for pipeline parallelism
- Broadcast for KV cache coordination in disaggregated serving
KV Connector Protocol (Disaggregated Serving)
Handler: vllm/distributed/kv_transfer/
Enables KV cache sharing between prefill and decode instances:
- Prefill instance computes KV cache
- KV Connector serializes and transfers KV blocks to decode instance
- Decode instance deserializes and loads into local KV cache
- Supports RDMA, TCP, and shared memory transports
MCP Tool Protocol
Handler: vllm/entrypoints/mcp/tool_server.py
vLLM can act as an MCP (Model Context Protocol) client:
- Connects to external MCP tool server via SSE transport
- Discovers available tools via
session.list_tools() - Converts MCP tool schemas to Harmony format for the responses API
- Executes tool calls and feeds results back into generation
This enables the /v1/responses endpoint to use external tools during generation.