Go Concurrency Vocabulary: Goroutines, Channels, and More
Goroutine, channel, WaitGroup, context, race condition — the Go concurrency vocabulary you need for code reviews, design discussions, and technical interviews in English.
Go’s concurrency model is one of the language’s most celebrated features — and one of the most discussed in code reviews, design documents, and interviews. Whether you are explaining a goroutine leak to a colleague or writing a PR description for a channel-based pipeline, having precise vocabulary makes technical communication much clearer.
Goroutines and Scheduling
Goroutine (pronunciation: “go-roo-teen”)
A lightweight thread managed by the Go runtime. Starting a goroutine is as simple as writing go myFunc(). Thousands of goroutines can run concurrently because they are multiplexed onto OS threads by the Go scheduler. Phrase: “We spawned a goroutine for each incoming request — the overhead is negligible compared to OS threads.”
Goroutine leak A goroutine that never terminates because it is blocked waiting for a channel that will never receive a value, or a context that is never cancelled. Goroutine leaks cause memory growth over time. Phrase: “The profiler showed goroutine count climbing — we had a goroutine leak in the subscription handler.”
WaitGroup (from the sync package)
A counter that waits for a collection of goroutines to finish. You call wg.Add(n) before launching goroutines and wg.Done() in each goroutine; the main goroutine blocks on wg.Wait(). Phrase: “Use a WaitGroup to wait for all worker goroutines before shutting down.”
Channels and Communication
Channel (buffered / unbuffered) The primary mechanism for goroutines to communicate and synchronise. An unbuffered channel blocks the sender until a receiver is ready. A buffered channel has a capacity; senders block only when the buffer is full. Phrase: “The pipeline uses a buffered channel with capacity 100 to absorb bursts.”
Select statement A control structure that waits on multiple channel operations simultaneously, proceeding with whichever is ready first. Essential for timeouts and cancellation. Phrase: “The select statement lets us listen on both the result channel and the done channel — whichever fires first wins.”
Fan-out / fan-in pattern Fan-out: distributing work across multiple goroutines reading from a single channel. Fan-in: merging results from multiple channels into one. Together they form a concurrent pipeline. Phrase: “We fan out to 10 worker goroutines and fan in their results on a single output channel.”
Synchronisation and Safety
Mutex (pronunciation: “myoo-tex”, from sync.Mutex)
A mutual exclusion lock that ensures only one goroutine can access a shared resource at a time. Phrase: “We protect the cache map with a mutex — concurrent reads are fine, but writes must be exclusive.”
Race condition
A bug where the output of a program depends on the non-deterministic scheduling of goroutines accessing shared state. Go has a built-in race detector: go test -race. Phrase: “The race detector flagged a race condition in the counter — two goroutines were incrementing it without a lock.”
Deadlock A situation where two or more goroutines are each waiting for the other to release a resource, so none can proceed. Go detects simple deadlocks at runtime and panics. Phrase: “We had a deadlock — goroutine A was waiting for goroutine B’s channel, and B was waiting for A’s.”
context.Context
The standard Go idiom for propagating cancellation, deadlines, and request-scoped values across goroutine boundaries. Phrase: “Always pass ctx as the first parameter — it lets the caller cancel the operation if the request times out.”
Advanced Patterns
errgroup (from golang.org/x/sync/errgroup)
A higher-level abstraction over WaitGroup that propagates the first non-nil error from a group of goroutines. Phrase: “We replaced the WaitGroup with an errgroup so any worker error cancels the whole batch.”
Backpressure The mechanism by which a slow consumer signals to a fast producer to slow down, typically through a full buffered channel blocking the sender. Phrase: “The buffered channel provides backpressure — if the writer gets too far ahead, it blocks until the reader catches up.”
Real Phrases from Go Code Reviews
- “This goroutine has no cancellation path — add a context so it can be stopped cleanly.”
- “Close the channel when the producer is done — ranging over a closed channel terminates cleanly.”
- “Run
go test -race ./...before merging — this PR touches concurrent code.” - “The select default case makes this non-blocking — is that intentional?”
Practice: Write a short Go code snippet implementing a fan-out pattern, then write a PR description explaining the design in English using at least six of the terms above.