When building systems where only the latest value matters, Go's default blocking channel behavior becomes a liability. Two patterns address this: non-blocking sends using select/default (drops values when the buffer is full, simple and safe for multiple producers) and drain-before-send (clears the old buffered value before writing the new one, guaranteeing the consumer always sees the freshest data but requiring a single producer). The post walks through the blocking problem with unbuffered and buffered channels, then explains both patterns with ASCII diagrams and code examples, covering tradeoffs and appropriate use cases like sensor telemetry, config reload signals, and Kubernetes controller reconciliation loops.
Table of contents
The Blocking ProblemPattern 1: Non-Blocking Send with select/defaultPattern 2: Drain-Before-SendWhen to Use Each9K Impressions