In Go, when would you reach for a channel versus a sync.Mutex to coordinate goroutines?

technical-conceptual · Mid level · software-engineering

What the interviewer is really asking

Assesses whether the candidate understands Go's concurrency primitives well enough to pick the right one by intent — communication versus protecting shared state — instead of defaulting to channels for everything.

What to say

What to avoid

Example answers

Strong: In a worker pool I used a channel to hand jobs to workers — that's data flowing between goroutines, exactly what channels are for. But the shared metrics counter those workers updated, I guarded with a sync.Mutex, because routing every increment through a channel would have been slower and noisier. I ran `go test -race` to confirm there were no data races.

Weak: Go's motto is don't communicate by sharing memory, share memory by communicating, so I always use channels and avoid mutexes since they're not really idiomatic.

Want questions matched to your role? Paste a job title, job description, or CV and get a personalized set, or go Pro to unlock the full bank.