Senior Backend Engineer Guide: Production Concurrency in Python (`asyncio`, `ProcessPoolExecutor`) vs. Go Goroutines & Channels
Choosing the right concurrency primitive—single-threaded event loops (`asyncio`), multi-process worker pools (`ProcessPoolExecutor`), OS threads, or M:N green threads (Go goroutines)—determines whether your backend server handles 10,000 concurrent connections effortlessly or collapses under CPU lock contention. As a Senior Backend Engineer who writes both production Python and Go (Golang) daily, here is the engineering playbook I use.
1. I/O-Bound vs. CPU-Bound Concurrency Decision Table
| Workload Profile | Best Python Pattern | Best Go (Golang) Pattern |
|---|---|---|
| High-Concurrency I/O (LLM streaming, WebSockets, HTTP fan-out) | asyncio.TaskGroup + `httpx.AsyncClient` with `asyncio.Semaphore` |
Bounded goroutine worker pool + `errgroup.Group` with `context.Context` |
| CPU-Bound Compute (PDF parsing, image resize, crypto,矩阵 math) | concurrent.futures.ProcessPoolExecutor or C/Rust extension releasing GIL |
Goroutines scheduled across `GOMAXPROCS` OS threads |
2. Bounded Concurrent Fan-Out in Python `asyncio` (`Semaphore` + `TaskGroup`)
Never call `asyncio.gather(*[fetch(u) for u in ten_thousand_urls])` without a concurrency semaphore—it will exhaust ephemeral sockets and trigger downstream rate limits. Use `asyncio.Semaphore` inside a structured `asyncio.TaskGroup`:
import asyncio
import httpx
async def fetch_all_bounded(urls: list[str], max_concurrency: int = 25) -> list[int]:
sem = asyncio.Semaphore(max_concurrency)
results: list[int] = [0] * len(urls)
async with httpx.AsyncClient(timeout=10.0) as client:
async def _worker(idx: int, url: str) -> None:
async with sem:
resp = await client.get(url)
results[idx] = resp.status_code
async with asyncio.TaskGroup() as tg:
for i, u in enumerate(urls):
tg.create_task(_worker(i, u))
return results
3. Related Backend Engineering Guides
- Hire a Senior Backend Engineer: Python, Django, FastAPI, Golang & PostgreSQL Pillar Guide
- Senior Backend Engineer Pattern: Transactional Outbox & Go Worker Pools
⚡ Hire Aldian Fazrihady — Senior Cloud, GCP, Backend, AI Application & Full Stack Engineer
Need production cloud architecture, GCP/AWS infrastructure, high-throughput backend systems, AI agents, or full stack web engineering? Book a 1-Day Programming Sprint for $100 USD (International Card / Apple Pay) or Rp 1,000,000 (Indonesian QRIS / Bank Virtual Account), or hire directly on Upwork:
Book $100 / Rp 1M 1-Day Sprint → Hire on Upwork (100% Job Success) →