Reference Architectures
AIintermediateupdated 2026-08-11

LLM Application Backend

A production LLM backend: gateway, prompt/version control, caching, guardrails, and observability.

#llm#ai#gateway#observability

Harvested from ARC Labs catalog seed + Operator-AI Bedrock gateway practice

View source in repo →
Prompt v14 at 2am. Gateway, versioned prompts, traces, and a cost cap.
Prompt v14 at 2am. Gateway, versioned prompts, traces, and a cost cap.

When not to use

A one-off notebook or an internal spike with no cost, safety, or replay requirements.

Problem

Calling an LLM directly from your app works in a demo but not in production — you need cost control, safety, versioned prompts, and the ability to debug a bad answer after the fact.

Shape

Requests flow through an LLM gateway that handles auth, rate limiting, provider routing, and retries. Prompts are versioned artifacts, not inline strings. A semantic/exact cache short-circuits repeated queries. Input and output guardrails screen for injection, PII, and policy violations. Every call is traced (prompt, model, tokens, latency, cost) for observability and eval.

Key decisions

  • Gateway indirection so you can switch providers or models without touching app code.
  • Prompt versioning so you can attribute a regression to a change and roll back.
  • Cache on normalized input to cut cost and latency on hot paths.
  • Streaming responses for perceived latency; buffer for guardrail checks where needed.

Failure modes

Provider outages need fallback routing or a degraded mode. Unbounded context or retries blow up cost — cap both. Prompt injection from user or retrieved content can exfiltrate data — screen inputs and constrain tool access. No tracing means you cannot reproduce a bad answer.

Scaling path

Add provider fallbacks and per-tenant quotas at the gateway. Move hot prompts behind the cache. Introduce an eval pipeline that replays traced traffic against prompt changes before you ship them.