doc/source/serve/llm/architecture/overview.md
(serve-llm-architecture-overview)=
Ray Serve LLM is a framework that specializes Ray Serve primitives for distributed LLM serving workloads. This guide explains the core components, serving patterns, and routing policies that enable scalable and efficient LLM inference.
Ray Serve LLM takes the performance of a single inference engine (such as vLLM) and extends it to support:
Ray Serve LLM excels at highly distributed multi-node inference workloads where the unit of scale spans multiple nodes:
Before diving into the architecture, you should understand these Ray Serve primitives:
For more details, see the {ref}Ray Serve core concepts <serve-key-concepts>.
Ray Serve LLM provides two primary components that work together to serve LLM workloads:
LLMServer is a Ray Serve deployment that manages a single inference engine instance. Replicas of this deployment can operate in three modes:
The following example demonstrates the sketch of how to use LLMServer standalone:
from ray import serve
from ray.serve.llm import LLMConfig
from ray.serve.llm.deployment import LLMServer
llm_config = LLMConfig(...)
# Get deployment options (placement groups, etc.)
serve_options = LLMServer.get_deployment_options(llm_config)
# Decorate with serve options
server_cls = serve.deployment(LLMServer).options(
stream=True, **serve_options)
# Bind the decorated class to its constructor parameters
server_app = server_cls.bind(llm_config)
# Run the application
serve_handle = serve.run(server_app)
# Use the deployment handle
result = serve_handle.chat.remote(request=...).result()
LLMServer controls physical placement of its constituent actors through placement groups. By default, it uses:
{CPU: 1} for the replica actor itself (no GPU resources).world_size number of {GPU: 1} bundles for the GPU workers.The world_size is computed as tensor_parallel_size × pipeline_parallel_size. The vLLM engine allocates TP and PP ranks based on bundle proximity, prioritizing TP ranks on the same node.
The PACK strategy tries to place all resources on a single node, but provisions different nodes when necessary. This works well for most deployments, though heterogeneous model deployments might occasionally run TP across nodes.
---
width: 600px
name: placement
---
Physical placement strategy for GPU workers
When LLMServer starts, it:
---
width: 600px
name: llmserver
---
Illustration of `LLMServer` managing vLLM engine instance.
OpenAiIngress provides an OpenAI-compatible FastAPI ingress that routes traffic to the appropriate model. It handles:
/v1/chat/completions, /v1/completions, /v1/embeddings, etc.The following example shows a complete deployment with OpenAiIngress:
from ray import serve
from ray.serve.llm import LLMConfig
from ray.serve.llm.deployment import LLMServer
from ray.serve.llm.ingress import OpenAiIngress, make_fastapi_ingress
llm_config = LLMConfig(...)
# Construct the LLMServer deployment
serve_options = LLMServer.get_deployment_options(llm_config)
server_cls = serve.deployment(LLMServer).options(**serve_options)
llm_server = server_cls.bind(llm_config)
# Get ingress default options
ingress_options = OpenAiIngress.get_deployment_options([llm_config])
# Decorate with FastAPI app
ingress_cls = make_fastapi_ingress(OpenAiIngress)
# Make it a serve deployment with the right options
ingress_cls = serve.deployment(ingress_cls, **ingress_options)
# Bind with llm_server deployment handle
ingress_app = ingress_cls.bind([llm_server])
# Run the application
serve.run(ingress_app)
:::{note} You can create your own ingress deployments and connect them to existing LLMServer deployments. This is useful when you want to customize request tracing, authentication layers, etc. :::
When the ingress makes an RPC call to LLMServer through the deployment handle, it can reach any replica across any node. However, the default request router prioritizes replicas on the same node to minimize cross-node RPC overhead, which is insignificant in LLM serving applications (only a few milliseconds impact on TTFT at high concurrency).
The following figure illustrates the data flow:
---
width: 600px
name: llmserver-ingress-rpc
---
Request routing from ingress to LLMServer replicas. Solid lines represent preferred local RPC calls; dashed lines represent potential cross-node RPC calls when local replicas are busy.
Ingress-to-LLMServer ratio: The ingress event loop can become the bottleneck at high concurrency. In such situations, upscaling the number of ingress replicas can mitigate CPU contention. We recommend keeping at least a 2:1 ratio between the number of ingress replicas and LLMServer replicas. This architecture allows the system to dynamically scale the component that is the bottleneck.
Autoscaling coordination: To maintain proper ratios during autoscaling, configure target_ongoing_requests proportionally:
target_ongoing_requests to say 75% of max capacity (for example, 48).target_ongoing_requests to maintain the ratio (for example, 24).Ray Serve LLM supports several deployment patterns for different scaling scenarios:
Create multiple inference engine instances that process requests in parallel while coordinating across expert layers and sharding requests across attention layers. Useful for serving sparse MoE models for high-throughput workloads.
When to use: High request volume, kv-cache limited, need to maximize throughput.
See: {doc}serving-patterns/data-parallel
Separate prefill and decode phases to optimize resource utilization and scale each phase independently.
When to use: Prefill-heavy workloads where there's tension between prefill and decode, cost optimization with different GPU types.
See: {doc}serving-patterns/prefill-decode
Implement custom routing logic for specific optimization goals such as cache locality or session affinity.
When to use: Workloads with repeated prompts, session-based interactions, or specific routing requirements.
See: {doc}routing-policies
Ray Serve LLM follows these key design principles:
LLMEngine protocol.core - Technical implementation details and extension pointsserving-patterns/index - Detailed serving pattern documentationrouting-policies - Request routing architecture and patterns../user-guides/index - Practical deployment guides