🏗️ Real-World Patterns

System Design Mapping

Every design pattern, mapped to the real-world systems that use it. Spot patterns in Netflix, Google, Uber, Spring, Kafka — and understand why they made that choice.

Creational

Singleton

Ensure a class has only one instance, and provide a global point of access to it.

Guide →
HikariCPSpring FrameworkJava RuntimeRedisAndroid
  • HikariCP Database Connection Pool (Every major Java backend)
  • Spring ApplicationContext (Spring Framework)
  • +3 more — see pattern page
⚠️ Using Singleton for mutable shared state (e.g., a user session object or shopping cart) causes race conditions in multi-
Factory

Define an interface for creating objects, but let subclasses decide which class to instantiate.

Guide →
JDBC DriverManagerslf4jKubernetesFactory PatternSpring
  • JDBC DriverManager.getConnection() (Java Database Connectivity)
  • slf4j LoggerFactory.getLogger() (SLF4J / Logback / Log4j)
  • +2 more — see pattern page
⚠️ Hardcoding the 'new' keyword throughout codebase instead of centralizing object creation — makes it impossible to swap i
Builder Pattern

Separate construction from representation

Guide →
OkHttpApache HttpClientProtobufAvroJPA CriteriaQuery
  • OkHttp HttpRequest Builder (OkHttp HTTP Client)
  • Protobuf/Avro Schema Builder (Google Protobuf / Apache Avro)
  • +2 more — see pattern page
⚠️ Passing 15+ constructor parameters making objects hard to instantiate — Builder separates construction from representati
Prototype Pattern

Create objects by cloning an existing prototype

Guide →
JavaScript Object.create()ReduxSpring FrameworkGitDocker
  • JavaScript Object.create() cloning (JavaScript / Node.js)
  • Redux state cloning (Redux state management)
  • +2 more — see pattern page
⚠️ Shallow cloning objects containing nested references — modifications to nested objects affect the original, breaking imm

Structural

Adapter Pattern

Convert incompatible interfaces into compatible ones

Guide →
JDBC AdaptersSpring HandlerAdapterAWS SDKGoogle OAuthApache Commons
  • JDBC database adapters (JDBC drivers (MySQL, PostgreSQL, Oracle))
  • Spring DispatcherServlet HandlerAdapter (Spring Framework)
  • +2 more — see pattern page
⚠️ Creating adapters for every small incompatibility instead of standardizing interfaces — leads to adapter chains (Adapter
Bridge Pattern

Decouple abstraction from implementation so they can vary independently

Guide →
JDBCAWT/SwingAbstract Window ToolkitHibernateSpring Data
  • JDBC Driver/Connection bridge (JDBC API)
  • AWT/Swing platform abstraction (Java GUI frameworks)
  • +2 more — see pattern page
⚠️ Mixing abstraction and implementation (e.g., database-specific code in business logic) — Bridge prevents this, but only
Composite Pattern

Compose objects into tree structures to represent hierarchies

Guide →
ReactDOMLinux VFSSwing UIGit objects
  • React component tree (React / Facebook)
  • Browser DOM tree (HTML5 / All browsers)
  • +2 more — see pattern page
⚠️ Creating separate iteration logic for leaves vs. branches — the whole point of Composite is to treat them uniformly and
Decorator Pattern

Add responsibilities to objects dynamically

Guide →
Java I/O StreamsExpress middlewareServlet filtersPython functools
  • Java InputStream chains (Java Standard Library)
  • Express middleware (Express.js / Node.js)
  • +3 more — see pattern page
⚠️ Subclassing instead of decorating — leads to explosive class hierarchies (BufferedSortedGZIPInputStream, BufferedGZIPSor
Facade

Provide a simplified interface to a complex subsystem of classes.

Guide →
Spring JdbcTemplateAWS SDKREST API gatewaysServletOpenGL
  • Spring JdbcTemplate (Spring Framework)
  • AWS SDK high-level APIs (AWS SDKs)
  • +2 more — see pattern page
⚠️ Over-simplifying facades that hide necessary domain complexity — developers then fight the abstraction, leading to "if o
Flyweight Pattern

Share fine-grained objects efficiently to reduce memory usage

Guide →
Java String poolDOM renderingFont cachingRedis caching
  • Java String interning pool (Java Virtual Machine)
  • Browser DOM text node pooling (V8 / SpiderMonkey / JavaScriptCore)
  • +2 more — see pattern page
⚠️ Flyweighting mutable objects — if shared state is modified, all references see the change, causing hard-to-debug distrib
Proxy Pattern

Control access to another object through a surrogate

Guide →
Spring AOPHibernateCloudflare CDNJava RMIgRPC
  • Spring AOP @Transactional proxy (Spring Framework)
  • Hibernate lazy-loaded entities (Hibernate ORM)
  • +3 more — see pattern page
⚠️ Proxies hiding too much complexity — clients don't know if a call is local or remote, leading to unexpected latency, net

Behavioral

Command

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

Guide →
Git commit historyRedux actionsTransaction logsCQRSKafka
  • Git commit history (Git / GitHub)
  • Redux action dispatching (Redux state management)
  • +2 more — see pattern page
⚠️ Commands that trigger side effects during construction instead of execution — makes undo/retry impossible and breaks sep
Iterator

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

Guide →
Java IteratorPython generatorsSQL cursorsStreaming APIs
  • Java Iterator interface (Java Collections Framework)
  • Python generators with yield (Python Standard Library)
  • +2 more — see pattern page
⚠️ Modifying collections while iterating — causes ConcurrentModificationException or undefined behavior instead of using It
Mediator

Define an object that encapsulates how a set of objects interact

Guide →
Kubernetes control planeRedux storeReact ContextMessage brokers
  • Kubernetes control plane (Kubernetes)
  • Redux central store (Redux state management)
  • +2 more — see pattern page
⚠️ Making the mediator a bottleneck with too much responsibility — God mediator becomes a performance and maintenance night
Memento

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

Guide →
Browser historyPhotoshop undoGit stashDatabase snapshots
  • Browser history stack (Chrome, Firefox, Safari)
  • Photoshop undo history (Adobe Photoshop)
  • +2 more — see pattern page
⚠️ Storing full object graphs as mementos — causes memory explosion and slow serialization; use delta-based snapshots inste
Observer

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

Guide →
Kafka consumersReact hooksAndroid LiveDataDOM events
  • Kafka consumer groups (Apache Kafka)
  • React useState hooks (React / Facebook)
  • +3 more — see pattern page
⚠️ Observer leaks from missing unsubscribe — listeners accumulate in memory, causing application slowdown and multiple exec
State

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

Guide →
TCP connection statesRedux reducersNetflix playerSpring StatefulEJB
  • TCP connection state machine (Kernel / POSIX sockets)
  • Redux reducers (Redux state management)
  • +2 more — see pattern page
⚠️ Large if/else chains checking state instead of delegating to state objects — leads to fragile, hard-to-extend state tran
Strategy

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

Guide →
Java ComparatorPayment processorsCompression algorithmsSorting engines
  • Java Comparator interface (Java Collections Framework)
  • Payment processor strategies (Stripe, PayPal, Square)
  • +2 more — see pattern page
⚠️ Hardcoding algorithm choice instead of making it pluggable — forces code changes for every new strategy and breaks Open/
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

Guide →
Java compiler ASTDocument exportersTax calculation systemsJSON serializers
  • Java compiler AST visitors (javac / Eclipse Compiler)
  • Document format exporters (LibreOffice, Word, Google Docs)
  • +2 more — see pattern page
⚠️ Adding visit methods to Visitor interface every time you add a new element type — violates Open/Closed; use dynamic disp

AI Agent & LLM

RAG

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

Guide →
ChatGPTPerplexity AIGitHub CopilotLangChainClaude
  • ChatGPT knowledge base retrieval (OpenAI)
  • Perplexity.AI web search integration (Perplexity AI)
  • +3 more — see pattern page
⚠️ Retrieving too many irrelevant documents and overwhelming the LLM context — dilutes relevant signal and increases halluc
Reflection

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

Guide →
ClaudeOpenAI GPT modelsSelf-refining loopsAnthropic research
  • Claude self-reflection (Anthropic)
  • OpenAI self-refining chains (OpenAI)
  • +2 more — see pattern page
⚠️ Reflection loops that endlessly second-guess themselves without external validation — converges to overthinking rather t
Memory

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

Guide →
LangChain memoryOpenAI AssistantsAnthropic extended contextVector databases
  • LangChain conversation memory (LangChain)
  • OpenAI Assistants persistent memory (OpenAI)
  • +3 more — see pattern page
⚠️ Unbounded memory growth — contexts explode in size, slowing inference and increasing hallucination risk.
Guardrails

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

Guide →
OpenAI moderation APIAnthropic Constitutional AILangChain validatorsGuardrails AI
  • OpenAI moderation API (OpenAI)
  • Anthropic Constitutional AI (Anthropic)
  • +3 more — see pattern page
⚠️ Single-layer guardrails without defense in depth — determined attackers bypass basic checks and exploit unprotected path

ML System & MLOps

Ready to practice?

Test your knowledge with FAANG-style interview questions.

Go to Top Practice Questions →