FastAPI Interview Questions
Routing and Pydantic validation, the dependency system, where async helps and where it silently blocks the event loop, auth and security, testing with dependency overrides, and what breaks under load.
Showing 1–20 of 100
#1What is FastAPI and what does it build on?
#2How does FastAPI decide where a parameter comes from?
#3Why does route ordering matter?
#4What is an APIRouter and how should you structure a large application?
#5What does response_model do and why should you use it?
#6How does FastAPI generate OpenAPI documentation?
#7What is the difference between FastAPI and Flask or Django REST Framework?
#8What is ASGI and why does it matter?
#9How do you handle application startup and shutdown?
#10How does middleware work in FastAPI?
#11What are background tasks and what are their limits?
#12How do you handle file uploads?
#13How do you return a streaming response?
#14How do WebSockets work in FastAPI?
#15What does Pydantic actually do for you?
#16What changed between Pydantic v1 and v2?
#17Should you use the same Pydantic model for input and output?
#18How do you write a custom validator?
#19What is the difference between Optional, a default, and exclude_unset?
#20How do you validate nested and list data?
Showing 1–20 of 100
Ask Aria about FastAPI
Sign in to chat with Aria
All 100 FastAPI questions at a glance
- What is FastAPI and what does it build on?(Easy)
- How does FastAPI decide where a parameter comes from?(Medium)
- Why does route ordering matter?(Medium)
- What is an APIRouter and how should you structure a large application?(Medium)
- What does response_model do and why should you use it?(Medium)
- How does FastAPI generate OpenAPI documentation?(Easy)
- What is the difference between FastAPI and Flask or Django REST Framework?(Medium)
- What is ASGI and why does it matter?(Medium)
- How do you handle application startup and shutdown?(Medium)
- How does middleware work in FastAPI?(Medium)
- What are background tasks and what are their limits?(Medium)
- How do you handle file uploads?(Medium)
- How do you return a streaming response?(Hard)
- How do WebSockets work in FastAPI?(Hard)
- What does Pydantic actually do for you?(Easy)
- What changed between Pydantic v1 and v2?(Medium)
- Should you use the same Pydantic model for input and output?(Medium)
- How do you write a custom validator?(Medium)
- What is the difference between Optional, a default, and exclude_unset?(Hard)
- How do you validate nested and list data?(Medium)
- What is model_config and what settings matter?(Medium)
- How do you handle camelCase JSON with snake_case Python?(Medium)
- What is a discriminated union and why use one?(Hard)
- How should you represent money and decimals?(Medium)
- What is Pydantic Settings and why use it for configuration?(Medium)
- How do you handle validation of query parameters and filters?(Medium)
- What is the performance cost of Pydantic validation?(Hard)
- How do you convert between ORM models and Pydantic schemas?(Hard)
- What happens when validation fails, and how do you customise it?(Medium)
- How do you version an API in FastAPI?(Medium)
- How does FastAPI's dependency injection work?(Medium)
- What is a yield dependency and when does the teardown run?(Hard)
- How do you manage a database session per request?(Hard)
- What is dependency caching and when does it bite?(Hard)
- What is a class-based dependency and when is it useful?(Medium)
- How do you apply a dependency to every route in a group?(Medium)
- How do you override dependencies in tests?(Medium)
- Should business logic live in dependencies or in services?(Medium)
- How do you share expensive resources across requests?(Medium)
- What is the Annotated style for dependencies and why is it preferred?(Medium)
- How do you implement pagination as a reusable dependency?(Medium)
- What happens if a dependency raises an exception?(Medium)
- How do you inject the current user and enforce permissions?(Medium)
- What is the difference between a dependency and middleware for cross-cutting concerns?(Medium)
- What is the difference between def and async def route handlers?(Medium)
- What happens if you block the event loop?(Hard)
- When does async actually improve performance?(Medium)
- How do you call several services concurrently in a handler?(Medium)
- How does the thread pool for sync handlers work and can you exhaust it?(Hard)
- What is the right async database setup?(Hard)
- How do you make outbound HTTP calls correctly?(Medium)
- What is the difference between BackgroundTasks and a task queue?(Medium)
- How do you handle timeouts for a request?(Hard)
- What happens when a client disconnects mid-request?(Hard)
- How do you run CPU-bound work in a FastAPI service?(Medium)
- What are the most common async mistakes in FastAPI code?(Medium)
- How do you decide between sync and async for a new service?(Medium)
- How does Uvicorn with multiple workers interact with async?(Hard)
- How do you implement JWT authentication in FastAPI?(Medium)
- What is the difference between OAuth2PasswordBearer and HTTPBearer?(Medium)
- Should you store JWTs in localStorage or a cookie?(Hard)
- How do you handle token refresh?(Hard)
- How do you configure CORS correctly?(Medium)
- How do you prevent SQL injection and other injection attacks?(Medium)
- How do you implement rate limiting?(Hard)
- What security headers should a FastAPI service send?(Medium)
- How do you handle authorisation that depends on the resource?(Hard)
- How should passwords be stored and verified?(Medium)
- How do you protect the OpenAPI docs in production?(Medium)
- What is mass assignment and how does Pydantic help or hurt?(Medium)
- How do you handle secrets in a FastAPI application?(Medium)
- What should you never include in an error response?(Medium)
- How does exception handling work in FastAPI?(Medium)
- How should you structure error responses?(Medium)
- What is the difference between returning a Response and returning data?(Medium)
- How do you set the status code for a response?(Easy)
- How do you handle a domain exception cleanly?(Medium)
- How do you add a correlation ID to every request and response?(Medium)
- How should logging be set up in a FastAPI service?(Medium)
- What should a health check endpoint do?(Medium)
- How do you return a file or a large download?(Medium)
- How do you document error responses in OpenAPI?(Medium)
- How do you test a FastAPI application?(Medium)
- How do you test with a real database?(Hard)
- How do you test authentication-protected endpoints?(Medium)
- How do you mock external HTTP calls in tests?(Medium)
- What should you test at the API level versus the service level?(Medium)
- How do you test WebSocket endpoints?(Hard)
- How do you test that validation works as intended?(Medium)
- How do you keep a test suite fast as the application grows?(Medium)
- What is contract testing and does FastAPI help?(Hard)
- How do you test background tasks and async side effects?(Medium)
- How do you deploy a FastAPI application?(Medium)
- How many workers should you run and why?(Hard)
- What should you monitor in a FastAPI service?(Medium)
- What are the common causes of a slow FastAPI endpoint?(Hard)
- How do you handle graceful shutdown?(Hard)
- How do you add caching to a FastAPI service?(Hard)
- What would you check before putting a FastAPI service into production?(Hard)
- When is FastAPI the wrong choice?(Medium)