📋 Quick Reference

Pattern Cheat Sheet

All 58 patterns on one page. Keep this open during architecture reviews, system design interviews, or code review sessions.

Creational — How objects are created

5 patterns

Structural — How objects are composed

7 patterns
Adapter Pattern●

Convert incompatible interfaces into compatible ones

→Integrating with third-party libraries that have incompatible interfaces

→Working with legacy code that you cannot or should not modify

interface-conversionintegration
Bridge Pattern●

Decouple abstraction from implementation so they can vary independently

→Separating abstraction from implementation when both should be extensible independently

→Avoiding permanent binding between abstraction and implementation

decouplingabstraction-implementation
Composite Pattern●

Compose objects into tree structures to represent hierarchies

→Building hierarchical tree structures (file systems, organizational charts, UI components)

→When you need to treat individual objects and groups of objects identically

tree-structurehierarchy
Decorator Pattern●

Add responsibilities to objects dynamically

→Adding features to objects without modifying their original class

→Creating flexible combinations of behaviors (coffee with milk, sugar, and chocolate)

behavior-extensioncomposition
Facade●

Provide a simplified interface to a complex subsystem of classes.

→A subsystem is complex and most callers only need a simple subset of its functionality.

→You want to layer your architecture — expose a clean API while hiding implementation details.

structuralsimplification
Flyweight Pattern●

Share fine-grained objects efficiently to reduce memory usage

→Creating many similar objects where memory is a concern

→Objects have much shareable (intrinsic) state vs. unique (extrinsic) state

memory-optimizationobject-sharing
Proxy Pattern●

Control access to another object through a surrogate

→Lazy loading: delay expensive object creation until actually needed

→Access control: restrict who can use an object or what they can do

lazy-loadingaccess-control

Behavioral — How objects communicate

10 patterns
Chain of Responsibility●

Pass a request along a chain of handlers. Each handler decides either to process the request or pass it along the chain

→Multiple objects can handle a request and the handler isn't known in advance

→Request handlers should be determined dynamically at runtime

handler-chainrequest-passing
Command●

Encapsulate a request as an object, allowing you to parameterize clients with different requests, queue them, and log them

→You need to queue requests and execute them later

→Implementing undo/redo functionality

encapsulationundo-redo
Iterator●

Provide a way to access the elements of an object sequentially without exposing its underlying representation

→You need to access collection elements without exposing the internal structure

→You want to support multiple simultaneous traversals of the same collection

sequential-accessencapsulation
Mediator●

Define an object that encapsulates how a set of objects interact

→Objects have many interdependencies creating complex communication

→You want to decouple objects from directly knowing each other

centralized-controldecoupling
Memento●

Capture and externalize an object's internal state without violating encapsulation, allowing it to be restored later

→You need undo/redo functionality

→You want to save and restore object state

state-captureundo-redo
Observer●

Define a one-to-many dependency where when one object changes state, all its dependents are notified automatically

→You need to notify multiple objects when state changes occur

→Objects interested in updates don't know each other in advance

event-drivenpublish-subscribe
State●

Allow an object to alter its behavior when its internal state changes

→Object behavior depends on state and changes at runtime

→You have many conditional statements (if/else or switch) based on state

state-machinebehavior-modification
Strategy●

Define a family of algorithms, encapsulate each one, and make them interchangeable

→You have multiple ways to solve a problem and need to select at runtime

→You want to avoid conditional statements (if/else or switch) scattered throughout code

interchangeablealgorithms
Template Method●

Define the skeleton of an algorithm in a base class, deferring some steps to subclasses

→Multiple classes implement similar algorithms with slight variations

→You want to avoid code duplication of common algorithm structure

algorithm-structureinheritance
Visitor●

Represent an operation to be performed on elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates

→You have a complex object structure with many different element types

→You need many different, unrelated operations on the structure

double-dispatchoperation-separation

AI Agent & LLM Patterns

18 patterns
Agent Handoffs●

One agent transfers full conversational control to a specialized peer — the receiving agent takes over completely, with context, not just a subtask.

→A general agent needs to route to a specialist who will own the entire conversation going forward

→Different topics within one product need different system prompts, tools, or model tiers

handoffsdelegation
RAG●

Prevent hallucinations and stale answers by retrieving real, relevant documents before the LLM generates a response.

→You need up-to-date information beyond the LLM's training data

→Domain-specific or proprietary knowledge is critical

retrievalgrounding
Chain of Thought●

Break down complex problems into step-by-step reasoning to improve answer quality.

→Problems require multi-step reasoning or mathematical calculations

→Questions involve logic, planning, or causal reasoning

reasoningstep-by-step
ReAct●

Combine reasoning and action: think through steps and execute tools to solve tasks.

→Tasks require gathering information from external sources

→Actions must be taken based on intermediate reasoning

reasoningaction
Tool Use●

Give LLMs the ability to call real functions — search the web, run code, query databases, and interact with APIs autonomously.

→Tasks require real-time data the LLM can't know (weather, stock prices, live search)

→You need deterministic, testable execution — e.g. exact database queries, calculations

function-callingtools
Multi-Agent●

Coordinate multiple specialized agents working together to solve complex problems.

→Tasks require diverse expertise (research, coding, design, review)

→Different subtasks would benefit from specialized agents

orchestrationspecialization
Reflection●

Generate, critique, and refine outputs iteratively to improve quality.

→Quality is more important than speed (creative writing, analysis)

→Complex tasks benefit from revision (code generation, essays)

self-critiqueiterative-refinement
Memory●

Maintain context across interactions using short-term and long-term memory systems.

→Multi-turn conversations longer than context window

→Agents need to learn from interactions across sessions

contextstate-management
Guardrails●

Validate inputs and outputs to ensure safety, quality, and compliance.

→Safety and content moderation are critical

→Regulatory compliance is required (HIPAA, GDPR)

safetyvalidation
Structured Output●

Constrain LLM responses to a schema so downstream code can reliably parse and act on them.

→You need to extract specific fields from unstructured text

→Downstream code must act on LLM output programmatically

json-modeschema
Human-in-the-Loop●

Pause agent execution and hand off to a human when confidence is low, stakes are high, or an action is irreversible.

→The agent is about to perform an irreversible action (delete, send, charge, deploy)

→Confidence score falls below a safe threshold

safetyoversight
Router●

Classify incoming requests and direct them to the best-fit model, agent, or handler.

→You have multiple models with different cost/capability trade-offs

→Different request types benefit from specialized agents or prompts

routingclassification
Prompt Template●

Separate prompt structure from dynamic content to build reusable, testable, and versionable LLM instructions.

→The same prompt structure is reused with different inputs across the codebase

→You need to version, A/B test, or iterate on prompts without touching application code

promptingtemplates
Context Management●

Keep what's relevant in the limited context window and evict the rest — without losing coherence.

→Conversations or agentic loops that run longer than a few exchanges

→Document Q&A where the source is larger than the context window

context-windowmemory
Scatter-Gather●

Fan out a task to multiple agents or tools in parallel, then synthesize their results into a single answer.

→Tasks decompose into independent subtasks with no data dependencies between them

→You need information from multiple sources simultaneously (search, databases, APIs)

parallelismorchestration
Fallback●

Gracefully degrade when a model or tool fails — retry, switch providers, or return a safe default.

→Your AI feature must stay available even during provider outages

→You're calling external tools or APIs that can fail

resiliencereliability
Orchestrator-Worker●

One coordinator plans and delegates; many stateless workers execute — then results flow back up.

→Tasks decompose cleanly into independent, parallelizable subtasks

→Different subtasks require different tools, expertise, or model tiers

orchestrationdelegation
Streaming●

Emit LLM tokens to the client as they're generated — don't wait for the full response.

→Any user-facing AI feature where the response takes more than 1–2 seconds

→Chat interfaces, writing assistants, code generation — anywhere the user reads while the model writes

ssestreaming

ML System & MLOps Patterns

8 patterns
Feature Store●

Centralize feature computation, storage, and serving so training and inference always use the exact same data.

→Multiple models sharing overlapping feature sets

→Strict SLA on serving latency (need pre-computed online features)

mlopsdata-engineering
Model Registry●

A versioned catalog of trained ML models with metadata, lineage, and stage transitions from staging to production.

→Multiple models in production (need to track which is deployed)

→Regulatory compliance requires audit trail of model decisions

mlopsmodel-management
Training Pipeline●

Automated, reproducible workflows that ingest data, train models, evaluate them, and register successful runs.

→Regular retraining needed (daily/weekly as new data arrives)

→Multiple models being trained independently (consolidate into one pipeline)

mlopsautomation
Serving Pipeline●

Deploy ML models behind a scalable, low-latency API that handles feature lookup, prediction, and response transformation.

→Real-time predictions needed (< 100ms SLA)

→High QPS (queries per second) requiring horizontal scaling

mlopsinference
Data Versioning●

Track datasets like code with immutable versions so any model run can be reproduced months later.

→Models require reproducibility (audit trail, regulatory compliance)

→Frequently retraining with new data versions

mlopsreproducibility
Model Monitoring●

Continuously track model performance, input distributions, and prediction drift to catch silent failures in production.

→Models in production serving real users

→Need to detect silent failures (accuracy degradation without labels)

mlopsobservability
A/B Testing●

Safely roll out new models by routing a fraction of traffic to the candidate and comparing business metrics against the control.

→Deploying a new model to production with business impact

→Want to prove statistical significance before promoting

mlopsexperimentation
Fine-Tuning●

Train a base model further on your own data to improve quality, consistency, or efficiency on a specific task.

→You have 50–1000+ high-quality labeled examples for a specific task

→Prompt engineering isn't achieving the quality or consistency you need

fine-tuningtraining
Difficulty:● Beginner● Intermediate● AdvancedClick any card to open the full pattern guide