async def endpoints run on the event loop and should await non-blocking operations (async database drivers, httpx, async LLM clients); a blocking call inside them (time.sleep, requests, heavy CPU) freezes the entire loop for every request.
Plain def endpoints are run in a worker thread pool, so blocking libraries are safe there and do not block the loop (up to the thread pool limit).
Rule of thumb: use async def only if everything you call inside is awaitable; otherwise use def. CPU-heavy work belongs in a process pool or task queue.
Loading…