☰ All patterns
Worker Pool
A fixed team of goroutines chewing through a queue of jobs.
01
Explain it like I'm new
Real-life analogy
Checkout lanes at a supermarket
There are 3 cashiers and a queue of customers. Each free cashier takes the next customer. More customers? The queue gets longer, but you never hire 1,000 cashiers.
😩 The problem
You have 10,000 images to resize. One goroutine per image could overwhelm memory, CPU or a downstream API.
💡 The pattern
Start N workers that range over a jobs channel and send to a results channel. Close jobs when done, and wait with a WaitGroup.
02
Play with it
An interactive model of the pattern. Click around, nothing can break.
jobs channel (0)
results (0)
💡 Try 1 worker vs 6 workers. More workers = faster, up to a point. In real life the limit is CPU, memory or the API you're calling.
03
Walk through the code
Click a step to highlight its lines. This is a complete program you can copy and run.
Press ▶ Run to execute this program.This output was captured by running the program with Go 1.24. Copy it into your editor or the Go Playground and try changing things.
04
When should I use it?
✅ Reach for it when…
- •Batch processing, crawling, resizing, sending emails, anything with many similar jobs.
🚫 Skip it when…
- •There are only a few jobs. Just start a goroutine per job.
🐹 Go tip
golang.org/x/sync/errgroup with g.SetLimit(n) gives you a worker pool with error handling in a few lines.
🌍 You've already seen it in
Background job runners, image pipelines, and database migration tools that process rows in batches.
05
Quick check
One question. No pressure.
Why do we close(jobs) after sending all jobs?
Related: Semaphore, Fan-out / Fan-in, Pipeline