📋 Quick Reference

Pattern Cheat Sheet

All 37 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

8 patterns
RAG

Ground LLM responses in real data by retrieving relevant documents before generating an answer.

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

Enable LLMs to call functions and external tools to expand their capabilities.

Tasks require real-time data or calculations

You need to integrate with external APIs or databases

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

ML System & MLOps Patterns

7 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
Difficulty: Beginner Intermediate AdvancedClick any card to open the full pattern guide