54 FastAPI interview questions with answers
54 FastAPI interview questions with detailed answers, sorted from basic to advanced. Free to practice, with progress saved automatically.
All FastAPI interview questions
What is FastAPI and when should you use it?
What is a path operation in FastAPI?
What are Pydantic models used for in FastAPI?
How does FastAPI generate OpenAPI documentation?
How does FastAPI distinguish request body, path params and query params?
What problem does `response_model` solve?
How does Dependency Injection work in FastAPI?
When should you use a dependency with `yield`?
How are `async def` and `def` routes different in FastAPI?
How do you organize a FastAPI app with APIRouter?
How does Pydantic v2 affect FastAPI code?
How should you design partial update/PATCH in FastAPI?
How does FastAPI handle validation errors and business errors?
How is OAuth2/JWT commonly implemented in FastAPI?
How should CORS be configured in FastAPI?
How should FastAPI manage SQL database sessions?
What are BackgroundTasks used for in FastAPI?
When should you use middleware in FastAPI?
What are FastAPI lifespan/startup-shutdown handlers used for?
How should you test FastAPI endpoints?
What should you watch out for when testing databases with FastAPI?
How are ASGI and Uvicorn related to FastAPI?
What should you optimize for a FastAPI app in Docker?
Should FastAPI authorization be designed with roles or scopes?
When should you use StreamingResponse and FileResponse?
How are WebSockets in FastAPI different from HTTP endpoints?
How is SSE different from WebSocket in FastAPI?
Should FastAPI file uploads use `bytes` or `UploadFile`?
How should settings and environment variables be managed in FastAPI?
What does production observability for FastAPI need?
Where do you start debugging a slow FastAPI app?
Should a FastAPI project be organized by layer or by feature?
Should FastAPI use the repository pattern?
What security mistakes are common in FastAPI APIs?
How should FastAPI response status codes be designed?
When should input and output schemas be separated in FastAPI?
Where should transaction boundaries be placed in a FastAPI service?
How should API versioning be handled in FastAPI?
How should FastAPI health checks split liveness and readiness?
When should you not choose FastAPI?
What happens when an `async def` endpoint calls `requests.get()` inside?
How does `Annotated[User, Depends(get_user)]` differ from the older `user = Depends(get_user)`?
How do you make a response contain only the fields that were actually set, without defaults?
Can you run FastAPI in production with `uvicorn --reload`? How many workers should you use?
Where does FastAPI run a plain `def` endpoint? Is that threadpool bounded?
If the same dependency appears in several branches of one request, is it called repeatedly? What is `use_cache` for?
Returning a SQLAlchemy object straight from an endpoint fails Pydantic v2 validation — how do you configure it?
How do `field_validator` and `model_validator` differ? When do you pick `mode='before'` over `mode='after'`?
How does testing async endpoints with `httpx.AsyncClient` + `ASGITransport` differ from `TestClient`?
How do you export a 1-million-row CSV through FastAPI without a memory spike?
Why does using a DB session from a `yield` dependency inside `BackgroundTasks` break on recent FastAPI?
How does `BaseHTTPMiddleware` differ from pure ASGI middleware, and when must you drop it?
Async SQLAlchemy raises `MissingGreenlet: greenlet_spawn has not been called` when reading a relationship — why, and how do you fix it?
If the client disconnects mid-request, does FastAPI stop the handler? How do you handle long-running endpoints?