Bounded worker pool with backpressure

5576
0

I avoid unbounded goroutines when processing queues; they look fine in staging and then blow up under a burst. This worker pool keeps a fixed number of workers and a bounded channel for jobs, which creates backpressure by design. The Submit call respects ctx.Done() so callers can stop enqueueing quickly during shutdown. On the worker side, each job receives the same ctx, so cancellations propagate. The most important operational detail is sizing: the job buffer should match the acceptable in-memory backlog, and the worker count should reflect downstream capacity (DB connections, API rate limits). Once you add metrics for queue length and processing time, this becomes a predictable subsystem.