Something that always gets us confused

Arpit Bhayani

Arpit Bhayani

Jul 18, 2023 • 2 min read


Something that always gets us confused. Concurrency vs. Parallelism. Let’s debunk it once and for all ⚡

Concurrency: When two or more tasks run during the overlapping time and make some progress is Concurrency.

Parallelism: When two or more tasks run during the overlapping time and make some progress simultaneously is Parallelism.

The only difference between the two statements is the word “simultaneous,” making all the difference.

Two tasks running concurrently can optionally use choose to execute on two separate cores of the CPU or execute on a single core and context switch to make progress.

But when two tasks are running in parallel, they have to be making progress simultaneously at a given instant. This means we can say …

⚡ all parallel executions are concurrent, but all concurrent executions need not parallel

Unlike popular belief, Concurrency and Parallelism are not mutually exclusive definitions; rather, they are nested. 🔨

Let’s talk Python and see where concurrency and parallelism fit in.

In Python, you can get concurrency using threads and asyncio. But if you need parallelism, you will have to use multiprocessing, forking out multiple processes to perform tasks in parallel.

This is typically due to a notorious feature called Global Interpreter Lock, fondly called GIL, which intentionally allows only one thread to hold the control of the Python interpreter at any given instant, preventing the execution and scheduling of others.

⚡ If you seek to become a better engineer and learn System Design the right way, you should definitely enroll in my upcoming cohort starting August 5th.

You can find the week-by-week curriculum and topics, benefits, testimonials, and other details arpitbhayani.me/course.

Arpit Bhayani

Principal Engineer II at Razorpay - building Agent Studio, Ex-staff engg at GCP Memorystore & Dataproc, Creator of DiceDB, ex-Amazon Fast Data, ex-Director of Engg. SRE and Data Engineering at Unacademy. I spark engineering curiosity through my no-fluff engineering videos on YouTube and my courses