Skip to content

Lesson 1 of 9 · 20m

Concurrency Is Not Parallelism

Why concurrency is a structure for dealing with independent work, parallelism is a way to use more cores, and confusing them causes over-threaded systems that are slower and less correct.

The first production concurrency bug I ever owned was not a race. It was a service that had been given 512 worker threads because "more parallelism means more throughput." Under load it spent most of its CPU time in context switches and lock contention, and latency got worse as traffic increased. The fix was boring: fewer workers, clearer ownership, and a queue. The incident report taught the lesson every senior engineer eventually learns: concurrency is about structure; parallelism is about execution resources.

Concurrency is a design property

A concurrent system is one that can make progress on multiple logical tasks while those tasks overlap in time. They do not have to run at the same instant. One core can interleave hundreds of tasks; that is concurrency without parallelism.

Parallelism is narrower: multiple computations physically execute at the same time on different cores, sockets, or machines. Parallelism can improve throughput. It does not, by itself, tell you how to coordinate shared state.

Concurrency:  task A ----    ----     ----
              task B     ----    ----
              one core interleaves both tasks
Parallelism:  task A ------------------
              task B ------------------
              two cores execute both at once

Threads are a mechanism, not a unit of design

A common failure mode is designing in threads: one thread per connection, one thread per file, one thread per request. That couples your architecture to operating-system scheduling. Better systems design in tasks or actors and let an executor map those tasks onto a bounded number of threads.

In Go, goroutines make this cheap enough to write naturally:

jobs := make(chan Job)
results := make(chan Result)
for worker := 0; worker < runtime.NumCPU(); worker++ {
    go func() {
        for job := range jobs {
            results <- process(job)
        }
    }()
}

The worker count is a resource decision. The number of jobs is a workload property. Mixing those two numbers is how you get systems that scale down under load.

Throughput and latency pull in opposite directions

Adding parallelism can increase throughput while making tail latency worse. Every shared queue, allocator, lock, and cache line becomes a coordination point. At low utilization the coordination cost is invisible. At high utilization it becomes the system.

The operational rule of thumb: size CPU-bound workers near the number of available cores, size blocking-I/O workers by measured concurrency, and never let unbounded work queue behind either one.

Field notes

  • If a design document says "use threads" before it says what is shared, the design is backwards.
  • One thread per request is simple until requests block; then thread count becomes your failure mode.
  • CPU-bound work does not get faster beyond core count; it just queues differently.
  • Concurrency bugs are timing-dependent. The fact that a test passes on your laptop proves almost nothing.
  • Start with ownership and invariants. Choose threads, coroutines, actors, or processes afterward.

Was this lesson helpful?

Sign in to rate