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.

PydanticDependenciesAsyncAuthProductionAria-powered explanations
0 / 100 answered
0%
4 Easy69 Medium27 Hard

Showing 120 of 100

#1What is FastAPI and what does it build on?

Easy
Fundamentals

#2How does FastAPI decide where a parameter comes from?

Medium
Fundamentals

#3Why does route ordering matter?

Medium
Fundamentals

#4What is an APIRouter and how should you structure a large application?

Medium
Fundamentals

#5What does response_model do and why should you use it?

Medium
Fundamentals

#6How does FastAPI generate OpenAPI documentation?

Easy
Fundamentals

#7What is the difference between FastAPI and Flask or Django REST Framework?

Medium
Fundamentals

#8What is ASGI and why does it matter?

Medium
Fundamentals

#9How do you handle application startup and shutdown?

Medium
Fundamentals

#10How does middleware work in FastAPI?

Medium
Fundamentals

#11What are background tasks and what are their limits?

Medium
Fundamentals

#12How do you handle file uploads?

Medium
Fundamentals

#13How do you return a streaming response?

Hard
Fundamentals

#14How do WebSockets work in FastAPI?

Hard
Fundamentals

#15What does Pydantic actually do for you?

Easy
Pydantic

#16What changed between Pydantic v1 and v2?

Medium
Pydantic

#17Should you use the same Pydantic model for input and output?

Medium
Pydantic

#18How do you write a custom validator?

Medium
Pydantic

#19What is the difference between Optional, a default, and exclude_unset?

Hard
Pydantic

#20How do you validate nested and list data?

Medium
Pydantic

Showing 120 of 100

Ask Aria about FastAPI

Sign in to chat with Aria

All 100 FastAPI questions at a glance
  1. What is FastAPI and what does it build on?(Easy)
  2. How does FastAPI decide where a parameter comes from?(Medium)
  3. Why does route ordering matter?(Medium)
  4. What is an APIRouter and how should you structure a large application?(Medium)
  5. What does response_model do and why should you use it?(Medium)
  6. How does FastAPI generate OpenAPI documentation?(Easy)
  7. What is the difference between FastAPI and Flask or Django REST Framework?(Medium)
  8. What is ASGI and why does it matter?(Medium)
  9. How do you handle application startup and shutdown?(Medium)
  10. How does middleware work in FastAPI?(Medium)
  11. What are background tasks and what are their limits?(Medium)
  12. How do you handle file uploads?(Medium)
  13. How do you return a streaming response?(Hard)
  14. How do WebSockets work in FastAPI?(Hard)
  15. What does Pydantic actually do for you?(Easy)
  16. What changed between Pydantic v1 and v2?(Medium)
  17. Should you use the same Pydantic model for input and output?(Medium)
  18. How do you write a custom validator?(Medium)
  19. What is the difference between Optional, a default, and exclude_unset?(Hard)
  20. How do you validate nested and list data?(Medium)
  21. What is model_config and what settings matter?(Medium)
  22. How do you handle camelCase JSON with snake_case Python?(Medium)
  23. What is a discriminated union and why use one?(Hard)
  24. How should you represent money and decimals?(Medium)
  25. What is Pydantic Settings and why use it for configuration?(Medium)
  26. How do you handle validation of query parameters and filters?(Medium)
  27. What is the performance cost of Pydantic validation?(Hard)
  28. How do you convert between ORM models and Pydantic schemas?(Hard)
  29. What happens when validation fails, and how do you customise it?(Medium)
  30. How do you version an API in FastAPI?(Medium)
  31. How does FastAPI's dependency injection work?(Medium)
  32. What is a yield dependency and when does the teardown run?(Hard)
  33. How do you manage a database session per request?(Hard)
  34. What is dependency caching and when does it bite?(Hard)
  35. What is a class-based dependency and when is it useful?(Medium)
  36. How do you apply a dependency to every route in a group?(Medium)
  37. How do you override dependencies in tests?(Medium)
  38. Should business logic live in dependencies or in services?(Medium)
  39. How do you share expensive resources across requests?(Medium)
  40. What is the Annotated style for dependencies and why is it preferred?(Medium)
  41. How do you implement pagination as a reusable dependency?(Medium)
  42. What happens if a dependency raises an exception?(Medium)
  43. How do you inject the current user and enforce permissions?(Medium)
  44. What is the difference between a dependency and middleware for cross-cutting concerns?(Medium)
  45. What is the difference between def and async def route handlers?(Medium)
  46. What happens if you block the event loop?(Hard)
  47. When does async actually improve performance?(Medium)
  48. How do you call several services concurrently in a handler?(Medium)
  49. How does the thread pool for sync handlers work and can you exhaust it?(Hard)
  50. What is the right async database setup?(Hard)
  51. How do you make outbound HTTP calls correctly?(Medium)
  52. What is the difference between BackgroundTasks and a task queue?(Medium)
  53. How do you handle timeouts for a request?(Hard)
  54. What happens when a client disconnects mid-request?(Hard)
  55. How do you run CPU-bound work in a FastAPI service?(Medium)
  56. What are the most common async mistakes in FastAPI code?(Medium)
  57. How do you decide between sync and async for a new service?(Medium)
  58. How does Uvicorn with multiple workers interact with async?(Hard)
  59. How do you implement JWT authentication in FastAPI?(Medium)
  60. What is the difference between OAuth2PasswordBearer and HTTPBearer?(Medium)
  61. Should you store JWTs in localStorage or a cookie?(Hard)
  62. How do you handle token refresh?(Hard)
  63. How do you configure CORS correctly?(Medium)
  64. How do you prevent SQL injection and other injection attacks?(Medium)
  65. How do you implement rate limiting?(Hard)
  66. What security headers should a FastAPI service send?(Medium)
  67. How do you handle authorisation that depends on the resource?(Hard)
  68. How should passwords be stored and verified?(Medium)
  69. How do you protect the OpenAPI docs in production?(Medium)
  70. What is mass assignment and how does Pydantic help or hurt?(Medium)
  71. How do you handle secrets in a FastAPI application?(Medium)
  72. What should you never include in an error response?(Medium)
  73. How does exception handling work in FastAPI?(Medium)
  74. How should you structure error responses?(Medium)
  75. What is the difference between returning a Response and returning data?(Medium)
  76. How do you set the status code for a response?(Easy)
  77. How do you handle a domain exception cleanly?(Medium)
  78. How do you add a correlation ID to every request and response?(Medium)
  79. How should logging be set up in a FastAPI service?(Medium)
  80. What should a health check endpoint do?(Medium)
  81. How do you return a file or a large download?(Medium)
  82. How do you document error responses in OpenAPI?(Medium)
  83. How do you test a FastAPI application?(Medium)
  84. How do you test with a real database?(Hard)
  85. How do you test authentication-protected endpoints?(Medium)
  86. How do you mock external HTTP calls in tests?(Medium)
  87. What should you test at the API level versus the service level?(Medium)
  88. How do you test WebSocket endpoints?(Hard)
  89. How do you test that validation works as intended?(Medium)
  90. How do you keep a test suite fast as the application grows?(Medium)
  91. What is contract testing and does FastAPI help?(Hard)
  92. How do you test background tasks and async side effects?(Medium)
  93. How do you deploy a FastAPI application?(Medium)
  94. How many workers should you run and why?(Hard)
  95. What should you monitor in a FastAPI service?(Medium)
  96. What are the common causes of a slow FastAPI endpoint?(Hard)
  97. How do you handle graceful shutdown?(Hard)
  98. How do you add caching to a FastAPI service?(Hard)
  99. What would you check before putting a FastAPI service into production?(Hard)
  100. When is FastAPI the wrong choice?(Medium)