Intermediate

Pattern Selection Guide

You have learned 12 AI design patterns throughout this course. Now comes the most important skill: knowing which pattern to apply, when to combine them, and when to keep things simple. This guide gives you practical decision frameworks for real-world AI system design.

Decision Flowchart for Choosing Patterns

Start here when designing a new AI feature or system. Ask these questions in order:

  1. Does the AI need external knowledge? → Yes: Start with RAG. No: Continue.
  2. Does the AI need to take actions or use tools? → Yes: Use the Agent pattern. No: Continue.
  3. Is the task a multi-step pipeline? → Yes: Use Prompt Chaining. No: Continue.
  4. Are there multiple task types that need different handling? → Yes: Use the Router pattern. No: Continue.
  5. Is cost a major concern? → Yes: Use Cascade (cheap model first). Add Caching.
  6. Is accuracy critical and errors are costly? → Yes: Use Ensemble and/or Human-in-the-Loop.
  7. Is safety a concern (user-facing, regulated)? → Yes: Add Guardrails.
  8. Is the input too large for one context window? → Yes: Use Fan-out/Fan-in.
  9. Is processing slow or asynchronous? → Yes: Use Event-Driven and/or Streaming.
💡
Most systems use 2-4 patterns: It is rare for a production AI system to use only one pattern. A typical customer support bot might use RAG + Router + Guardrails + Cache. Start with the primary pattern that addresses your core challenge, then layer in supporting patterns as needed.

"I Need To..." Pattern Mapping

Find your scenario in this table to identify the best pattern(s):

I Need To... Primary Pattern Supporting Patterns
Answer questions from my documents RAG Cache, Guardrails
Build a chatbot that takes actions Agent HITL, Guardrails
Process documents through multiple steps Prompt Chaining Fan-out/Fan-in, Event-Driven
Handle different types of user requests Router Cascade, Cache
Minimize AI costs at scale Cascade + Cache Distillation, Batch
Ensure AI safety for users Guardrails HITL, Monitoring
Get the highest possible accuracy Ensemble HITL, Guardrails
Handle AI decisions with real consequences HITL Guardrails, Cascade
Process very large documents Fan-out/Fan-in Cache, Event-Driven
Build real-time AI features Streaming Cache, Router
Process files/events asynchronously Event-Driven Fan-out/Fan-in, Cache
Provide AI-powered search RAG Cache, Router
Moderate user-generated content Guardrails + Cascade HITL, Event-Driven
Generate reports from data Prompt Chaining Cache, Fan-out/Fan-in
Translate content at scale Fan-out/Fan-in Cache, Batch
Build a code review tool Agent + Prompt Chaining Guardrails, Event-Driven
Create personalized recommendations RAG + Router Cache, Ensemble
Handle multi-language support Router Cache, Cascade
Detect fraud or anomalies Ensemble + HITL Event-Driven, Guardrails
Summarize meetings or calls Prompt Chaining Fan-out/Fan-in, Cache

Combining Patterns: Proven Combinations

Some pattern combinations work exceptionally well together. Here are the most effective combinations used in production:

RAG + Guardrails + Cache

The standard stack for any knowledge-based AI application. RAG provides accurate, grounded answers from your documents. Guardrails prevent hallucination, PII leakage, and prompt injection. Cache reduces costs for frequently asked questions. Used by: customer support bots, documentation assistants, internal knowledge bases.

Agent + HITL + Cascade

For autonomous systems that take real-world actions. The Agent handles tool use and multi-step reasoning. HITL provides human oversight for high-stakes actions (purchases, deletions, communications). Cascade optimizes cost by using a cheap model for simple agent decisions and escalating to a powerful model for complex ones. Used by: sales automation, DevOps agents, research assistants.

Router + Cascade + Cache

The cost optimization stack. The Router identifies the request type and routes to the appropriate handler. Cascade tries the cheapest model first for each route. Cache prevents redundant calls for similar requests. This combination can reduce AI costs by 80%+ compared to sending everything to the most expensive model.

Fan-out/Fan-in + Event-Driven + Guardrails

For large-scale document processing pipelines. Event-Driven triggers processing on file upload. Fan-out/Fan-in splits large documents for parallel processing. Guardrails validate each chunk's output. Used by: legal document analysis, compliance review, content migration.

Pattern Compatibility Matrix

Not all patterns combine well. This matrix shows which patterns work together and which create conflicts:

Pattern Works Great With Works But Complex Avoid Combining
RAG Cache, Guardrails, Router Agent, Ensemble -
Agent HITL, Guardrails, Cascade Fan-out/Fan-in Ensemble (too slow)
Prompt Chaining Guardrails, Cache, Router Fan-out/Fan-in, HITL -
Cascade Router, Cache, HITL Ensemble, Agent -
Ensemble HITL, Guardrails Cache, Router Cascade (conflicting goals)
Fan-out/Fan-in Event-Driven, Cache Guardrails, HITL Agent (complex state)

Anti-Patterns to Avoid

Knowing what not to do is just as important as knowing what to do. Avoid these common mistakes:

Over-Engineering (Pattern Soup)

Using too many patterns when a simple prompt would suffice. If your use case is "answer a question given some context," a single LLM call with the context in the prompt may be all you need. Do not add RAG, Router, Cascade, Ensemble, and Guardrails just because they exist. Each pattern adds complexity, latency, and potential failure points.

Premature Optimization

Adding caching, distillation, or batch processing before you understand your traffic patterns. Start with the simplest architecture that works, measure performance, then optimize the bottlenecks you actually observe.

Guardrails as an Afterthought

Building the entire system first and then trying to bolt on safety. Guardrails should be part of the design from day one, not an emergency addition after the first incident.

HITL Without Feedback Loops

Having human reviewers correct AI outputs but never using those corrections to improve the model. Without active learning, the same errors keep recurring and review costs never decrease.

Ignoring Cost Until the Bill Arrives

Not estimating or monitoring AI costs during development. A pattern that works beautifully in testing with 100 requests per day can bankrupt you at 100,000 requests per day. Always calculate the cost per request and extrapolate to expected production volumes.

⚠️
The simplicity rule: Start with the simplest pattern that could possibly work. Add complexity only when the simple approach fails to meet a specific, measurable requirement. Document why each pattern was added and what problem it solves, so future developers understand the architecture's rationale.

Real-World Application Architectures

Here are three complete architectures for common AI applications, showing how patterns combine in practice:

Customer Support Bot

Patterns: Router + RAG + Cascade + Guardrails + Cache + Streaming

  1. Input guardrails check for PII and injection attacks
  2. Router classifies the request: FAQ, technical support, billing, or escalation
  3. Cache checks for a similar recent question and returns the cached answer if found
  4. RAG retrieves relevant knowledge base articles for the classified category
  5. Cascade tries a fast, cheap model first; escalates to a powerful model if the response quality is low
  6. Output guardrails verify the response is accurate, non-toxic, and on-topic
  7. Streaming delivers the response token-by-token for a responsive chat experience

Document Processing System

Patterns: Event-Driven + Fan-out/Fan-in + Prompt Chaining + Guardrails + Cache

  1. Event trigger: File upload to S3 triggers a processing event
  2. Fan-out: Large documents are chunked and processed in parallel
  3. Prompt chaining: Each chunk goes through extract → classify → summarize steps
  4. Fan-in: All chunk results are merged into a unified report
  5. Guardrails: Validate extracted data, check for PII, verify output format
  6. Cache: Store processed results to avoid reprocessing the same document
  7. Event notification: Publish a completion event with the results

Content Moderation Pipeline

Patterns: Cascade + Guardrails + HITL + Event-Driven + Ensemble

  1. Cascade layer 1: Fast classifier flags obviously safe content (auto-approve) and obviously harmful content (auto-remove)
  2. Cascade layer 2: Borderline content goes to a more powerful model for nuanced analysis
  3. Ensemble: For the most ambiguous cases, run multiple models and take a vote
  4. HITL: Cases where ensemble models disagree go to human moderators
  5. Guardrails: Safety checks on all automated decisions before they take effect
  6. Event-Driven: All decisions are logged as events for audit and model retraining

Cost-Performance Matrix

Pattern Implementation Cost Runtime Cost Impact Latency Impact Quality Impact
RAG Medium (vector DB, embeddings) +20% (embedding + retrieval) +200-500ms High improvement
Agent High (tools, safety) +100-500% (multi-step) +2-30s High (for complex tasks)
Prompt Chaining Low-Medium +50-200% (multiple calls) +1-10s Medium improvement
Router Low +5-10% (classification) +100-300ms Medium (better routing)
Cascade Medium -40-70% (cost savings) Varies Maintained or slight decrease
Ensemble Low-Medium +200-500% (N models) +0 (parallel) or +Nx High improvement
HITL High (UI, workflow) +$1-50 per review +minutes to hours Highest
Guardrails Medium +10-30% +100-500ms Safety improvement
Cache Low-Medium -30-70% (savings) -90% (cache hits) Maintained
Fan-out/Fan-in Medium +10-20% (merge step) -50-80% (parallel) Maintained
Event-Driven High (infrastructure) Neutral Async (no user wait) Maintained

Getting Started Checklist

When building a new AI system, follow this checklist to choose and implement the right patterns:

  1. Define the problem clearly: What is the AI doing? What inputs does it receive? What output does it produce? What are the quality requirements?
  2. Estimate volume and budget: How many requests per day? What is the acceptable cost per request? What is the latency budget?
  3. Identify the primary pattern: Use the decision flowchart above. Pick the one pattern that addresses your core challenge.
  4. Build a simple prototype: Implement the primary pattern with the simplest possible architecture. Get it working end-to-end.
  5. Measure and evaluate: Test with real data. Measure accuracy, latency, cost per request, and error rates.
  6. Add safety early: Implement basic guardrails (input validation, output filtering) before any user testing.
  7. Add supporting patterns incrementally: Based on measurement results, add one pattern at a time to address specific gaps.
  8. Monitor in production: Track cost, latency, error rates, and user satisfaction continuously. Set up alerts for anomalies.
  9. Iterate based on data: Use production metrics to refine thresholds, update guardrails, and tune the architecture over time.
Congratulations! You have completed the AI Design Patterns course. You now have a comprehensive understanding of the 12 core patterns used to build production-grade AI systems: RAG, Agent, Prompt Chaining, Router, Cascade, Ensemble, Human-in-the-Loop, Guardrails, Cache, Fan-out/Fan-in, Event-Driven, and this Pattern Selection Guide. The key to mastery is applying these patterns in real projects - start with the simplest pattern that works, measure everything, and evolve your architecture based on data.

Next Steps

Now that you have completed this course, here are recommended paths to continue your AI learning:

  • AI Architecture: Dive deeper into the neural network architectures (Transformers, CNNs, RNNs) that power the models these patterns wrap around.
  • Multi-Model Apps: Learn how to build applications that use multiple AI models together, a natural extension of patterns like Router, Ensemble, and Cascade.
  • Deep Learning: Understand the fundamentals of how AI models are trained, which helps you make better decisions about distillation, fine-tuning, and model selection.
  • LLM Models: Explore the landscape of available LLMs, their capabilities, and their pricing - essential knowledge for choosing the right models in your pattern implementations.

Ready to Go Deeper?

Live instructor-led courses from our partners. Affiliate disclosure.