Production LLM Inference Platform: Architecture, Routing, and Operations

    This article walks through the engineering practices required to turn a working large language model inference setup into a production-grade platform. It covers a four-layer architecture that separates resources, inference engines, scheduling, and observability; declarative deployment and version governance for multi-version model serving; cache-aware routing that converts prefix cache hit rates into throughput; autoscaling driven by service-level objectives rather than CPU utilization; observability signals specific to inference such as batch saturation and generation quality; stream resumption and fault tolerance for long outputs; continuous tuning against replayed production traffic; and a phased rollout plan with an acceptance checklist. Readers will find configuration examples, routing and scaling pseudocode, and concrete criteria for deciding whether an inference service is genuinely production-ready.

    1. Background: Why “It Runs” Is Not “It Works in Production”

    In most teams, standing up a large language model with an inference engine is not hard: load the weights, start the service, send one request, get a result. That can be done in half a day. The real cost shows up afterward — when concurrency climbs from single digits to hundreds or thousands, when one major model version becomes several minor versions coexisting, when GPU memory is exhausted by long contexts, when a node drops offline at 3 a.m., when a business team starts asking why this request was five times slower than the last one. None of these fall within the responsibility of a single-instance inference engine. They belong to cluster-level scheduling and governance.

    The core tension in production inference infrastructure can be stated in one sentence: compute is scarce and expensive, while load is volatile, bursty, and uneven. Without a scheduling layer, resource utilization and service quality degrade at the same time — either you reserve large amounts of idle capacity for the peak, or you see widespread timeouts when traffic fluctuates. So the goal of the platform layer is not to replace the inference engine, but to add five capabilities on top of it: control, scale, failover, diagnosis, and continuous improvement.

    2. Overall Architecture: Layered and Decoupled

    A sustainable inference platform is usually divided into four layers, with explicit contracts between them so capabilities do not bleed into one another.

    • Resource layer: the container orchestration system handles node onboarding, resource quotas, image distribution, and fault isolation, abstracting raw compute into a resource pool that is declarative, schedulable, and reclaimable.
    • Engine layer: the single-instance inference runtime handles efficient computation, including batch scheduling, GPU memory management, and operator optimization, exposing a unified request/response contract upward.
    • Scheduling layer: the core of the platform, responsible for service orchestration, traffic distribution, elastic scaling, fault recovery, and configuration tuning.
    • Observability layer: metrics, logs, and traces are collected through a unified pipeline, serving both real-time alerting and offline tuning and capacity planning.

    The value of this layering is that replacement cost stays bounded: the engine can be swapped from one to another with no impact on the business, and the resource layer can migrate from self-managed clusters to a managed container platform without changing scheduling policies.

    3. Model Deployment and Version Governance

    The deployment unit in production is not “a model file” but “a set of service instances with constraints.” A practical approach is to express the deployment as declarative configuration that spells out the image, weight source, startup arguments, resource requests, readiness criteria, and replica range, leaving the platform to reconcile toward the desired state.

    1. service:
    2. name: chat-inference
    3. model:
    4. source: object-storage://models/chat-7b-v3
    5. revision: v3
    6. runtime:
    7. image: inference-runtime:latest
    8. args: ["--max-model-len", "8192", "--gpu-memory-utilization", "0.88"]
    9. resources:
    10. accelerator: 1
    11. cpu: "8"
    12. memory: 32Gi
    13. replicas: { min: 2, max: 40 }
    14. readiness:
    15. probe: /health
    16. warmupSeconds: 90

    A few engineering details are easy to overlook. First, weights are large and cold starts are slow, so warmup probes and readiness delays are needed to keep traffic away from instances that have not finished GPU memory allocation. Second, multiple versions coexisting is the norm, so use weight derivation and traffic-weighted canary releases rather than a single hard cutover. Third, configuration must be versioned, so any production change can be traced back to a specific configuration snapshot; otherwise incident reviews have nothing to work from.

    4. Cache-Aware Routing: Turning Hit Rate into Throughput

    The cost structure of inference requests is highly uneven: short prompts, long prompts, shared system prefixes, and multi-turn conversations can differ by an order of magnitude. If routing only uses round robin or least connections, requests sharing a prefix get scattered across instances, prefix caches are repeatedly invalidated, and compute is wasted on duplicate work.

    Cache-aware routing makes the scheduling decision carry context affinity: maintain, for each instance, an approximate set of prefix fingerprints present in its cache, and prefer routing new requests to instances likely to hit. Set an affinity ceiling so a hot instance cannot be overloaded. In practice this usually means a lightweight index mapping prefix hashes to instances along with a last-active timestamp, plus invalidation when instances scale or restart.

    1. key = hash(system_prompt + prefix_tokens_window)
    2. if index[key] exists and load(target) < threshold:
    3. route -> target # affinity first
    4. else:
    5. route -> least_pending() # fall back to load first
    6. index.update(key, target, ttl=120s)

    Affinity is only a preference. Load-based fallback and timeout circuit breaking must always remain in place, or cache optimization turns into long-tail latency.

    5. Autoscaling Against Service Objectives

    Traditional CPU-utilization-based scaling largely fails for inference, because the bottleneck is usually GPU memory and the batch queue rather than the processor. A better approach is to translate business objectives into observable scaling signals: p95/p99 time to first token, end-to-end per-request latency percentiles, per-instance queue length, and batch saturation.

    A dual-loop design works well. The fast loop adjusts per-instance concurrency limits and batch size within seconds to tens of seconds, absorbing transient spikes. The slow loop adjusts replica count over minutes to follow trends. Because cold starts are expensive for large model instances, scale-out must be paired with warmup and gradual traffic ramp-up, while scale-in needs a cooldown window and graceful termination to avoid flapping right after removing capacity.

    1. if p95_ttft > SLO_ttft for 60s: scale_out(step=max(1, ceil(pending/8)))
    2. if p95_ttft < SLO_ttft * 0.5 for 10m and replicas > min: scale_in(cooldown=5m)

    6. Observability: Locate First, Optimize Later

    Inference observability needs two additional signal categories beyond a typical microservice: saturation metrics tied to GPU memory and batching, and quality metrics tied to generation, such as output length distribution, truncation rate, and repetition rate. Beyond metrics, traces should record time spent in queueing, prefill, and decode stages, and logs should retain redacted prompt and response summaries for sampled requests so issues can be reproduced.

    Alert design should avoid scattering single-metric thresholds everywhere. Combined conditions are more useful: latency percentiles breaching SLO while the queue keeps growing points to insufficient capacity; latency breaching SLO with a short queue more likely means an overly long single request or an engine anomaly; rising error rate accompanied by instance restarts means investigate resources and runtime stability first.

    7. Stream Resumption and Fault Tolerance

    In long-output scenarios, a single interruption can invalidate an entire result, which is expensive. Practical measures include: treat generation as a resumable state machine and persist generated content plus context position periodically or at key points; carry an idempotency key on the request so retries resume from the checkpoint instead of regenerating from scratch; when an instance exits abnormally, have the scheduling layer migrate unfinished requests to healthy instances while preserving streaming semantics transparently for the client.

    1. request_id = uuid() # idempotency key
    2. checkpoint = { tokens, position, updated_at }
    3. on_failure: reattach(request_id, checkpoint) -> resume_stream()

    Graceful termination is also required: stop accepting new requests first, wait for in-flight requests to reach a checkpoint, then release resources. This minimizes user-visible interruption caused by releases and scale-in.

    8. Continuous Tuning for Real Workloads

    Static parameters are almost never right on the first try. A more reliable path is to sample real production traffic into a replay set, then run grid or Bayesian search over key parameters in an isolated environment — batch size, GPU memory utilization ratio, max context, concurrency limit, routing affinity threshold — with the objective of maximizing throughput subject to meeting latency targets. Candidate configurations then go through small-traffic canary validation before being fixed as the recommended baseline for that version. Tuning must be reproducible: fixed dataset, fixed random seed, and a full record of configuration and results for every trial, otherwise conclusions cannot be retained.

    9. Rollout Plan and Acceptance Checklist

    A four-phase rollout is suggested. Phase one delivers declarative deployment and basic observability so the service becomes manageable. Phase two adds cache-aware routing and queue metrics for the first throughput gains. Phase three ships the dual-loop autoscaling and stream resumption to improve stability and cost. Phase four introduces replay-based tuning to establish versioned configuration baselines.

    Five questions make a useful self-check. Does a single release go unnoticed by users? Can unfinished requests resume after a node failure? Can scale-out reach target capacity within the window the business tolerates? Can latency and saturation metrics be attributed to a specific stage? Is every configuration change traceable and rollback-able? If all five pass consistently, the inference service has genuinely moved from “it runs” to “it works in production.”