SOARDO
Software Engineer (SDE)fastapiadvanced3 interactive MCQs in app

Async Route Handlers & Event Loops

async def (event loop) vs def (threadpool) execution modelblocking I/O inside async def freezing all requestsusing httpx.AsyncClient / asyncpg in async def

FastAPI handles **`def`** vs **`async def`** endpoints differently under the hood! Plain **`def`** routes run automatically inside AnyIO’s worker **threadpool** (default ~40 threads) so blocking libraries (`psycopg2`, `requests`, disk reads) don’t freeze sibling requests; **`async def`** routes execute **directly on the main event loop thread**, expecting strictly non-blocking `await` (`httpx.AsyncClient`, `asyncpg`)!

switching `async def grade(): requests.post(...)` (freezes the loop!) either to `await httpx_client.post(...)` or plain sync `def grade():` (offloaded to threadpool) restores concurrent throughput!
(#1 FastAPI performance bug!) declaring `async def endpoint():` while calling blocking `requests.get()` or `time.sleep()` inside freezes the ENTIRE FastAPI event loop across all users!
FastAPI — Concurrency and async/await (Official)read ↗Async Route Handlers & Event Loops — Applied Practicepractice ↗

Practice Async Route Handlers & Event Loops with 3 graded MCQs & written feedback.

Take SOARDO’s free 12-question diagnostic to see how strong you are across your target role and unlock adaptive daily missions.

Test yourself free on SOARDO →View full Software Engineer roadmap

More Software Engineer Study Guides