0% found this document useful (0 votes)
11 views3 pages

Python Microservice Assessment Requirements

This document outlines the requirements for a Python coding assessment focused on building a microservice backend using FastAPI, PostgreSQL, and Redis. Candidates must demonstrate skills in API development, data modeling, database integration, caching, and Dockerization, with specific functional requirements for CRUD operations on products. Deliverables include a GitHub repository, README, Docker files, and optional enhancements such as unit tests and API documentation.

Uploaded by

magic.mike906
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)
11 views3 pages

Python Microservice Assessment Requirements

This document outlines the requirements for a Python coding assessment focused on building a microservice backend using FastAPI, PostgreSQL, and Redis. Candidates must demonstrate skills in API development, data modeling, database integration, caching, and Dockerization, with specific functional requirements for CRUD operations on products. Deliverables include a GitHub repository, README, Docker files, and optional enhancements such as unit tests and API documentation.

Uploaded by

magic.mike906
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

Python Developer Coding Assessment – Requirement

Document

Overview

This document describes the requirements for a coding assessment to build a


microservice backend using Python. The candidate should demonstrate proficiency in
API development, database interaction, caching, and containerization using Docker.

Technology Stack

• Python with FastAPI


• SQLAlchemy or any equivalent ORM
• PostgreSQL
• Redis / any equivalent for caching
• Docker and Docker Compose

Functional Requirements

1. API Development

Develop a FastAPI application exposing the following endpoints:

• GET /products – List all products


• POST /products – Add a new product
• GET /products/{id} – Get product by ID
• PUT /products/{id} – Update product by ID
• DELETE /products/{id} – Delete product by ID

2. Data Modeling

Design a SQLAlchemy (or equivalent ORM) model for Product with the following fields:

• id: UUID or auto-incrementing ID


• name: String, required
• description: String
• price: Float, required
• in_stock: Boolean

3. Database Integration

• Configure the FastAPI app to connect to a PostgreSQL database


• Implement basic CRUD operations for the product model

4. Caching with Redis

• Cache the GET /products/{id} response using Redis


• Set the cache expiry to 60 seconds
• Invalidate the cache when a product is updated or deleted

5. Dockerization

• Create a Dockerfile for the FastAPI application


• Create a [Link] file including:
o FastAPI app
o PostgreSQL service
o Redis service

6. Optional Enhancements (Bonus)

• Use Pydantic models for request/response validation


• Write at least one basic unit test for any endpoint
• Expose interactive API documentation using Swagger UI (/docs)
• Use .env files to manage environment variables
• Provide a Postman collection or cURL commands to test the API

Deliverables

Submit the following:

• GitHub repository or zipped folder containing your project files


• README file with clear setup instructions
• Dockerfile and [Link]
• .[Link] file to describe expected environment variables
• (Optional) Postman collection or API test script
Timeline

Within 5 days from the time of task assignment

Common questions

Powered by AI

Dockerization is important because it facilitates consistent environments across different stages of development and ensures isolated and repeatable build and deployment processes. Key components in the document include the creation of a Dockerfile for building the FastAPI application container and a docker-compose.yml file that orchestrates the entire environment, including services for the FastAPI app, PostgreSQL, and Redis. This setup ensures modularity and scalability.

Caching should be implemented for the 'GET /products/{id}' endpoint using Redis, with a cache expiry time set to 60 seconds. Cache invalidation should occur when a product is updated or deleted. This setup ensures efficient data retrieval by reducing database load while maintaining data consistency through cache invalidation strategies.

Including a Postman collection or cURL commands is significant because they provide ready-to-use examples for testing API functionality, serving as robust references for both manual and automated testing environments. This inclusion facilitates dependency management and quick validation of functionality, which is vital for collaborative development and continuous integration processes. It also aids in efficiently demonstrating the microservice's capabilities to stakeholders.

Optional enhancements include using Pydantic models for request and response validation, writing a basic unit test for any endpoint, exposing interactive API documentation via Swagger UI (/docs), using .env files for environment variable management, and providing a Postman collection or cURL commands for API testing. These enhancements improve functionality by ensuring data integrity and robustness, facilitating documentation, enhancing testability, and improving the configuration and deployment processes.

API documentation plays a crucial role by providing developers with clear and comprehensive information on how to interact with the API endpoints. Interactive documentation, such as Swagger UI, further enhances this by offering a user-friendly interface to explore available endpoints, view request/response models, test API interactions, and understand integration points, thus improving usability and reducing development time and errors.

The main components required for the microservice backend development include API development with FastAPI, database interaction using SQLAlchemy or an equivalent ORM with PostgreSQL, caching mechanism using Redis or a similar solution, and containerization with Docker. The functionality also includes developing CRUD operations endpoints for products, data modeling with SQLAlchemy, implementing caching strategies, and ensuring proper Docker integration with Docker Compose.

The document suggests managing environment variables using .env files. This practice is critical because it separates configuration from code, making it easier to manage different environments such as development, testing, and production. It also enhances security by preventing sensitive information, like database credentials, from being hardcoded in the application.

The implementation of CRUD operations aligns with the functional requirements by allowing the microservice to manage product data effectively. CRUD operations—Create (POST), Read (GET), Update (PUT), and Delete (DELETE)—are needed to handle products' lifecycle, which is essential for fulfilling the API development requirements that include endpoints for listing, adding, retrieving, updating, and deleting products.

Upon completing the coding assessment, the candidate must provide a GitHub repository or zipped folder containing the project files, a README file with clear setup instructions, Dockerfile and docker-compose.yml, and a .env.sample file describing the expected environment variables. Additionally, optional enhancements such as a Postman collection, API test scripts, unit tests, and exposed API documentation are encouraged.

The database model for the Product entity requires fields such as id (UUID or auto-incrementing ID), name (string, required), description (string), price (float, required), and in_stock (boolean). These attributes are significant as they encapsulate the essential data properties of a product, ensuring comprehensive data representation and facilitating robust database operations.

You might also like