Skip to Content

Where is async/await the right tool?

Category: Python Fundamentals

Answer

Async shines for I/O-bound workloads (HTTP, DB, files) where one task waits for I/O most of the time. It lets ONE thread drive thousands of concurrent tasks because each awaits others. CPU-bound work? Use multiprocessing or ProcessPoolExecutor — async doesn’t speed up Python’s GIL-bound pure compute.

Concrete examples from the fca project context

Example 1

async def fetch(url): … reads in parallel for 100 URLs in ~1 RTT.

Example 2

async with async_session() -> async for row in session.execute(…): … for high-throughput DB.

Example 3

asyncio.gather(*tasks) fans out and waits for the slowest.

Example 4

CPU-heavy work -> concurrent.futures.ProcessPoolExecutor, NOT asyncio.

Data flow / flow chart

I/O wait -> async/await (concurrency)
  CPU compute -> multiprocessing (parallelism in separate processes)

Takeaway

async for I/O concurrency. multiprocessing for CPU parallelism. Don’t mix the two.