How do you explain goroutines and channels without turning every problem into a pipeline?
Goroutines are cheap concurrency. Channels coordinate; mutexes still have a place.
Points worth saying
- A goroutine is a lightweight concurrent function scheduled by Go.
- Channels pass ownership of values between goroutines.
- Shared memory with a mutex is fine when a channel would only add noise.
A full answer
A goroutine starts with the go keyword. Thousands can exist because the runtime multiplexes them onto OS threads. That does not mean unbounded fan-out is free; you still bound work with a worker pool or a semaphore.
Channels are for handing a value to another goroutine and optionally waiting. Prefer clear ownership: who sends, who receives, who closes. Closing is the sender’s job when the stream ends.
Do not force a channel into a simple shared counter. A sync.Mutex or atomic is clearer. In an interview, say the coordination model first, then the API. The goal is correctness under concurrency, not using every keyword in the language.
Mark your progress
Create a practice profile to mark this question.