Design Patterns & Best Practices in Go
Real Go implementations of the full Gang of Four catalog, written around small interfaces, composition, concurrency safety, and explicit errors.
Interactive Architecture Walkthroughs
Step through each pattern one node at a time — the diagram highlights the active component while the narrator panel explains its role in the architecture.
creational
Singleton Pattern
Use sync.Once carefully for one-time initialization, and understand when dependency injection is a better fit.
structural
Decorator
Add behavior around an object dynamically by wrapping it with small focused layers that share the same interface.
behavioral
Observer
Notify dependent subscribers when state changes so event-driven reactions stay decoupled from the publisher.
Pattern Categories
Go still uses creational, structural, and behavioral patterns, but it adapts them through interfaces and composition instead of inheritance-heavy class hierarchies.
Creational
5 patternsPatterns for object creation in Go, usually expressed through constructor functions, interfaces, and functional options.
Explore patternsStructural
7 patternsPatterns for composing types and boundaries in Go with interfaces, embedding, adapters, and focused packages.
Explore patternsBehavioral
10 patternsPatterns for organizing control flow, workflows, and collaboration with explicit errors, interfaces, and small units of behavior.
Explore patternsAgentic
8 patternsPatterns for building AI agent systems in Go: reasoning loops, tool dispatch, memory, retrieval, and multi-agent coordination.
Explore patternsPublished Go Articles
Each article includes working Go source, Go-specific tradeoffs, and guidance on when the pattern helps or hurts.
Abstract Factory in Go
Create related objects through one factory so whole product families can change together without leaking concrete types.
Builder in Go
Separate a multi-step construction workflow from the final representation so the same input can produce different outputs cleanly.
Factory Method in Go
Use constructor functions and small interfaces to select concrete implementations without coupling callers to them.
Prototype Pattern in Go
Clone preconfigured object graphs when copying is simpler or faster than rebuilding the same structure from scratch.
Singleton Pattern in Go
Use sync.Once carefully for one-time initialization, and understand when dependency injection is a better fit.
Adapter in Go
Wrap an incompatible API behind the interface your application already expects so the rest of the code stays unchanged.