Go for Infrastructure
Worker pools
A worker pool bounds concurrency with a fixed number of goroutines reading jobs from one channel.
What you will be able to do
- Build a pool that closes its channels in the right places
- Add cancellation so workers do not leak
What is in the lesson
- A real situation where this goes wrong
- How it works, step by step
- A command to try yourself
- How it fails in production, and how to tell
- Three quiz questions with explanations
Read this lessonFree. No account needed.
More in Go for Infrastructure
- Atomic operationsBeginner · 4 min
sync/atomic performs a read-modify-write on one value as a single indivisible operation.
- Race detectorBeginner · 4 min
Go’s race detector reports certain unsynchronized accesses in code paths exercised by a run.
- Bounded concurrencyBeginner · 4 min
Bounded concurrency limits how many operations are active while a separate queue holds waiting work.
- Backpressure in GoBeginner · 4 min
Explain backpressure in Go as a bounded channel or semaphore that makes fast producers wait, so queued work cannot grow memory without limit during a traffic spike.
- HTTP server timeoutsBeginner · 4 min
Explain what each net/http server timeout limits, and set them so slow or stalled clients cannot hold connections and goroutines open indefinitely on a public API.
- net/http transportBeginner · 4 min
Explain how the Go HTTP transport pools idle connections, why a per-request client causes churn, and how to size the pool and drain bodies so connections are reused.