Design a graceful worker pool in Go
WHAT IT TESTS: concurrency coordination with goroutines, channels, and context. OUTLINE: buffered job channel, fixed worker goroutines, WaitGroup to await in-flight work, context cancellation to stop intake.
WHAT IT TESTS: idiomatic Go concurrency primitives and lifecycle correctness. ANSWER OUTLINE: a jobs channel feeding a fixed set of worker goroutines; a sync.WaitGroup that Add(N) at startup and Done() per worker; a context.Context whose cancellation signals workers to drain and stop; Submit returns an error once shutdown begins. Shutdown closes the jobs channel exactly once, then WaitGroup.Wait blocks until all in-flight jobs finish.
Read the original → interview
- #go
- #concurrency
- #goroutines
- #context
- #graceful-shutdown
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.