Go Channels: Buffered vs. Unbuffered
Unbuffered channels are a synchronous rendezvous, blocking until both sender and receiver are ready. Buffered channels are an async mailbox, letting senders drop messages and go. The footgun is using a buffer to hide a deadlock instead of fixing it.
Unbuffered Go channels force a synchronous rendezvous; a sender blocks until a receiver is ready, guaranteeing a direct handoff. Buffered channels act as an asynchronous mailbox with a fixed capacity, decoupling goroutines by allowing a sender to deposit items without waiting for an immediate receiver. This is ideal for managing work queues or smoothing out bursty producers. The main footgun is choosing an arbitrary buffer size, which can hide underlying synchronization problems or create new bottlenecks when the buffer fills.
Read the original → go.dev
- #go
- #concurrency
- #channels
- #goroutines
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.