Concurrency vs Parallelism
Dealing with many things vs doing many things
Rob Pike famously said 'Concurrency is about dealing with lots of things at once. Parallelism is about doing lots of things at once.' They're related but distinct concepts that are often incorrectly used interchangeably.
Concurrency
Concurrency is the ability to handle multiple tasks by interleaving their execution. A single-core processor can be concurrent by rapidly switching between tasks (context switching), giving the illusion of simultaneity. It's about structure and design — writing code that can manage multiple things in flight. Go goroutines, JavaScript's event loop, and Python's asyncio are all concurrency tools.
Parallelism
Parallelism is the ability to execute multiple tasks simultaneously, literally at the same time. This requires multiple processing units (cores, CPUs, machines). It's about execution — actually doing multiple computations at the same instant. Multi-threaded code on a multi-core CPU, GPU computing, and distributed systems are parallelism tools.
Key Differences
- **Physical requirement**: Concurrency needs only one core. Parallelism needs multiple cores/processors. - **Focus**: Concurrency is about program structure. Parallelism is about program execution. - **Analogy**: Concurrency = one chef managing multiple dishes. Parallelism = multiple chefs each cooking a dish. - **Can exist independently**: You can have concurrency without parallelism (single-core async), and parallelism without concurrency (SIMD instructions). - **Python's GIL**: Python has concurrency (asyncio, threading) but threads can't achieve true parallelism for CPU work due to the GIL. Use multiprocessing instead.
When to Use Each
**Use concurrency** for I/O-bound work: network requests, file operations, database queries. The program spends most of its time waiting, so interleaving tasks is efficient. **Use parallelism** for CPU-bound work: image processing, data crunching, scientific computation. The bottleneck is computation, so you need more processors working simultaneously.
Analogy
**Concurrency**: A single barista managing 5 orders — starts the espresso, steams milk while waiting, takes another order during downtime. One person, many tasks in progress. **Parallelism**: Five baristas each making one drink simultaneously. Five people, five tasks, actual simultaneous execution.