Skip to content
PRODUCTION BLUEPRINTS30 total patterns

Architecture & Engineering Patterns

Reusable, battle-tested patterns for production AI systems. Architecture blueprints define system topology; engineering patterns specify runtime execution controls.

Architecture patterns versus engineering patterns

Choose the system shape first, then the techniques that make that shape reliable.

Architecture Blueprints

· 13 system shapes
ARCH-01LLM Applications
Basic LLM application
The simplest production LLM application: a UI calls an API which calls the model. Everything else is built on top of this shape.
3 valid contexts 3 anti-patterns
ARCH-02Retrieval
RAG system
Retrieval-augmented generation: ground the LLM in your private data by retrieving relevant chunks and injecting them into the prompt.
4 valid contexts 3 anti-patterns
ARCH-03Agents
Agent system
An LLM with tools that can decide, act and observe in a loop until a task is complete.
3 valid contexts 3 anti-patterns
ARCH-04Agents
Production agent
An agent system wrapped in the production machinery required to ship safely: gateway, policy, observability, evaluation, caching and security.
3 valid contexts 2 anti-patterns
ARCH-05Agents
Multi-agent system
A system of specialised agents coordinated by an orchestrator or graph to solve complex tasks via division of labour.
3 valid contexts 2 anti-patterns
ARCH-06Cost & Reliability
Model router
Route requests to the cheapest model that can handle the query, falling back to stronger models as needed.
3 valid contexts 2 anti-patterns
ARCH-07Quality
Evaluation pipeline
Continuous evaluation of LLM outputs in CI and production to catch regressions before users do.
3 valid contexts 2 anti-patterns
ARCH-08Security
Guardrail layer
Input and output safety layers that filter, validate and redact before content reaches the model or the user.
3 valid contexts 2 anti-patterns
ARCH-09Reliability
Streaming pipeline
Stream tokens to the UI with server-side processing of structured outputs, function calls and tool execution.
3 valid contexts 2 anti-patterns
ARCH-10Agents
Human-in-the-loop
Pause agent execution for human approval before destructive or high-stakes actions, then resume.
3 valid contexts 2 anti-patterns
ARCH-11Retrieval
Hybrid search
Combine dense vector search with sparse keyword (BM25) search and fuse the results for more robust retrieval.
3 valid contexts 2 anti-patterns
ARCH-12Agents
Reasoning planner with fast executor
Pair an upstream reasoning model for upfront task planning and verification with a high-throughput, low-latency executor model for sequential tool calls.
3 valid contexts 3 anti-patterns
ARCH-13Retrieval
GraphRAG hybrid search
Combine entity-relationship knowledge graphs, hierarchical community summaries, dense vector search, and sparse BM25 keyword matching for global corpus understanding and multi-hop reasoning.
3 valid contexts 3 anti-patterns

Engineering Runtime Controls

· 17 mechanisms
ENG-01Reliability
Retry with exponential backoff
LLM APIs and external services fail transiently — rate limits, network blips, provider hiccups. Naive retry storms the failing service and makes things worse.
Retry failed requests with exponentially increasing delay, full jitter (randomised), a max attempt count, and only for idempotent / retryable status codes.
View implementation code →Production ready
ENG-02Reliability
Fallback model chain
A single LLM provider has outages, rate limits or degradations. Your product should not go down with it.
Define an ordered fallback chain of models. On failure (after retries), fall through to the next model in the chain. Each model has its own retry policy.
View implementation code →Production ready
ENG-03Cost
Model routing
Using a frontier model for every query is expensive and slow. Most queries are simple and a small model is sufficient.
Classify query complexity and route to the cheapest model that can handle it, with fallback to stronger models on low confidence.
View implementation code →Production ready
ENG-04Cost
Semantic caching
Many users ask similar questions. Re-generating identical or near-identical answers wastes money and adds latency.
Cache LLM responses keyed by a hash of the canonical prompt. For semantic similarity, embed the query and match against cached queries above a similarity threshold.
View implementation code →Production ready
ENG-05Latency
Streaming responses
Generating a full response before sending it to the user creates high perceived latency. Users abandon slow pages.
Stream tokens from the LLM to the client via Server-Sent Events as they are generated, so the user sees the first token in < 500ms.
View implementation code →Production ready
ENG-06Reliability
Structured output validation
LLMs produce malformed JSON, extra fields, wrong types, or hallucinate enum values. Downstream code crashes.
Constrain decoding with a JSON schema (where supported), then validate the output with a strict schema validator. On failure, repair or retry.
View implementation code →Production ready
ENG-07Security
Guardrails
Users inject prompts ('ignore previous instructions'), share PII, or receive harmful outputs. Production LLM apps need defence in depth.
Run an input guard before the model and an output guard before the response. Block, redact, or fall back to a safe response.
View implementation code →Production ready
ENG-08Cost
Rate limiting
Without rate limits, a single user or abuser can blow through your cost budget or DDoS the provider.
Apply per-user, per-IP and global rate limits using a token bucket or sliding window, with a cost-based limit (not just request count).
View implementation code →Production ready
ENG-09Reliability
Circuit breaker
When a downstream service fails, retrying every request keeps hammering it and slows everything down. The system never recovers.
Track failures per downstream. When failures exceed a threshold, open the circuit and fail fast for a cooldown period, then half-open to test recovery.
View implementation code →Production ready
ENG-10Scalability
Async jobs and queue
Long-running LLM tasks (document summarisation, batch embedding, multi-agent research) block request threads and time out.
Submit work to a queue. Workers process jobs asynchronously. Clients poll or receive a webhook/SSE when done.
View implementation code →Production ready
ENG-11Quality
Prompt versioning
Prompts are code. Editing a prompt in a notebook breaks production, cannot be rolled back, and cannot be evaluated across versions.
Version prompts as code. Tag, evaluate and deploy prompt versions through the same pipeline as application code.
View implementation code →Production ready
ENG-12Safety
Human approval gate
Agents that take destructive actions (send email, modify data, make payment) cannot be fully autonomous.
Pause the agent before destructive actions, persist state, request human approval, resume on approval with the decision in context.
View implementation code →Production ready
ENG-13Security
Prompt injection defence
User input or retrieved documents contain instructions like 'ignore all previous instructions and...'. The model obeys the injected instruction.
Treat all untrusted text as data, not instructions. Use structured prompts with clear delimiters, system prompt primacy, and an output guard that detects instruction-following from untrusted context.
View implementation code →Production ready
ENG-14Security
Secrets management
LLM API keys in .env files or code lead to leaks, unrotated keys, and no audit of who used which key.
Store secrets in a vault (HashiCorp Vault, AWS Secrets Manager). Fetch at startup or per-request with short-lived tokens. Rotate frequently. Never log secrets.
View implementation code →Production ready
ENG-15Performance
Prompt caching and KV cache prefix alignment
LLM inference recomputes Key-Value (KV) activations for the entire prompt on every turn, driving up time-to-first-token (TTFT) and input token bills. Prepending dynamic elements (timestamps, session UUIDs, or un-anchored variables) breaks the shared prefix, causing a 0% KV cache hit rate and forcing full prefill recomputation.
Structure prompts in monotonically increasing order of dynamism: static system instructions -> tool definitions -> static reference documents -> conversation history -> dynamic user query. Keep prefixes bit-identical across requests and avoid dynamic variables before the cache breakpoint.
View implementation code →Production ready
ENG-16Cost
Reasoning token budgeting
Frontier reasoning models (OpenAI o1/o3, Claude 3.7 Thinking, Gemini Flash Thinking, DeepSeek-R1) generate chain-of-thought tokens during inference. Without explicit budgeting, queries burn thousands of thinking tokens on overthinking, hit API output token limits, trigger HTTP socket timeouts, and blow cost ceilings.
Allocate dedicated reasoning token budgets based on task complexity tiers. Reserve output token headroom so thinking does not truncate the final response, decouple client-side read timeouts to tolerate thinking latency, and strip obsolete 'think step-by-step' prompt wrappers.
View implementation code →Production ready
ENG-17Architecture
Dynamic tool routing
Exposing dozens or hundreds of tools in every agent prompt causes prompt bloat, inflates input token costs, degrades model reasoning, and increases tool hallucinations or misrouted invocations (needle-in-a-haystack tool selection problem).
Index all tool schemas in a semantic search registry. On each user turn, run a fast intent classification or semantic retrieval step to select the top-k relevant tools (e.g., 3-5 candidates) and inject only those schemas into the active LLM context window.
View implementation code →Production ready