0% found this document useful (0 votes)
60 views6 pages

Python Backend Developer Interview Q&A

Python questions for interview
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views6 pages

Python Backend Developer Interview Q&A

Python questions for interview
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

FULL 300+ PYTHON BACKEND DEVELOPER INTERVIEW QUESTIONS

PYTHON (60 QUESTIONS)

1. Difference between list, tuple, set, dict?

2. What is mutability?

3. Explain list comprehension.

4. What are generators?

5. What is yield?

6. What is iterator protocol?

7. Explain GIL.

8. Threading vs multiprocessing?

9. What is asyncio?

10. What is event loop?

11. Explain decorators.

12. Decorator with arguments.

13. Lambda functions.

14. Difference between *args and **kwargs.

15. What are dunder methods?

16. What is __str__ vs __repr__?

17. What is __slots__?

18. Explain inheritance.

19. Types of inheritance.

20. Method Resolution Order.

DJANGO (70 QUESTIONS)

1. What is MVT architecture?

2. Django request lifecycle.

3. What are apps in Django?

4. What is [Link]?

5. Django ORM advantages.

6. What is queryset?

7. What is select_related?

8. What is prefetch_related?

9. N+1 query problem.


10. What are migrations?

11. makemigrations vs migrate.

12. Raw SQL in Django.

13. What are model managers?

14. What is Meta class?

15. How to add database index?

16. Django middleware order.

17. Write custom middleware.

18. Django signals.

19. post_save vs pre_save.

20. What is csrf_token?

DJANGO REST FRAMEWORK (50 QUESTIONS)

1. What is DRF?

2. Serializer vs ModelSerializer.

3. Nested serializers.

4. validate() vs validate_field().

5. What are APIView?

6. What is GenericAPIView?

7. Mixins usage.

8. ViewSets advantages.

9. Router usage.

10. Pagination types.

11. Filtering backends.

12. SearchFilter.

13. OrderingFilter.

14. Throttling classes.

15. JWT authentication.

16. Token authentication.

17. SessionAuthentication.

18. How to override list()?

19. Custom permissions.

20. API documentation.


FASTAPI (60 QUESTIONS)

1. ASGI vs WSGI.

2. Why FastAPI is fast?

3. What is Pydantic?

4. BaseModel validation.

5. Field() usage.

6. Dependency Injection via Depends().

7. Path vs query parameters.

8. UploadFile vs File().

9. Streaming responses.

10. Logging middleware.

11. Custom exception handlers.

12. OAuth2PasswordBearer.

13. JWT Authentication.

14. BackgroundTasks.

15. Startup events.

16. Shutdown events.

17. CORS setup.

18. APIRouter usage.

19. Async vs sync.

20. Database session handling.

SQL (40 QUESTIONS)

1. Inner vs left join.

2. Right vs full join.

3. What is ACID?

4. What is normalization?

5. Types of normalization.

6. What is index?

7. Composite index.

8. Unique index.

9. What is foreign key?

10. Primary key vs unique key.

11. What is group by?


12. What is having?

13. Window functions.

14. Rank vs dense_rank.

15. Query for second highest salary.

16. SQL injection.

17. Transactions.

18. Commit vs rollback.

19. Explain EXPLAIN PLAN.

20. Subqueries.

REDIS (30 QUESTIONS)

1. What is Redis?

2. Redis data types.

3. TTL usage.

4. What is caching?

5. Cache invalidation strategies.

6. Redis pub/sub.

7. Rate limiting using Redis.

8. Redis pipeline.

9. What is distributed lock?

10. Redis vs Memcached.

CELERY (25 QUESTIONS)

1. What is Celery?

2. Worker vs broker.

3. Redis vs RabbitMQ.

4. How to schedule tasks?

5. Retry mechanism.

6. apply_async vs delay.

7. Task chaining.

8. Celery Beat.

9. Monitoring Celery.

10. Idempotent tasks.


REST API (20 QUESTIONS)

1. What is REST?

2. HTTP methods.

3. Idempotency.

4. Versioning strategies.

5. Pagination.

6. Caching headers.

7. ETag usage.

8. JWT flow.

9. OAuth2 flow.

10. Status codes.

DEPLOYMENT & DEVOPS (25 QUESTIONS)

1. What is Docker?

2. Dockerfile basics.

3. Docker volumes.

4. Docker compose.

5. Gunicorn vs Uvicorn.

6. Nginx as reverse proxy.

7. Environment variables.

8. Load balancing.

9. Horizontal scaling.

10. CI/CD pipelines.

SECURITY (20 QUESTIONS)

1. SQL Injection.

2. XSS.

3. CSRF.

4. CORS.

5. Password hashing.

6. bcrypt vs sha256.

7. JWT security risks.

8. HTTPS.

9. OAuth2 roles.
10. API key safety.

LINUX + GIT (20 QUESTIONS)

1. grep usage.

2. ps aux usage.

3. tail logs.

4. chmod usage.

5. Git merge vs rebase.

6. Git stash.

7. Cherry pick.

8. Git workflow.

9. SSH keys.

10. Git conflicts.

SYSTEM DESIGN (10 QUESTIONS)

1. Design rate limiter.

2. Design file upload service.

3. Design notification system.

4. Design scalable login system.

5. Design URL shortener.

(End of Full Question List)

Common questions

Powered by AI

JWT (JSON Web Tokens) and session authentication differ significantly in their approach. JWTs are stateless, eliminating the need for server-side storage of user sessions, which enhances scalability by reducing the server's memory burden and allows for a distributed architecture without session synchronization issues. However, JWTs must be managed carefully to prevent token theft and replay attacks. In contrast, session authentication requires storing session data on the server, potentially limiting scalability due to increased memory usage and complexity in a distributed setup. It is inherently more secure regarding token renewal and invalidation since server-side sessions can be invalidated at will, making it easier to manage user state at the cost of scaling efficiency .

In Django, middleware components function as a series of hooks that interact with requests and responses during the request lifecycle. They can process requests before the view is called, and responses after the view has been processed, thereby enabling functionalities like authentication, logging, cross-site request forgery protection, etc. Custom middleware can be created to introduce additional processing steps that are not covered by built-in middleware, such as custom logging, manipulating request and response headers, modifying data on-the-fly, or implementing request-rate limiting. This ability to inject custom functionality helps adapt applications to specific business or performance needs .

The choice between threading and multiprocessing in Python significantly impacts the performance based on how tasks are executed. Threading in Python is constrained by the Global Interpreter Lock (GIL), which allows only one thread to execute Python code at a time within a single process, making it less effective for CPU-bound tasks. Threading is useful for I/O-bound tasks where the program spends more time waiting for input/output operations to complete. On the other hand, multiprocessing creates separate processes with independent memory space, bypassing the GIL, and is suitable for CPU-bound tasks as it can fully utilize multiple CPU cores, providing true parallelism .

*args and **kwargs in Python allow functions to accept a variable number of arguments, enhancing their flexibility. *args captures additional positional arguments beyond those explicitly defined in the function signature as a tuple. This is useful when the exact number of positional arguments needed to be handled is unknown. **kwargs captures arbitrary keyword arguments as a dictionary, allowing the function to handle named arguments that were not anticipated at the time of function definition. Together, these constructs enable more generic and adaptable function definitions that can operate over a wide range of input scenarios without modification .

ACID properties—Atomicity, Consistency, Isolation, and Durability—are critical for ensuring reliable and consistent database transactions. Atomicity guarantees that a transaction is all-or-nothing, meaning either all operations are completed successfully or none are. Consistency ensures a transaction brings the database from one valid state to another, maintaining data integrity. Isolation prevents transactions from interfering with each other, thus maintaining consistency in concurrent transactions. Durability ensures that once a transaction is committed, it is permanently recorded, even in the event of system failures. Together, these properties maintain system reliability by protecting against data loss and inconsistencies, which is crucial for business-critical applications .

ModelSerializers in DRF provide an abstraction that automatically generates fields and validations based on the model, reducing boilerplate code and ensuring consistency between the database schema and the API response. In contrast, a Serializer offers more flexibility and control, requiring explicit definition of all fields and validations, which allows customization independent of the database structure. This distinction affects API development by influencing the balance between ease of use and customization; ModelSerializers are ideal for rapid development with minimal code, whereas Serializers are preferred when the API specifications diverge from the underlying model structure .

Django ORM provides a high-level abstraction over raw SQL, enabling developers to interact with the database using Python code, which increases productivity and reduces the likelihood of SQL injection vulnerabilities. It abstracts database operations, making it easier to switch database backends without changing the application logic. This feature is particularly useful in scalable web applications where maintainability and portability are critical. Additionally, the ORM automatically translates Python queries into efficient SQL queries, enhancing performance by optimizing database access .

Using the `__slots__` attribute in Python restricts attribute assignment to a fixed set of fields, thereby eliminating the need for a per-instance `__dict__`. This can significantly reduce memory overhead, which accelerates access to attribute values, leading to performance improvements. It is particularly beneficial in scenarios involving the creation of a large number of instances, such as in data processing or simulation, where memory savings translate into substantial performance boosts. However, it reduces flexibility, as it disables features like dynamic creation of attributes on instances .

FastAPI's dependency injection system, through the `Depends()` function, allows for clean, modular code that separates concerns effectively. Key considerations include understanding how to manage lifecycle states of dependencies, as FastAPI resolves them and injects them into route endpoints. The benefits of using this system include improved testability due to granular control over dependencies, enhanced reusability of code components, and clear separation of business logic from infrastructural concerns. This design pattern provides cleaner architectures and makes codebases more maintainable and scalable as it grows .

In Celery, a broker functions as a message queue that distributes task messages among different workers, while a worker performs the actual tasks defined by the Celery application. The separation is crucial as the broker ensures reliable message transmission, queuing, and routing of tasks, which enables distributed task processing. This allows workers to perform tasks concurrently and asynchronously, contributing to system scalability and fault tolerance. The broker-worker model also decouples task execution, i.e., even if one worker fails, other workers can continue processing, while brokers manage task distribution seamlessly .

You might also like