Patterns for Gos
Concurrency patterns are proven ways of structuring goroutines: worker pools, fan-out and fan-in, pipelines, and cancellation with context.Context. Avoiding bugs means recognising data races, deadlocks and goroutine leaks, and using tools such as the race detector to find them before production.
Stage: Concurrency · Part of the Go roadmap · Last reviewed 19 November 2026
What to learn in Patterns
- Build a worker pool that processes jobs from a channel
- Cancel work across goroutines using context with timeout
- Chain stages into a pipeline using channels
- Run go test -race to detect a data race
- Spot a goroutine leak caused by a blocked channel send
Patterns interview questions
How does context.Context help with cancellation?
A context carries a cancellation signal, deadline and request-scoped values down a call chain. Goroutines select on ctx.Done() and return when it closes, so a timeout or client disconnect stops work and frees resources.
What causes a goroutine leak?
A goroutine leaks when it blocks forever, for example waiting on a channel nobody sends to, or sending with no receiver. It never exits, keeping memory alive. Use context cancellation, buffered channels or closing channels to give it a way out.
Where Patterns fits in the Go roadmap
Patterns belongs to the Concurrency stage (intermediate level), which takes about 20 hours. Go's strength.