Deployment turns a working workflow into a dependable service
A prototype proves that a request can produce an output. Production deployment must keep that workflow available, secure, observable, affordable, and recoverable while real traffic and model versions change. The first architectural choice is often whether inference runs behind a hosted API or on infrastructure your team operates.
Neither choice is universally cheaper, faster, more private, or safer. Compare the actual provider, region, model, hardware, workload, contract, and operating capability. Preserve a stable application interface so this choice can change without rewriting every product feature.
Deploying Generative AI Applications in Simple Words
Deploying generative models is fundamentally different from deploying microservices. LLMs and diffusion models are GPU-memory bound: an inference server must manage dynamic KV-caches across thousands of concurrent tokens. High-performance runtimes (like vLLM or Triton) use continuous batching, PagedAttention, and FP8 quantization to boost serving throughput by $10\times$ while holding p99 latency under tight SLAs!
Serving Engine
vLLM / Triton with continuous batching & PagedAttention
Weight Optimization
FP8 / INT4 quantization reduces VRAM footprint by 50%
Capacity Planning
Little's Law: L = λ × W models concurrency & queues
Canary Deployment
Shadow evaluation, gradual traffic ramp, instant rollback
Hosted API or self-hosted open model?
| Dimension | Hosted model / API | Self-hosted / open model |
|---|---|---|
| Startup effort | Provider supplies serving infrastructure and an API. | Team provisions runtime, weights, hardware, networking, and operations. |
| Infrastructure control | Control is bounded by provider options and contract. | Team controls stack and placement but owns failures. |
| Privacy / data location | Depends on provider data flow, retention, region, and terms. | Can keep inference in a chosen environment; team must secure it. |
| Customization | Available methods depend on the service. | Weights and runtime may be modifiable if the licence and format allow. |
| Scaling responsibility | Provider operates capacity; quotas and limits still apply. | Team plans replicas, queues, accelerators, and autoscaling. |
| Maintenance | Provider maintains serving stack; client integration still changes. | Team patches dependencies, drivers, runtime, weights, and hosts. |
| Latency | Network, provider queue, region, and model contribute. | Placement is controllable; local queues and hardware contribute. |
| Cost structure | Often usage or reserved-capacity charges plus data/network terms. | Hardware, idle capacity, engineering, energy, and operations. |
| Version control | Pin versions where supported and monitor provider changes. | Team chooses exact artifacts and rollout schedule. |
| Observability | Combine provider telemetry with application measurements. | Team instruments model server, hardware, queue, and application. |
Figure 1 — Hosted and self-hosted paths place responsibility differently
Both paths begin behind the same application server. Hosted inference transfers more infrastructure operation to a provider; self-hosting gives the team more infrastructure control and responsibility.
An application server branches to a hosted path through a provider API and provider-managed inference, and a self-hosted path through the organization's inference service, model runtime, and compute infrastructure. Side panels compare infrastructure control, scaling responsibility, privacy and data location, customization, maintenance, cost structure, and version control without claiming that either path is always safer or cheaper.
Application server
stable internal contract
BRANCHES TO
HOSTED PATH
Provider API → managed inference
Provider manages more serving infrastructure.
Team still manages integration, policy, measurements, and contract choices.
Data location depends on provider region and terms.
SELF-HOSTED PATH
Inference service → runtime → compute
Team controls and manages more infrastructure.
Team owns capacity, maintenance, security, and rollout.
Customization depends on licence and model format.
Keep secrets and provider details behind the server
Provider keys belong in a server-side secret manager or protected environment—not JavaScript delivered to a browser, a mobile binary, source control, or ordinary logs. Give each service the least access it needs, rotate credentials, and make suspected exposure an incident with a revocation path.
Define an internal request and response contract that the application understands. An adapter translates that contract to a chosen provider or self-hosted server. Record the actual model and version that served each request so a quality change can be traced without leaking unnecessary user content.
A stable serving boundary
This is conceptual pseudocode, not a runnable provider integration. APP_TIMEOUT and SERVER_SECRET come from protected server configuration; the exact web framework, retryable-error types, and provider methods must be supplied by the implementation.
# Conceptual server pseudocode — provider APIs and web frameworks vary.
def generate(request, idempotency_key):
validated = validate_and_rate_limit(request)
provider = choose_healthy_provider(validated.model_class)
try:
return provider.call(
validated,
timeout_seconds=APP_TIMEOUT,
secret=SERVER_SECRET,
idempotency_key=idempotency_key,
)
except TransientFailure as error:
record_failure(provider.version, error.category)
return approved_fallback(validated)Bound failure instead of retrying blindly
A timeout limits how long the application waits. A retry may help a transient failure, but repeated generation can produce a different result, duplicate a billed task, or repeat an external action. Retry only classified transient failures, use a small attempt limit with backoff, and attach an idempotency key when the receiving system supports it so one logical request is not processed twice.
Rate limits protect budgets and shared capacity. Concurrency limits cap simultaneous work; queues absorb short bursts. Batching can improve accelerator use when similar requests can wait together, while streaming can show partial output sooner without reducing total compute. Cache only when inputs, permissions, model version, and policy make reuse safe. Do not cache personalized, secret, time-sensitive, random, or safety-dependent results under an overly broad key.
Worked capacity estimate: how many requests are in flight?
Suppose production measurements show an average arrival rate of 2 requests per secondand an average processing time of 3 seconds per request. Both numbers are measured averages over the same stable period. The calculation is 2 × 3 = 6 requests in flight on average. This helps estimate starting capacity and concurrency limits. It is not an autoscaling guarantee: bursts, long-tail latency, failures, batching, hardware saturation, and queueing require extra measurement and headroom.
Figure 2 — Reliability controls surround the production request path
Keep the central request readable, then place traffic, call, performance, observability, and rollout mechanisms where they act. The concurrency equation is a planning estimate, not an autoscaling guarantee.
A central production path moves from client to application server, validation and context, provider abstraction, model inference, and response. Before and around requests are authentication, secrets, rate limiting, and concurrency controls. Call reliability contains timeout, bounded retry, idempotency when supported, and fallback. Performance contains streaming, appropriate batching, and safe caching. Observability includes error rate, p50 and p95 latency, throughput, cost per successful task, and quality or safety regression. Deployment includes canary or shadow traffic, rollback, and version rollout. A small planning inset calculates two requests per second times three seconds as approximately six in-flight requests on average.
BEFORE REQUEST
auth · secrets · rate limit · concurrency
CENTRAL REQUEST PATH
Client
authenticated request
Application server
request ID + policy
Validation / context
approved input + evidence
Provider abstraction
stable interface + version
Model inference
hosted or self-hosted
Response
result or fallback
CALL RELIABILITY
timeout · bounded retry · idempotency · fallback
PERFORMANCE
stream · batch when useful · cache when safe
OBSERVABILITY
errors · p50/p95 · throughput · cost · regressions
DEPLOYMENT
canary/shadow · stop rules · rollback · versions
Planning estimate
2 requests/s × 3 s ≈ 6 in flight
average estimate · not autoscaling guarantee
Observe the user service, not only the GPU
| Signal | What it means | Useful breakdowns |
|---|---|---|
| Request and error rate | Traffic arriving and requests ending unsuccessfully | Endpoint, error class, provider, model version |
| p50 / p95 latency | 50% / 95% of requests finish at or below these measured times | Queue, first token, full response, input/output size |
| Throughput | Successful tasks, outputs, tokens, or media units per time | Workload class, hardware, batch size |
| Cost per successful task | Total attributable serving cost divided by accepted task completions | Model, provider, retries, cache status |
| Quality regression | Fixed evaluation or sampled production quality worsens | Prompt version, model version, case slice |
| Safety failures | A prohibited or harmful output passed or a valid request was wrongly blocked | Policy category and reviewed severity—without unnecessary private text |
Scale and release model versions deliberately
Autoscaling changes serving capacity in response to signals such as pending requests or hardware use; it needs minimum/maximum bounds, warm-up assumptions, and a plan for cold starts. A fallback might use a smaller approved model, a read-only experience, a queued job, or a clear unavailable response. It must be evaluated too—silently returning a lower-quality unsafe answer is not resilience.
Treat model, prompt, safety policy, and serving configuration as versioned release artifacts. Shadow a new version on copied eligible traffic without showing its output, or canary it to a small real-traffic slice. Compare errors, latency, cost, quality, and safety against the current version. Define stop conditions and a tested rollback before increasing traffic.
Deployment readiness checklist
Secrets are server-side, access-scoped, rotatable, and absent from ordinary logs.
Model/provider adapters expose a stable request, response, error, and version contract.
Timeout, retry, idempotency, rate, queue, and concurrency behavior is tested.
Caching and streaming decisions match privacy, freshness, randomness, and user experience.
Capacity tests cover ordinary traffic, bursts, cold starts, and long-tail latency.
Dashboards connect reliability, cost, quality, and safety to model and prompt versions.
Canary or shadow criteria, stop conditions, fallback behavior, and rollback are rehearsed.
Logging minimizes sensitive content and has retention, access, and incident rules.
Summary / Key Takeaways
- Deployment turns a working generative workflow into a service that must remain secure, available, observable, affordable, and recoverable.
- Choose hosted or self-hosted inference from measured privacy, control, cost, latency, scaling, maintenance, and operating constraints.
- Keep provider keys and implementation details behind a stable server-side request and response contract.
- Bound timeouts, retries, rate, queues, and concurrency; use idempotency where supported so retries do not duplicate one logical request.
- Average in-flight work can be estimated as arrival rate × average processing time, but bursts and long-tail latency still require headroom and measurement.
- Observe errors, p50/p95 latency, throughput, cost per successful task, quality regressions, and safety failures by model and prompt version.
- Release with shadow or canary evidence, stop conditions, an evaluated fallback, and a tested rollback path.