Golang / GoLang Concurrency Mastery Interview Questions
What is the difference between unbuffered and buffered channels in Go?
This is the most fundamental channel question in every Go interview. The two types have completely different synchronisation semantics.
| Aspect | Unbuffered (make(chan T)) | Buffered (make(chan T, N)) |
|---|---|---|
| Capacity | 0 | N |
| Send blocks when | No goroutine is ready to receive | Buffer is already full (N items queued) |
| Receive blocks when | No goroutine is ready to send | Buffer is empty |
| Synchronisation model | Synchronous rendezvous — sender and receiver meet at the channel | Asynchronous up to capacity |
| Typical use case | Signalling, handshake, guaranteed delivery confirmation | Decoupling producer/consumer throughput rates |
// Unbuffered â sender parks until a receiver is ready ch := make(chan int) go func() { ch <- 42 }() // goroutine parks until main receives v := <-ch // unblocks the sender fmt.Println(v) // 42 // Buffered â send does not block until buffer is full bch := make(chan int, 3) bch <- 1 // no goroutine needed â value goes into buffer bch <- 2 bch <- 3 // bch <- 4 // BLOCKS â buffer full, no receiver fmt.Println(<-bch) // 1 (FIFO ordering) fmt.Println(<-bch) // 2 fmt.Println(<-bch) // 3 // Inspect buffer state fmt.Println(len(bch), cap(bch)) // 0 3 // Classic deadlock with unbuffered channel in same goroutine // ch2 := make(chan int) // ch2 <- 99 // DEADLOCK: send blocks, nobody ever receives
Zero-copy optimisation for unbuffered channels: when a sender and receiver goroutine meet at an unbuffered channel, Go copies the data directly from the sender's stack to the receiver's — no intermediate heap allocation. This is why unbuffered channels have the lowest latency of any inter-goroutine communication mechanism.
More Related questions...