Objective
The objective of this assignment is to assess your Backend development skills, problem-solving abilities, and code quality. You will be creating a secure and scalable backend service built on Node.js and Express.js. Similar to a minimal version of AnswersAi, this service will take in user requests and handle questions. This is designed to be used with a frontend application - and while you do not need to build any frontend, please keep this in mind while designing this service.
This assignment has been designed to be doable within 4-5 hours. You will have 5 days from when you receive the email to submit this assignment. If you need more time, please email [email protected] to request an extension.
You do not need to complete 100% of task requirements. Please complete as much as you can within the 5-day timeline - we value speed over perfection.
Requirements
-
Design a RESTful API using Node.js and Express.js with the following endpoints:
- POST /api/questions
- Accept user question, and return AI-generated answer.
- GET /api/questions/:questionId
- Retrieve specific question and answer by question ID.
- POST /api/users
- Create a new user account.
- GET /api/users/:userId
- Retrieve a user profile with a given userId
- GET /api/users/:userId/questions
- Retrieve all questions asked by user with a given userId
-
Implement authentication and authorization using JWT tokens or similar for API security.
- POST /api/auth/login: User login endpoint.
- POST /api/auth/logout: User logout endpoint.
- POST /api/auth/refresh: Refresh access token endpoint.
-
Design and implement a database schema for questions and users.
- Ensure that this is scalable, and be prepared to explain your design choice (relation vs non-relational, ACID guarantees, etc).
- Keep in mind that this service will scale to hundreds of thousands of users who might use it concurrently.
- Optional: Use an ORM (such as Sequelize or Knex.js).
-
Integrate with an AI service (e.g. OpenAI API) to generate answers. Use secure libraries/SDKs for API calls. We recommend langchain.
- Keep in mind that this service will scale to hundreds of thousands of users who might use it concurrently.
- Please document a solution (no need to code it) that ensures that users get timely responses even during periods of high load.
-
Containerize the application using Docker. Provide a Dockerfile for easy deployment.
-
Design a scalable infrastructure on AWS or GCP (EC2, RDS, ELB, ECS, Auto Scaling, etc.). Provide an architecture diagram or description.
- You do not need to deploy to the cloud. Simply provide an architecture diagram (using software like Lucidchart or on pen and paper), or a written description.
-
Write unit tests for critical components (API endpoints, database interactions) using Jest, Mocha, or similar libraries.
-
Provide a README with setup and running instructions, including dockerfile setup and running instructions, database setup, environment variables, and dependencies.
Evaluation Criteria
Your assignment will be evaluated based on the following criteria:
- API Design and Implementation (20%):
- Proper design and structure of API endpoints
- Adherence to RESTful principles
- Appropriate use of HTTP methods and status codes
- Clear and consistent API documentation
- Database Design and Interaction (20%):
- Proper database schema design
- Appropriate use of data types and constraints
- Efficient and optimized database queries
- Proper handling of database interactions (CRUD operations)
- Authentication and Authorization (15%):
- Secure implementation of user authentication using JWT tokens
- Proper handling of token creation, verification, and expiration
- Secure storage and handling of sensitive information (e.g., passwords)
- Code Quality and Best Practices (15%):
- Adherence to coding best practices and conventions
- Proper code organization and modularization
- Appropriate use of error handling and logging
- Efficient and optimized code implementation