Design patterns are named, reusable solutions to problems that come up again and again. Their biggest value is often the shared vocabulary: saying "use a strategy here" or "add a circuit breaker" communicates a whole design in a few words.
Patterns are tools, not goals. The best code uses them where they fit and avoids forcing them where a simpler solution works.
Creational patterns
These deal with how objects are created, adding flexibility and reuse.
- Factory
- Create objects without specifying their exact class, for example choosing a payment provider at runtime.
- Builder
- Construct complex objects step by step, keeping construction readable.
- Singleton
- Ensure a single instance. Use sparingly: it often hides dependencies and complicates testing.
Structural patterns
These describe how pieces fit together.
- Adapter
- Make an incompatible interface work with yours, such as wrapping a legacy API.
- Facade
- Offer a simple interface over a complex subsystem.
- Decorator
- Add behaviour, such as caching or logging, without changing the original code.
Behavioural patterns
These describe how objects interact and share responsibility.
- Strategy
- Swap algorithms at runtime, such as different pricing rules.
- Observer
- Notify subscribers when something changes; the basis of event-driven designs.
- Command
- Represent actions as objects, enabling queues, undo and audit.
Architectural and cloud patterns
Larger-scale patterns shape how distributed systems behave.
- Circuit breaker
- Stop calling a failing dependency for a while, so failures don't cascade.
- Retry with backoff
- Retry transient failures with increasing delays and limits.
- Saga
- Coordinate a business transaction across services with compensating actions.
- CQRS
- Separate models for writing and reading data, each optimised for its job.
- Strangler fig
- Replace a legacy system gradually by routing features to new components.
Using patterns well
Start from the problem, not the pattern. If a simple function solves it, use the simple function. Introduce a pattern when it removes duplication, makes change easier, or communicates intent clearly to the team. Name patterns in code and design documents so others recognise them.
Patterns and AI assistants
AI coding assistants know common patterns well and will often suggest them, sometimes where they aren't needed. Ask the assistant to explain why a pattern fits before accepting it, and include your team's preferred patterns and anti-patterns in the repository context file.
Patterns also help when prompting: "add a circuit breaker around the payment client" is a precise instruction that an assistant can follow reliably.
Anti-patterns to watch for
Some recurring designs cause more harm than good: the god object that knows everything, the distributed monolith where services must be deployed together, and chatty interfaces that need many calls to do one thing. Naming these in reviews helps teams spot and fix them early.
How to put it into practice
- Learn the most common patterns and their trade-offs as a team.
- Name patterns explicitly in code and ADRs where they are used.
- Apply resilience patterns such as timeouts, retries and circuit breakers to every remote call.
- Use the strangler fig pattern for legacy modernisation.
- Review pattern use in design reviews: does it simplify or complicate?
- Remove patterns that no longer earn their complexity.
Common mistakes
- Applying patterns to show sophistication rather than to solve a problem.
- Overusing singletons, which hide dependencies.
- Retries without backoff or limits, which turn small failures into outages.
- Distributed transactions where a saga or a simpler design would do.
How to measure progress
- Incidents caused by cascading failures between services.
- Time to add new variants of behaviour (for example a new provider).
- Code review comments about unnecessary complexity.
- Progress of legacy replacement using the strangler fig pattern.