Production Go combines goroutines, channels, context, and worker pools. Patterns appear in observability agents, API gateways, and Kubernetes controllers.
Common patterns
- Worker pool — fixed goroutines reading jobs from a channel
- Fan-out / fan-in — split work across goroutines, merge results
- Pipeline — stages connected by channels
- errgroup — coordinate goroutines with first error cancellation (stdlib
golang.org/x/sync/errgrouplocally)
Pitfalls
Goroutine leaks from blocked sends/receives, forgotten WaitGroups, or ignoring context cancellation—always plan shutdown paths.
Important interview questions and answers
- Q: How prevent goroutine leaks?
A: Use context cancellation, buffered channels or extra receivers, and ensure WaitGroups complete. - Q: Worker pool benefit?
A: Limits concurrency—protects DB connections and CPU under load spikes.
Self-check
- Name two concurrency patterns used in services.
- What causes a goroutine leak?
Pitfall: Goroutine leaks from blocked channel ops—always design shutdown: close jobs, cancel context, or use buffered channels with care.
Interview prep
- Worker pool benefit?
Limits concurrency—protects DB connections and CPU under load.
- Goroutine leak causes?
Blocked send/receive, forgotten WaitGroup, ignored context cancellation.