21 patterns · every example is a real, runnable Go program
Go Design Patterns
for Noobs
Learn the patterns Go developers actually use, explained with coffee machines and pizza orders instead of jargon. Then play with them, step through real code, and quiz yourself.
- 21
- patterns
- 10
- playgrounds
- 0
- jargon walls
$ go run ./singleton
Your learning journey starts here
Progress is saved in this browser. Mark a pattern as learned at the bottom of each lesson.
How every lesson works
- 01
Real-life analogy
Every pattern starts with an everyday story, before any code.
- 02
Play with it
Click, drag and toggle an interactive model of the pattern.
- 03
Code walkthrough
Step through a complete Go program, line by line.
- 04
Run & quiz
See the real output, then check yourself with a quick quiz.
Creational patterns
How things get made.
Control and simplify object creation.
Singleton→
Exactly one instance, shared by everyone, created safely.
Like the office coffee machine
Factory→
Ask for what you want; let a function decide how to build it.
Like ordering at a restaurant
Builder→
Build a complicated object step by step, then validate once.
Like building your own pizza
Functional Options→
Go's favourite way to make constructors with optional settings.
Like customising a coffee order
Prototype→
Make new objects by cloning an existing one, deeply.
Like photocopying a form
Structural patterns
How things fit together.
Compose types into bigger structures.
Adapter→
Make an incompatible type fit the interface you expect.
Like a travel plug adapter
Decorator→
Wrap behaviour in layers to add features without changing it.
Like gift wrapping
Facade→
One simple front door to a complicated system.
Like a hotel concierge
Proxy→
A stand-in that controls access to the real thing.
Like a personal assistant
Composite→
Treat single items and groups of items the same way.
Like boxes inside boxes
Behavioral patterns
How things talk.
Organise responsibilities and communication.
Strategy→
Swap algorithms at runtime behind one interface.
Like getting to the airport
Observer→
Notify many subscribers automatically when something happens.
Like subscribing to a youtube channel
Command→
Turn actions into objects so you can queue, log and undo them.
Like a restaurant order ticket
State→
Let an object change its behaviour when its internal state changes.
Like a traffic light
Chain of Responsibility→
Pass a request along a chain until someone handles or rejects it.
Like airport security
Iterator→
Loop over any collection with `for range` (Go 1.23+).
Like a pez dispenser
Concurrency patterns
Go's superpower.
Goroutines and channels working together safely.
Worker Pool→
A fixed team of goroutines chewing through a queue of jobs.
Like checkout lanes at a supermarket
Pipeline→
Chain stages with channels so data flows through like an assembly line.
Like a car assembly line
Fan-out / Fan-in→
Split work across many goroutines, then merge the results into one channel.
Like a group project
Context Cancellation→
Tell goroutines to stop: timeouts, deadlines and manual cancel.
Like a kitchen timer and a cancelled order
Semaphore→
Limit how many goroutines do something at the same time.
Like a nightclub bouncer
Pattern finder
Don't know the name? Describe the problem.
Patterns are just names for solutions to common problems. Type what you're trying to do and we'll point you at the pattern that solves it.
Already know a few? Take the 10-question quiz →- …have only one shared config / database connectionSingletonCreational
- …hide which concrete type gets createdFactoryCreational
- …give a constructor optional parameters with defaultsFunctional OptionsCreational
- …create objects from a templatePrototypeCreational
- …add logging, auth or timing around existing codeDecoratorStructural
- …give callers an easy APIFacadeStructural
- …work with tree structures like folders or menusCompositeStructural
- …replace a big if/else on 'type'StrategyBehavioral