What is concurrency, and how does it differ from parallelism?
Concurrency means structuring a program so that several tasks are in progress during overlapping time periods, with their execution interleaved, for example a web server handling many requests while some wait for the database. Parallelism means executing multiple tasks literally at the same instant on multiple CPU cores or machines. Concurrency is about dealing with many things at once; parallelism is about doing many things at once. A program can be concurrent on a single core, and parallel only with multiple cores.
Read full answerHide full answer
Applies togeneral programming and backend systems (threads, processes, coroutines, async I/O, multi-core execution)
Comparison
| Aspect | Concurrency | Parallelism |
|---|---|---|
| Definition | Multiple tasks make progress in overlapping time | Multiple tasks run simultaneously |
| Hardware need | Works on one core (time slicing) | Needs multiple cores or machines |
| Main goal | Responsiveness, handling many waiting tasks, structure | Speed-up of CPU-heavy work |
| Typical workloads | I/O-bound: network, disk, database waits | CPU-bound: image processing, numeric computation |
| Tools | Threads, event loops, coroutines (async/await), goroutines | Multiple processes or threads on cores, SIMD, GPUs, distributed jobs |
| Main risks | Race conditions, deadlocks, ordering bugs | Same, plus load balancing and synchronization overhead |
Visual Intuition
-
Concurrency on one core:
A A B B A C B C A ...(tasks interleave) -
Parallelism on two cores: core 1 runs
A A A A, core 2 runsB B B Bat the same time
Example: Concurrent I/O in Python
import asyncio, time
async def fetch(name, delay):
await asyncio.sleep(delay) # simulates waiting on a network call
return name
async def main():
start = time.perf_counter()
results = await asyncio.gather(fetch("users", 1), fetch("orders", 1), fetch("prices", 1))
print(results, round(time.perf_counter() - start))
asyncio.run(main()) # ['users', 'orders', 'prices'] 1
Three one-second waits finish in about 1 second, not 3, on a single thread: that is concurrency without parallelism.
Example: Parallel CPU Work
from concurrent.futures import ProcessPoolExecutor
def square_sum(n):
return sum(i * i for i in range(n))
if __name__ == "__main__":
with ProcessPoolExecutor() as pool:
print(list(pool.map(square_sum, [10, 20, 30]))) # [285, 2470, 8555]
Separate processes can run on separate cores simultaneously, which is parallelism. (In CPython the global interpreter lock means threads do not run Python bytecode in parallel by default, so CPU-bound Python work uses processes; free-threaded builds from Python 3.13 relax this.)
In Backend Systems
-
A web server handles thousands of concurrent connections, most of them waiting on I/O, using an event loop (Node.js, Nginx) or many lightweight threads (Go goroutines, Java virtual threads).
-
A batch job processes data in parallel across cores or a cluster (Spark).
-
Most real systems combine both: concurrent request handling, with parallel execution across cores and machines.
Trade-offs
-
Concurrency adds coordination complexity: shared state needs synchronization.
-
Parallelism has limits: Amdahl’s Law says the serial part of a program caps the speed-up (if 10% must run serially, the maximum speed-up is 10x however many cores you add).
-
More threads than cores for CPU-bound work causes context-switch overhead without gains.
Interview Tip
Use the “dealing with vs doing many things at once” distinction (from Rob Pike), give an I/O-bound concurrency example and a CPU-bound parallelism example, and mention Amdahl’s Law. A common mistake is treating the two words as synonyms.