Backend
Python async specifics
The event loop, the GIL, def vs async def in FastAPI, and free-threaded Python.
What it is and why it exists
asyncio runs coroutines on one thread; any blocking call stops all of them. FastAPI runs plain def endpoints in a thread pool and async def endpoints on the loop — so a sync call in async def is the classic bug. The GIL means threads don’t run Python bytecode in parallel (free-threaded builds relax this), so CPU-bound work goes to processes.
Quick prototype
async def everywhere, sync SDK inside.
In production, at scale
Async clients (httpx.AsyncClient, async DB drivers), asyncio.to_thread or run_in_executor for unavoidable sync work, Uvicorn/Gunicorn worker counts tuned, structured concurrency (TaskGroup) with timeouts, and CPU work in Celery/ARQ workers or a process pool.
Vendors and tools
| FastAPI / Starlette / Uvicorn | ASGI stack |
|---|---|
| asyncpg / SQLAlchemy async / psycopg 3 | Async Postgres |
| ARQ / Celery | Background workers |
How it fails
- Creating a new HTTP client per request (no connection pooling)
- Forgetting await, so the call never runs
What the interviewer asks next
def or async def for an endpoint that calls a sync library?
Plain def — FastAPI runs it in a thread pool so the event loop stays free. Or async def with asyncio.to_thread around the sync call.