Performance: ASGI and async-first architecture
HIGH IMPACT
This affects how quickly the server can handle multiple requests and respond without blocking, improving interaction speed and throughput.
from fastapi import FastAPI import asyncio app = FastAPI() @app.get("/async") async def async_endpoint(): await asyncio.sleep(2) # non-blocking sleep return {"message": "done"}
from fastapi import FastAPI app = FastAPI() @app.get("/sync") def sync_endpoint(): import time time.sleep(2) # blocking sleep return {"message": "done"}
| Pattern | Concurrency | Event Loop Blocking | Input Delay | Verdict |
|---|---|---|---|---|
| Synchronous blocking calls | Low (serial) | High (blocks event loop) | High (long input delay) | [X] Bad |
| Async-first non-blocking calls | High (concurrent) | Low (event loop free) | Low (fast input response) | [OK] Good |