Queuing
Queues should express explicit backpressure and overflow policy. Capacity is a design choice, not a patch for blocked goroutines.
Canonical guidance
- make queue size part of the design
- decide what happens when producers outrun consumers
- keep shutdown and draining semantics explicit
Use when
- bounded work queues
- burst absorption
- handoff between producer and worker stages
Avoid
- unbounded backlog by accident
- raising queue sizes until tests stop hanging
- using a queue where direct backpressure would be clearer
Preferred pattern
- pair queue capacity with a documented overload policy
Anti-pattern
- a buffered channel with a magic size and no explanation
Explanation: This is tempting because a buffer can stop blocking temporarily, but it often only delays overload visibility.
Why
- queues control resource pressure and failure behavior
Related pages
Sources
- Go Concurrency Patterns: Pipelines and cancellation - Sameer Ajmani
- Advanced Go Concurrency Patterns - Sameer Ajmani