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 receivesZero-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.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
