<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Anil Kumar on Medium]]></title>
        <description><![CDATA[Stories by Anil Kumar on Medium]]></description>
        <link>https://medium.com/@p.anilkumar?source=rss-49894f49f971------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*U-tDJ56uZivYCRdl</url>
            <title>Stories by Anil Kumar on Medium</title>
            <link>https://medium.com/@p.anilkumar?source=rss-49894f49f971------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 22:30:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@p.anilkumar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Async vs Threads vs Multiprocessing: Understanding Python Concurrency Through the Lens of AI…]]></title>
            <link>https://medium.com/@p.anilkumar/async-vs-threads-vs-multiprocessing-understanding-python-concurrency-through-the-lens-of-ai-047e8d03c6fa?source=rss-49894f49f971------2</link>
            <guid isPermaLink="false">https://medium.com/p/047e8d03c6fa</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[Anil Kumar]]></dc:creator>
            <pubDate>Thu, 11 Jun 2026 08:18:38 GMT</pubDate>
            <atom:updated>2026-06-11T09:49:42.974Z</atom:updated>
            <content:encoded><![CDATA[<h3>Async vs Threads vs Multiprocessing: Understanding Python Concurrency Through the Lens of AI Engineering</h3><p>A practical guide to choosing between Async, Threads, and Multiprocessing in modern Python applications and AI systems — with runnable examples, real-world analogies, and a decision framework you’ll actually remember.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1BF8rrO7CGj_oN8mLSCskA.png" /></figure><p>If you’ve ever wondered:</p><ul><li>Why FastAPI prefers Async</li><li>Why Multiprocessing bypasses the GIL</li><li>Why Threads sometimes help and sometimes don’t</li><li>Why modern AI frameworks rely heavily on Async</li></ul><p>then this article is for you.</p><p>We’ll build the intuition from first principles, explore runnable examples, and finish with a simple framework you can use to choose the right concurrency model in your own projects.</p><p>Last week I wanted to compare responses from multiple AI models side by side.</p><p>The task sounded simple:</p><ul><li>Send the same prompt to GPT</li><li>Send it to Claude</li><li>Send it to Gemini</li><li>Send it to DeepSeek</li><li>Compare the outputs</li></ul><p>Ten minutes later, I found myself staring at a much bigger question:</p><blockquote><em>Should I use Threads, Multiprocessing, or Async?</em></blockquote><p>If you’ve been learning Python for a while, you’ve probably encountered all three.</p><p>Threads.</p><p>Processes.</p><p>async and await.</p><p>I didn’t struggle with the syntax.</p><p>I struggled with the decision.</p><p>Every tutorial showed me how to create a thread, start a process, or write an async function. What I couldn’t find was a simple framework for deciding <em>when</em> each approach actually made sense.</p><p>This article is the explanation I wish I had when I first encountered Python concurrency.</p><p>By the end, you’ll understand:</p><ul><li>Why Async dominates modern AI applications</li><li>When Threads are still useful</li><li>When Multiprocessing becomes the best option</li><li>What the GIL actually does</li><li>How Python works with the Operating System</li><li>A simple mental model for choosing the right tool</li></ul><p>Most importantly, you’ll know how to make the decision yourself.</p><h3>The Real Question Nobody Asks</h3><p>Most discussions start like this:</p><blockquote><em>Async vs Threads</em></blockquote><p>or</p><blockquote><em>Threads vs Multiprocessing</em></blockquote><p>I think that’s the wrong starting point.</p><p>The real question is:</p><blockquote><em>Where is your program spending its time?</em></blockquote><p>Every program spends its life doing one of two things:</p><ol><li>Working</li><li>Waiting</li></ol><p>Once you understand which one dominates your application, the choice becomes surprisingly obvious.</p><p>Let’s see why.</p><h3>A Tale of Two Programs</h3><p>Imagine Program A:</p><pre>import requests<br><br>response = requests.get(<br>    &quot;https://api.example.com&quot;<br>)</pre><p>At first glance, it feels like the computer is working during the entire request.</p><p>In reality:</p><pre>Build request      1 ms<br>Send request       1 ms<br>Wait for network   3000 ms<br>Process response   5 ms</pre><p>Total time:</p><pre>3007 ms</pre><p>Actual CPU work:</p><pre>7 ms</pre><p>Waiting:</p><pre>3000 ms</pre><p>The CPU is doing almost nothing.</p><p>Now consider Program B:</p><pre>total = 0<br><br>for i in range(500_000_000):<br>    total += i</pre><p>This program isn’t waiting.</p><p>It’s calculating continuously.</p><p>The CPU is busy every second.</p><p>Two programs.</p><p>Two completely different bottlenecks.</p><p>Two completely different solutions.</p><h3>Python and the Operating System: An Underrated Partnership</h3><p>Many developers imagine Python as doing everything itself.</p><p>The reality is much more interesting.</p><p>A simplified picture looks like this:</p><pre>Your Code<br>     ↓<br>Python Runtime<br>     ↓<br>Operating System<br>     ↓<br>CPU / Memory / Network</pre><p>Whenever you create:</p><pre>Thread(...)</pre><p>Python asks the Operating System to create a thread.</p><p>Whenever you create:</p><pre>Process(...)</pre><p>Python asks the Operating System to create a process.</p><p>Whenever you make a network request:</p><pre>requests.get(...)</pre><p>Python asks the Operating System to communicate over the network.</p><p>Think of Python as the conductor.</p><p>Think of the Operating System as the orchestra.</p><p>The conductor gives instructions.</p><p>The orchestra performs the work.</p><p>Understanding this relationship makes concurrency much easier to reason about.</p><h3>The GIL: Python’s Most Misunderstood Feature</h3><p>No discussion about Python concurrency is complete without mentioning the GIL.</p><p>The term sounds intimidating.</p><p>The idea is actually simple.</p><p>GIL stands for:</p><p><strong>Global Interpreter Lock</strong></p><p>The simplified rule is:</p><blockquote><em>Only one thread can execute Python bytecode at a time within a Python process.</em></blockquote><p>The moment many developers hear this, they jump to a conclusion:</p><blockquote><em>Threads are useless.</em></blockquote><p>That’s not true.</p><p>The GIL affects CPU-bound work executed in Python bytecode.</p><p>Let’s use an analogy.</p><p>Imagine four chefs sharing a kitchen.</p><p>All four chefs can stand in the kitchen.</p><p>All four chefs can prepare ingredients.</p><p>All four chefs can plan their next steps.</p><p>But there is only one knife.</p><p>At any moment, only one chef can use that knife.</p><p>That’s similar to how Python threads share access to Python bytecode through the GIL.</p><h3>Why Does the GIL Exist?</h3><p>A natural question follows:</p><blockquote><em>If the GIL limits parallelism, why does Python have it at all?</em></blockquote><p>The answer is surprisingly practical.</p><p>Python uses a memory management technique called reference counting.</p><p>Without the GIL, multiple threads could modify Python objects simultaneously.</p><p>Imagine:</p><pre>Thread A updates an object<br>Thread B updates the same object<br>Thread C deletes the object</pre><p>Managing memory safely becomes significantly more complex.</p><p>The GIL simplifies this problem.</p><p>The tradeoff looks like this:</p><pre>Simpler memory management<br>          ↓<br>Less CPU parallelism</pre><p>Like many engineering decisions, it isn’t perfect.</p><p>It’s a compromise.</p><h3>Threads: The First Tool Most Developers Learn</h3><p>Let’s start with a simple example.</p><pre>from threading import Thread<br>import time<br><br>def worker():<br>    time.sleep(5)<br><br>start = time.time()<br><br>threads = [<br>    Thread(target=worker)<br>    for _ in range(5)<br>]<br><br>for thread in threads:<br>    thread.start()<br><br>for thread in threads:<br>    thread.join()<br><br>print(time.time() - start)</pre><p>Question:</p><p>How long will this program take?</p><p>Many beginners guess:</p><pre>25 seconds</pre><p>because:</p><pre>5 workers × 5 seconds</pre><p>The actual answer is:</p><pre>~5 seconds</pre><p>Why?</p><p>Because the threads are not doing work.</p><p>They’re waiting.</p><p>While one thread waits, another thread can run.</p><p>This makes threads surprisingly effective for:</p><ul><li>File operations</li><li>Network requests</li><li>Background jobs</li><li>Legacy blocking libraries</li></ul><p>This is where many developers stop.</p><p>Unfortunately, there’s another side to threads.</p><p>And it can become painful very quickly.</p><h3>The Hidden Challenge: Race Conditions</h3><p>Threads share memory.</p><p>At first, that sounds fantastic.</p><p>One thread creates some data.</p><p>Another thread uses it.</p><p>Simple.</p><p>Until two threads try to modify the same data at the same time.</p><p>Consider this example:</p><pre>from threading import Thread<br><br>counter = 0<br>def increment():<br>    global counter<br>    for _ in range(100_000):<br>        counter += 1<br>threads = [<br>    Thread(target=increment)<br>    for _ in range(2)<br>]<br>for t in threads:<br>    t.start()<br>for t in threads:<br>    t.join()<br>print(counter)</pre><p>What would you expect?</p><pre>200000</pre><p>Right?</p><p>Not always.</p><p>Sometimes you’ll see:</p><pre>198734<br>199212<br>199998</pre><p>Wait.</p><p>How can that happen?</p><p>The reason is that:</p><pre>counter += 1</pre><p>is not a single operation.</p><p>Python actually performs several steps:</p><pre>Read counter<br>Add 1<br>Write counter back</pre><p>Imagine:</p><pre>Thread A reads 100<br>Thread B reads 100</pre><pre>Thread A writes 101<br>Thread B writes 101</pre><p>One update is lost.</p><p>This is called a <strong>Race Condition</strong>.</p><p>Multiple workers are racing to modify the same resource.</p><h3>Synchronization: Teaching Workers to Take Turns</h3><p>How do we solve this?</p><p>With synchronization.</p><p>Synchronization simply means:</p><blockquote><em>Coordinating workers so they don’t interfere with each other.</em></blockquote><p>Python provides a Lock.</p><pre>from threading import Lock<br><br>counter = 0<br>lock = Lock()<br>def increment():<br>    global counter<br>    for _ in range(100_000):<br>        with lock:<br>            counter += 1</pre><p>Now only one thread can modify the counter at a time.</p><p>Think of a lock as a restroom key.</p><pre>Worker 1 wants access<br>↓<br>Takes the key<br><br>Worker 2 wants access<br>↓<br>Must wait<br><br>Worker 1 finishes<br>↓<br>Returns the key<br><br>Worker 2 enters</pre><p>Synchronization solves correctness problems.</p><p>But it introduces another reality:</p><p>Threads often spend time waiting for each other.</p><h3>If Threads Share Memory, Why Use Processes?</h3><p>This brings us to Multiprocessing.</p><p>Imagine you’re processing a huge dataset.</p><pre>total = 0<br><br>for i in range(500_000_000):<br>    total += i</pre><p>The CPU is busy continuously.</p><p>This is not a waiting problem.</p><p>This is a computing problem.</p><p>And this is where Multiprocessing shines.</p><h3>Multiprocessing: One Process Per Core</h3><p>Let’s look at an example.</p><pre>from multiprocessing import Pool<br><br>def square(number):<br>    return number * number<br><br>with Pool(4) as pool:<br>    results = pool.map(<br>        square,<br>        range(1000000)<br>    )</pre><p>Something interesting happens here.</p><p>Instead of:</p><pre>One Python interpreter<br>One GIL<br>One process</pre><p>we now have:</p><pre>Process 1<br>Process 2<br>Process 3<br>Process 4</pre><p>Each process gets:</p><ul><li>Its own memory</li><li>Its own Python interpreter</li><li>Its own GIL</li></ul><p>Notice the last point.</p><p>Each process has its own GIL.</p><p>This is how Multiprocessing bypasses the GIL limitation.</p><p>Now multiple CPU cores can genuinely work at the same time.</p><p>This is real parallelism.</p><h3>The Hidden Cost of Multiprocessing</h3><p>At this point you might wonder:</p><blockquote><em>Why not use Multiprocessing everywhere?</em></blockquote><p>Because every advantage comes with a cost.</p><p>Processes don’t share memory.</p><p>Imagine:</p><pre>Process A<br>counter = 100</pre><p>Can Process B access it?</p><p>No.</p><p>Process B doesn’t even know it exists.</p><p>Each process has its own isolated memory space.</p><p>This is both a strength and a weakness.</p><h3>IPC: The Postal Service of Processes</h3><p>Suppose Process A wants to send information to Process B.</p><p>How does it do that?</p><p>Through IPC.</p><p>IPC stands for: <strong>Inter-Process Communication</strong></p><p>Think of it as a postal service.</p><pre>Process A<br>   ↓<br>Package Data<br>   ↓<br>Send Package<br>   ↓<br>Process B</pre><p>Python provides several IPC mechanisms:</p><pre>Queue<br>Pipe<br>SharedMemory</pre><p>The important thing to remember is:</p><blockquote><em>Communication between processes is never free.</em></blockquote><p>Data has to move.</p><p>And moving data takes time.</p><h3>Serialization: Packing the Parcel</h3><p>Before data travels between processes, Python often needs to serialize it.</p><p>Serialization simply means:</p><blockquote><em>Convert an object into a format that can be transported.</em></blockquote><p>Imagine shipping a bicycle.</p><p>You don’t send it exactly as it is.</p><p>You:</p><pre>Disassemble<br>Pack<br>Ship<br>Unpack<br>Reassemble</pre><p>Serialization works similarly.</p><p>Python packages the object.</p><p>Transfers it.</p><p>Reconstructs it on the other side.</p><p>This overhead is usually acceptable for CPU-heavy workloads. But for lightweight tasks, it can become wasteful.</p><p>This is one reason why Multiprocessing isn’t the answer to every concurrency problem.</p><h3>Async: A Completely Different Philosophy</h3><p>Threads ask the Operating System for more workers.</p><p>Processes ask the Operating System for more workers.</p><p>Async takes a different approach.</p><p>Instead of adding workers, it asks:</p><blockquote><em>Can one worker manage multiple tasks?</em></blockquote><p>This is the idea that finally made Async click for me.</p><h3>The Restaurant Analogy</h3><p>Imagine a restaurant.</p><p>A waiter takes your order.</p><p>The food needs 20 minutes to cook.</p><p>What should the waiter do?</p><p>Option 1:</p><pre>Stand beside your table<br>for 20 minutes</pre><p>Terrible idea.</p><p>Option 2:</p><pre>Take your order<br>Go serve other customers<br>Come back when food is ready</pre><p>That’s Async.</p><p>The waiter isn’t doing multiple things simultaneously.</p><p>The waiter is managing waiting intelligently.</p><h3>Your First Async Program</h3><pre>import asyncio<br><br>async def worker():<br>    print(&quot;Started&quot;)<br>    await asyncio.sleep(5)<br>    print(&quot;Finished&quot;)<br><br>await worker()</pre><p>Notice the keyword:</p><pre>await</pre><p>This is the heart of Async.</p><p>It essentially means:</p><blockquote><em>I cannot make progress right now. Feel free to run something else.</em></blockquote><p>That’s it.</p><p>That’s the magic.</p><h3>Running Multiple Tasks</h3><p>Now let’s run three workers.</p><pre>import asyncio<br><br>async def worker():<br>    await asyncio.sleep(5)<br><br>async def main():<br>    await asyncio.gather(<br>        worker(),<br>        worker(),<br>        worker()<br>    )<br><br>await main()</pre><p>Question:</p><p>How long does this take?</p><p>Not:</p><pre>15 seconds</pre><p>Instead:</p><pre>~5 seconds</pre><p>because all three tasks spend most of their lives waiting.</p><p>This is exactly what Async was designed for.</p><h3>The Event Loop: The Brain Behind Async</h3><p>At this point, Async might feel a little magical.</p><p>We write:</p><pre>await some_api_call()</pre><p>and somehow multiple tasks continue making progress.</p><p>What’s actually happening behind the scenes?</p><p>The answer is something called the <strong>Event Loop</strong>.</p><p>Think of the Event Loop as a project manager.</p><p>Its entire job is to keep asking:</p><pre>Task A ready?<br>No.<br><br>Task B ready?<br>Yes.<br><br>Run Task B.<br><br>Task C ready?<br>No.<br><br>Task D ready?<br>Yes.<br><br>Run Task D.</pre><p>It continuously checks which tasks can make progress and which ones are waiting.</p><p>Unlike Threads, where the Operating System decides which thread runs next, Async applications delegate those decisions to the Event Loop, which continuously determines which task is ready to make progress.</p><p>A simplified picture looks like this:</p><pre>Event Loop<br>                     |<br>     ---------------------------------<br>     |               |               |<br>  Task A          Task B          Task C<br>     |               |               |<br> Waiting         Running         Waiting</pre><p>This is one of the biggest conceptual differences between Threads and Async.</p><pre>Threads:<br>Operating System scheduling<br><br>Async:<br>Event Loop scheduling</pre><p>This distinction allows Async applications to manage hundreds or even thousands of waiting operations without creating hundreds or thousands of threads.</p><h3>The Moment Async Finally Clicked For Me</h3><p>While benchmarking multiple AI models, I realized something interesting.</p><p>The code:</p><pre>response = await llm_call()</pre><p>does not mean:</p><blockquote><em>Stop everything and wait.</em></blockquote><p>What it really means is:</p><blockquote><em>I cannot make progress right now.</em></blockquote><blockquote><em>Feel free to run something else until I become ready again.</em></blockquote><pre>import asyncio<br>import time<br><br><br>def calculate():<br><br>    print(&quot;Starting calculation...&quot;)<br>    time.sleep(3)<br>    print(&quot;Calculation complete&quot;)<br><br>    return 42<br><br><br>async def llm_call():<br><br>    print(&quot;Calling LLM...&quot;)<br>    await asyncio.sleep(5)<br>    print(&quot;LLM responded&quot;)<br><br>    return &quot;Hello&quot;<br><br><br>async def main():<br><br>    llm_task = asyncio.create_task(llm_call())<br><br>    calc_task = asyncio.to_thread(calculate)<br><br>    response = await llm_task<br><br>    result = await calc_task<br><br>    print(response, result)<br><br><br>asyncio.run(main())</pre><pre>0 sec  Start LLM<br><br>0 sec  Start calculation thread<br><br>3 sec  Calculation complete (irrespective of LLM wait)<br><br>5 sec  LLM responds<br><br>Total = 5 sec</pre><p>That single realization changed how I thought about Async.</p><p>That single realization changed how I thought about Async.</p><p>Suddenly, Async stopped feeling like a programming trick and started feeling like a scheduling strategy.</p><h3>gather() vs as_completed()</h3><p>When developers first learn Async, they often encounter:</p><pre>await asyncio.gather(<br>    task1(),<br>    task2(),<br>    task3()<br>)</pre><p>gather() is fantastic.</p><p>It starts all tasks concurrently and waits until every task finishes.</p><p>Imagine three model calls:</p><pre>GPT       2 sec<br>Gemini    4 sec<br>Claude   15 sec</pre><p>Using:</p><pre>await asyncio.gather(...)</pre><p>the program waits until all three models finish.</p><p>Only then are the results returned.</p><pre>Wait 15 seconds<br>↓<br>Receive all results together</pre><p>This is perfect when you need every result before continuing.</p><p>But during my AI benchmarking project, I wanted something different.</p><p>I wanted to see results as soon as they arrived.</p><p>Why wait for Claude if GPT has already finished?</p><p>That’s where:</p><pre>asyncio.as_completed()</pre><p>becomes extremely useful.</p><p>Example:</p><pre>for task in asyncio.as_completed(tasks):<br>    result = await task<br>    print(result)</pre><p>Now the behavior changes:</p><pre>GPT finishes<br>↓<br>Display result<br><br>Gemini finishes<br>↓<br>Display result<br><br>Claude finishes<br>↓<br>Display result</pre><p>The slowest model no longer delays the visibility of the fastest models.</p><p>This creates a much better user experience.</p><p>For AI benchmarking, agent evaluation, and model comparison workflows, as_completed() often feels more natural than gather().</p><h3>Why Modern AI Applications Love Async</h3><p>At this point, a pattern should be emerging.</p><p>Modern AI applications spend most of their time waiting.</p><p>Consider a typical AI workflow:</p><pre>User Query<br>     ↓<br>LLM API Call<br>     ↓<br>Vector Database Search<br>     ↓<br>Web Search<br>     ↓<br>Another LLM Call<br>     ↓<br>Database Update<br>     ↓<br>Response Returned</pre><p>Notice something interesting.</p><p>Almost every step involves:</p><pre>Waiting</pre><p>Waiting for:</p><ul><li>Network responses</li><li>APIs</li><li>Databases</li><li>Search systems</li><li>External services</li></ul><p>In many AI applications, a single user request may trigger multiple LLM calls, vector database lookups, web searches, and external API requests.</p><p>The application is often acting less like a calculator and more like an orchestrator. And orchestration is exactly where Async excels.</p><p>Async was specifically designed to handle coordination efficiently.</p><p>This is one reason why modern frameworks heavily embrace asynchronous programming.</p><p>Examples include:</p><ul><li>FastAPI</li><li>LangGraph</li><li>Agent Frameworks</li><li>OpenAI SDK</li><li>Anthropic SDK</li><li>Many modern web backends</li></ul><p>These systems are not using Async because it’s trendy.</p><p>They’re using Async because the workload naturally spends most of its life waiting.</p><h3>The Decision Framework</h3><p>After learning about Threads, Multiprocessing, Async, Locks, IPC, Serialization, and Event Loops, it’s easy to feel overwhelmed.</p><p>Fortunately, choosing the right tool can usually be reduced to one question:</p><blockquote><em>What is my program doing most of the time?</em></blockquote><p>If the answer is:</p><pre>API Calls<br>Database Queries<br>Web Requests<br>LLM Calls<br>Agent Workflows</pre><p>Use:</p><p>✅ Async</p><p>If the answer is:</p><pre>Data Processing<br>NumPy Computations<br>Pandas Transformations<br>Machine Learning Training<br>Image Processing<br>Video Processing</pre><p>Use:</p><p>✅ Multiprocessing</p><p>If the answer is:</p><pre>Legacy Libraries<br>Blocking SDKs<br>Background Workers<br>Mixed Workloads</pre><p>Use:</p><p>✅ Threads</p><p>Don’t start by asking:</p><blockquote><em>Should I use Async?</em></blockquote><p>Instead ask:</p><blockquote><em>Is my application mostly waiting or mostly computing?</em></blockquote><p>The answer usually reveals the right architecture.</p><h3>The 15-Second Decision Tree</h3><p>If you’ve read this far and only want one thing to remember, make it this:</p><pre>               Is your application<br>                 mostly waiting?     <br>                        │<br>                 ┌──────┴──────┐<br>                 │             │<br>                YES            NO<br>                 │             │<br>              Async      Mostly Computing?<br>                               │<br>                        ┌──────┴──────┐<br>                        │             │<br>                       YES            NO<br>                        │              │<br>              Multiprocessing       Threads</pre><p>Whenever you’re unsure which concurrency model to use, start here.</p><p>You don’t need to think about Event Loops, GILs, Locks, IPC, or Serialization first.</p><p>Instead, ask a simpler question:</p><blockquote><em>Where is my application spending most of its time?</em></blockquote><p>The answer will usually point you toward the right tool.</p><h3>Key Takeaways</h3><p>Before you leave, here’s the entire article condensed into a few bullet points:</p><p>✅ Async is optimized for waiting.</p><p>✅ Multiprocessing is optimized for computing.</p><p>✅ Threads are useful when working with blocking code or libraries that don’t support Async.</p><p>✅ The GIL mainly affects CPU-bound workloads, not I/O-bound workloads.</p><p>✅ IPC and Serialization are the hidden costs of Multiprocessing.</p><p>✅ Modern AI applications spend more time coordinating than computing.</p><p>✅ Async isn’t about doing more work simultaneously. It’s about handling waiting more efficiently.</p><p>✅ The best concurrency model depends less on syntax and more on where your application spends its time.</p><p>If you remember only one thing from this article, let it be this:</p><blockquote><em>Don’t start by asking whether you should use Async, Threads, or Multiprocessing.</em></blockquote><blockquote><em>Start by asking where your program is spending its time.</em></blockquote><h3>Final Thoughts</h3><p>When I first started learning Python concurrency, I thought the challenge was understanding the syntax.</p><p>I spent time learning:</p><pre>Thread()<br>Process()<br>async def<br>await<br>asyncio.gather()</pre><p>Eventually, I realized the syntax was never the difficult part.</p><p>The difficult part was understanding <strong>what problem each tool was designed to solve.</strong></p><p>For a long time, I viewed concurrency as a way to make programs faster.</p><p>Today, I think about it differently.</p><p>Concurrency is often not about making your computer work harder.</p><p>It’s about making your computer wait smarter.</p><p>That single idea changed everything for me.</p><p>When I call an LLM, query a database, make an API request, or scrape a website, the CPU is usually not busy.</p><p>It’s waiting.</p><p>And while it’s waiting, Async allows other work to continue.</p><p>When I’m processing millions of records, training a model, transforming large datasets, or performing heavy computations, waiting isn’t the problem anymore.</p><p>The CPU is the bottleneck.</p><p>That’s where Multiprocessing shines.</p><p>And when I’m working with blocking libraries, background workers, or systems that don’t support Async, Threads still remain a practical and powerful option.</p><p>After all the diagrams, code examples, and technical explanations, this is the framework I keep coming back to:</p><pre>Mostly Waiting?<br>    ↓<br>Use Async <br><br>Mostly Computing?<br>    ↓<br>Use Multiprocessing<br><br>Blocking Library?<br>    ↓<br>Use Threads</pre><p>That’s it.</p><p>Not every concurrency decision will be perfect.</p><p>There will always be edge cases.</p><p>But if you start with those three questions, you’ll make the right architectural choice far more often than not.</p><p>What’s fascinating is that modern AI systems have made this distinction even more important.</p><p>A typical AI application today might:</p><pre>Receive User Request<br>        ↓<br>Call GPT<br>        ↓<br>Search the Web<br>        ↓<br>Query a Database<br>        ↓<br>Call Another Model<br>        ↓<br>Generate a Response</pre><p>Most of those steps involve waiting.</p><p>Not computing.</p><p>That’s one of the reasons Async has become such a fundamental building block in modern AI engineering.</p><p>Frameworks like FastAPI, LangGraph, agent frameworks, and many production AI systems are not embracing Async because it’s fashionable.</p><p>They’re embracing it because the nature of modern applications has changed.</p><p>We’re spending less time computing.</p><p>We’re spending more time coordinating.</p><p>And that’s exactly what Async was designed for.</p><p>If there’s one thing I hope you take away from this article, it’s this:</p><blockquote><em>Don’t start by asking whether you should use Async, Threads, or Multiprocessing.</em></blockquote><blockquote><em>Start by asking where your program is spending its time.</em></blockquote><p>Once you answer that question, the right tool usually reveals itself.</p><p>And when that happens, concurrency stops feeling like magic and starts feeling like engineering.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=047e8d03c6fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>