A buffered channel has a fixed capacity, so a send only blocks when the buffer is full and a receive only blocks when it is empty. A blocking channel, properly called an unbuffered channel, has no capacity: a send and a receive must meet, so each side waits for the other. In Go, "blocking" is not a separate channel type. Both kinds block in some situations, and the buffer size you pass to make decides when.
Choosing between them controls how tightly goroutines are synchronized and how much work can queue up between a producer and a consumer.
The only difference at creation time is the optional capacity argument.
You can check the state with the built-in functions len(ch), the number of queued values, and cap(ch), the capacity. For an unbuffered channel both return 0.
On an unbuffered channel the send completes only when a receiver takes the value. The sender and receiver rendezvous, which gives a strong guarantee: when the send returns, the receive has started.
This is the standard way to hand a result back or to signal completion. Because both sides wait, the channel doubles as a synchronization point and no mutex is needed.
A buffered channel stores up to cap values in a queue. A send puts the value in the buffer and returns immediately while there is room. When the buffer is full, the sender blocks. A receive takes the oldest value, and blocks only when the buffer is empty. Values arrive in first-in, first-out order.
If you tried a fourth send without receiving first, and no other goroutine were reading, the program would stop with fatal error: all goroutines are asleep - deadlock!.
| Aspect | Unbuffered | Buffered |
|---|---|---|
| Creation | make(chan T) | make(chan T, n) |
| Send blocks when | No receiver is ready | The buffer is full |
| Receive blocks when | No sender is ready | The buffer is empty |
| Synchronization | Strong, sender and receiver meet | Weaker, send does not mean received |
| Typical use | Signals, hand-offs, ping-pong | Work queues, bursts, semaphores |
| Risk | Deadlock if one side never arrives | Hidden backlog, delayed failure |
A buffer lets a producer run ahead of slow consumers by a bounded amount.
A buffered channel of struct{} limits concurrency: send to acquire a slot, receive to release it.
Closing or sending on an unbuffered done channel tells another goroutine that work has finished, as in the earlier example.
Start with unbuffered unless you have a reason. It makes ordering and back-pressure obvious, and bugs show up as deadlocks quickly. Add a buffer when you can explain the number: the count of workers, the size of a known burst, or a limit on in-flight jobs. Avoid large buffers used only to "make it stop blocking", because they hide slow consumers, increase memory use and delay the moment you notice a problem. A buffer of one is also a common idiom for results from a goroutine that might otherwise leak if nobody reads them.
Often slightly, because the sender does not wait for a receiver, but the gain depends on the workload. Pick the type for the synchronization you need and measure with a benchmark if speed matters.
The sending goroutine blocks until another goroutine receives a value. If no goroutine ever does, you get a deadlock or a leaked goroutine.
No. Capacity is fixed at creation. Create a new channel if you need a different size.
A closed channel still delivers any buffered values first, then returns the zero value immediately. Use v, ok := <-ch to detect closure, or for range ch.
An unbuffered channel makes sender and receiver meet, which gives synchronization and back-pressure. A buffered channel adds a bounded queue so the sender runs ahead until the buffer fills. Default to unbuffered, size buffers deliberately, close channels from the sending side, and remember that both types can block.