This assignment requires you to create a Kubernetes-based task management system using a simplified architecture and a Next.js client application.
The goal of this project is to develop a Kubernetes-based system that handles tasks using a microservices architecture. You will build a system where tasks are managed by an API server, processed by a task engine, communicated via RabbitMQ, and stored in a MongoDB database. Additionally, you will create a Next.js client application to interact with the system.
Ensure you have the following tools installed on your machine:
- Docker
- Kubernetes (Minikube or any other local K8S setup)
- Node.js
- MongoDB
Clone the repository to your local machine:
git clone https://github.com/BrainbaseHQ/template-k8s-toy-problem
cd template-k8s-toy-problem
Start your Kubernetes cluster (using Minikube or any other local K8S setup):
minikube start
Your project should roughly have the following structure:
template-k8s-toy-problem/
│
├── api-server/
│ ├── Dockerfile
│ ├── index.js
│ ├── package.json
│ └── k8s/
│ ├── deployment.yaml
│ └── service.yaml
│
├── task-engine/
│ ├── Dockerfile
│ ├── index.js
│ ├── package.json
│ └── k8s/
│ ├── deployment.yaml
│ └── service.yaml
│
├── client/
│ ├── Dockerfile
│ ├── pages/
│ │ └── index.js
│ ├── package.json
│ └── k8s/
│ ├── deployment.yaml
│ └── service.yaml
│
├── k8s/
│ ├── mongodb-deployment.yaml
│ ├── rabbitmq-deployment.yaml
│ └── ingress.yaml
│
└── README.md
- api-server: Handles client requests and interacts with RabbitMQ and MongoDB.
- task-engine: Processes tasks from RabbitMQ, calls OpenAI to generate code, and updates MongoDB.
- client: Next.js application for interacting with the system.
- RabbitMQ: Message broker for task distribution.
- MongoDB: Database for storing task information.
Tasks in MongoDB should follow this schema:
{
"_id": "unique-task-id",
"user_id": "XXX",
"objective": "Create a function that sums up three numbers.",
"language": "python",
"created_at": "2024-07-14T00:00:00Z",
"completed_at": null,
"status": "pending",
"code": ""
}
- RabbitMQ should feed the task engine with 10 tasks at a time.
- Tasks should have a TTL (time-to-live) of 5 minutes.
- Tasks should retry until acknowledged.
- The task engine is responsible for taking tasks, calling OpenAI to write the code in the specified language for the given objective, and updating the
code
field in the task. - Task status should be updated to "running" when processing starts and to "completed" or "failed" after processing.
- The client should be a single-page Next.js application with two input boxes for objective and language.
- The client should display a list of the user's tasks.
- All requests to MongoDB should go through the API server.
- API server can handle
/tasks/add
and/tasks/get
endpoints. - Tasks are stored in MongoDB.
- API server sends tasks to RabbitMQ.
- Task Engine retrieves tasks from RabbitMQ.
- Task Engine retrieves tasks from RabbitMQ.
- Task Engine processes tasks, calls OpenAI to generate code, updates MongoDB with the code, and updates the task status.
- Next.js client with input boxes for objective and language.
- Client displays a list of the user's tasks.
- Client communicates with the API server.
Once all four milestones are successfully completed, you should have a fully functional Kubernetes-based task management system with a client application.
Ensure that the system is scalable, fault-tolerant, and easy to maintain. This aligns with Brainbase's goal of providing reliable and efficient automation solutions.