termEngineering & architecture

Concurrency and Parallelism

Concurrency structures overlapping work, while parallelism executes multiple pieces of work at the same instant.

Download Markdown (.md)

01What it means

Concurrency is the composition and coordination of multiple tasks whose execution can overlap; parallelism is simultaneous execution on multiple processing resources. A system can be concurrent on one processor by interleaving tasks, and concurrent design can enable but does not guarantee faster parallel execution.[1][2]

Overlapping work versus simultaneous execution Concurrency structures multiple tasks; parallelism runs work at the same instant
Concurrency
Tasks make progress in overlapping periodsCoordination, scheduling, shared state, cancellation
Parallelism
Tasks execute simultaneouslyMultiple cores or workers, partitioning, synchronization

A single processor can interleave concurrent tasks. Parallel execution needs multiple processing resources and still pays coordination costs.

02Why it matters

Digital products handle many requests, background tasks, and external waits. Distinguishing concurrency from parallelism helps teams reason about responsiveness, throughput, capacity, data races, and why adding workers or processors may not make a sequential or highly contended workload faster.

03When to use it

Use concurrent structure when independent activities must make progress despite waiting or variable timing. Use parallel execution when work can be divided safely and measurement shows additional compute improves the relevant outcome. Sequential code is preferable when tasks are ordered, small, or coordination cost dominates.

04How it works

  1. Identify tasks that can overlap and the state or resources they share.
  2. Choose coordination mechanisms such as queues, immutable messages, locks, or structured tasks.
  3. Set concurrency limits to protect memory, connections, dependencies, and fairness.
  4. Run eligible work across available processors when parallel execution is beneficial.
  5. Test race conditions, cancellation, ordering, and failure propagation under realistic load.
  6. Measure throughput and latency because scheduling and coordination can erase expected gains.

05A practical example

Example

A document service concurrently fetches metadata and permissions while waiting on storage, improving response time even on limited compute. Thumbnail generation is separately parallelized across CPU cores, but worker count is capped after measurements show contention beyond eight workers.

06Where it breaks

Concurrent systems are harder to reason about and reproduce. Shared state creates races and deadlocks; parallel work adds scheduling and communication overhead. Performance depends on workload, dependencies, runtime, hardware, and safe resource limits.

Common mistakes

  • Using concurrency and parallelism as synonyms.
  • Increasing worker counts without limits on downstream connections or memory.
  • Sharing mutable state without a clear synchronization or ownership model.
  • Assuming more processors will accelerate inherently sequential work.

07Sources

  1. Concurrency Is Not ParallelismThe Go Programming Language · Official technical explanationConcurrency Is Not Parallelism
  2. Go Concurrency PatternsThe Go Programming Language · Official technical presentationGo Concurrency Patterns
View saved topics

Start typing to search titles, definitions, categories, and frameworks.