Top 50 FastAPI Interview Questions
with Answers (Crash Prep)
1. What is FastAPI?
Answer: FastAPI is a modern Python web framework used to build high-performance REST APIs.
It is based on ASGI, supports async programming, automatic validation using Pydantic, and
provides automatic Swagger documentation.
2. Why FastAPI over Flask or Django?
Answer: FastAPI is faster, supports async natively, has automatic validation, automatic docs, and
better performance compared to Flask and Django.
3. What is ASGI?
Answer: ASGI (Asynchronous Server Gateway Interface) is a standard interface that allows
Python frameworks to handle async requests, multiple connections, and real-time operations
efficiently.
4. What is dependency injection?
Answer: Dependency injection is a design pattern where dependencies like database
connections or authentication logic are provided to functions automatically instead of creating
them manually.
5. What is Pydantic?
Answer: Pydantic is a library used in FastAPI for data validation and serialization using Python
type hints.
6. Difference between sync and async endpoints?
Answer: Sync endpoints block execution while async endpoints allow handling multiple requests
concurrently, improving performance.
7. What is REST?
Answer: REST is an architectural style used to design APIs using HTTP methods like GET, POST,
PUT, DELETE.
8. Difference between PUT and PATCH?
Answer: PUT replaces the entire resource while PATCH updates only specific fields.
9. What is stateless API?
Answer: A stateless API does not store client session data on the server. Each request contains
all required information.
10. What is HTTP status code 201?
Answer: It indicates that a resource was successfully created.
11. What is ORM?
Answer: ORM (Object Relational Mapping) allows interacting with databases using Python
objects instead of SQL queries.
12. What is SQLAlchemy?
Answer: SQLAlchemy is a popular ORM library used in Python for database operations.
13. What is primary key?
Answer: A primary key uniquely identifies each record in a database table.
14. What is indexing?
Answer: Indexing improves database query performance by allowing faster data retrieval.
15. What is N+1 problem?
Answer: It occurs when multiple database queries are executed unnecessarily, reducing
performance.
16. What is JWT?
Answer: JWT is a token-based authentication method used to securely transmit user identity
between client and server.
17. What are parts of JWT?
Answer: Header, Payload, Signature.
18. Where JWT is stored?
Answer: It is stored on client side, usually in local storage or HTTP-only cookies.
19. What is refresh token?
Answer: A refresh token is used to generate a new access token when the old one expires.
20. What is authentication?
Answer: Authentication verifies user identity.
21. What is authorization?
Answer: Authorization determines what actions a user can perform.
22. What is RBAC?
Answer: RBAC (Role-Based Access Control) restricts access based on user roles.
23. What is OAuth2?
Answer: OAuth2 is an authorization framework used for third-party login like Google login.
24. What is middleware?
Answer: Middleware runs before or after a request to process it.
25. What is dependency in FastAPI?
Answer: A dependency is a reusable function used for database, authentication, etc.
26. What is caching?
Answer: Caching stores frequently accessed data to improve performance.
27. What is Redis?
Answer: Redis is an in-memory database used for caching.
28. What is TTL?
Answer: TTL is the time duration before cached data expires.
29. What is pagination?
Answer: Pagination limits data returned per request.
30. How to improve API performance?
Answer: Using caching, indexing, async programming, and pagination.
31. What is connection pooling?
Answer: It reuses database connections instead of creating new ones.
32. What is load balancing?
Answer: It distributes traffic across multiple servers.
33. What is async advantage?
Answer: It allows handling multiple requests efficiently.
34. What is validation?
Answer: Validation ensures input data is correct.
35. What is schema?
Answer: A schema defines structure of data.
36. What is exception handling?
Answer: It manages errors gracefully.
37. What is secure password storage?
Answer: Passwords should be hashed using bcrypt.
38. What is token expiration?
Answer: It limits token validity time.
39. What is API versioning?
Answer: It manages API updates without breaking clients.
40. What is dependency override?
Answer: It replaces dependencies for testing.
41. What is eager loading?
Answer: It loads related data in single query.
42. What is lazy loading?
Answer: It loads data only when needed.
43. What is scalability?
Answer: Ability to handle increased load.
44. What is concurrency?
Answer: Handling multiple tasks simultaneously.
45. What is thread blocking?
Answer: When execution waits for task completion.
46. What is async await?
Answer: Used to define asynchronous code.
47. What is bearer token?
Answer: A token used in Authorization header.
48. What is API security?
Answer: Protecting APIs using authentication and validation.
49. What is database transaction?
Answer: A sequence of operations executed as single unit.
50. How FastAPI achieves high performance?
Answer: It uses async, ASGI, and efficient validation.