What is the difference between concurrency and parallelism in Go?
Learn the difference between concurrency and parallelism in Go, how goroutines and GOMAXPROCS relate, and why concurrency enables but need not be parallel.
Expected Interview Answer
Concurrency is about structuring a program as many independent tasks that can make progress by interleaving, while parallelism is actually running multiple tasks at the same instant on multiple CPU cores.
In Go you express concurrency with goroutines and channels — a design decision about composition. Parallelism is an execution property the runtime provides when GOMAXPROCS lets the scheduler map runnable goroutines onto multiple OS threads across physical cores. A concurrent program can run on a single core (interleaved) or on many cores (parallel); concurrency enables parallelism but does not require it.
- Cleaner program structure with independent tasks
- Scales to multiple cores when hardware allows
- Better throughput for I/O-bound and CPU-bound work
- Composable design using goroutines and channels
- Runtime controls parallelism via GOMAXPROCS
AI Mentor Explanation
Concurrency is one umpire tracking bowling, run-rate, and reviews by switching attention between them so all progress; parallelism is having three umpires, each handling one duty at the exact same moment across the ground.
Step-by-Step Explanation
Step 1
Define concurrency
Structure the program as independent tasks (goroutines) that can be started, paused, and resumed.
Step 2
Define parallelism
Recognize it as simultaneous execution requiring multiple CPU cores at the same instant.
Step 3
Express concurrency in Go
Launch goroutines with the go keyword and coordinate them with channels or sync primitives.
Step 4
Enable parallelism
Set GOMAXPROCS (default = number of cores) so the scheduler runs goroutines on multiple OS threads.
Step 5
Observe the relationship
The same concurrent code runs interleaved on one core or in parallel on many, without code changes.
What Interviewer Expects
- Clear distinction between structure and execution
- Goroutines and channels as concurrency tools
- Role of GOMAXPROCS and OS threads
- That concurrency enables but does not guarantee parallelism
- A concrete example of each
Common Mistakes
- Treating concurrency and parallelism as synonyms
- Assuming goroutines always run on separate cores
- Thinking GOMAXPROCS=1 means code is not concurrent
- Confusing parallel speedup with concurrent structure
- Believing more goroutines automatically means more parallelism
Best Answer (HR Friendly)
“Concurrency means designing a program so many jobs can be worked on in overlapping time, while parallelism means those jobs actually run at the exact same moment on different processor cores. Go makes concurrency easy with goroutines, and the runtime turns it into parallelism when the hardware has spare cores.”
Code Example
package main
import (
"fmt"
"runtime"
"sync"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU()) // allow parallelism
var wg sync.WaitGroup
for i := 0; i < 3; i++ {
wg.Add(1)
go func(id int) { // concurrency: independent tasks
defer wg.Done()
fmt.Println("task", id)
}(i)
}
wg.Wait()
}Follow-up Questions
- What does GOMAXPROCS control and what is its default?
- Can a concurrent Go program run on a single core?
- How do goroutines differ from OS threads?
- When does adding more goroutines stop improving performance?
- How do channels help coordinate concurrent goroutines?
MCQ Practice
1. Which statement best describes the relationship in Go?
Concurrency is about structure and can exist on one core; parallelism is simultaneous execution that relies on concurrent structure plus multiple cores.
2. What primarily determines whether goroutines run in parallel?
GOMAXPROCS caps how many OS threads run Go code simultaneously, so parallelism depends on it and on having multiple cores.
Flash Cards
Concurrency — Structuring a program as independent tasks that can make progress by interleaving.
Parallelism — Multiple tasks executing at the same instant on multiple CPU cores.
GOMAXPROCS — Runtime setting limiting how many OS threads execute Go code simultaneously; defaults to core count.
Does concurrency imply parallelism? — No — concurrent code can run interleaved on a single core with no parallelism.