The Student Grading System is a microservice-based web application that allows users to submit and retrieve student grades. It is built using Flask, MongoDB, Docker, and is designed for scalability and consistency. The system allows multiple instances to run simultaneously and synchronize data across all instances.
- Submit Grades: Submit student grades for different subjects.
- Retrieve Grades by Subject: Get the count, average, and median of student grades for a specific subject.
- Retrieve Grades by Student: Retrieve all grades for a specific student, along with their average.
- Scaling: Multiple instances can be spun up to support higher loads.
- Containerization: The application is fully containerized using Docker.
- Docker
- Docker Compose
- Python 3.9+
- MongoDB
├── app/
│ ├── __init__.py # Application factory
│ ├── routes.py # API routes
│ ├── models.py # Pydantic models
│ ├── services.py # Service layer to handle logic
│ ├── db.py # MongoDB connection
├── tests/
│ ├── test_routes.py # Unit and integration tests for API routes
├── Dockerfile # Dockerfile to containerize the Flask app
├── docker-compose.yml # Docker Compose configuration
├── haproxy.cfg # HAProxy configuration for load balancing
├── README.md # Project documentation
├── requirements.txt # Python dependencies
git clone https://github.com/your-username/student-grading-system.git
cd student-grading-system
To build the Docker containers, run:
docker-compose build
To start the application along with MongoDB and load balancer (HAProxy), run:
docker-compose up
This will spin up the following services:
- MongoDB: Running on port 27017.
- Grading Service: Running two instances on ports 8000 and 8001.
- HAProxy: Load balancer running on port 80.
- GET /: Returns a welcome message.
Response:
{
"message": "Welcome to the Student Grading System!"
}
- POST /grades/submit: Submits a grade for a student in a specific subject.
Request:
{
"student_id": "12345",
"subject": "Math",
"grade": 85
}
Response:
- Success:
201 Created
- Validation Error:
400 Bad Request
- GET /grades/subject/: Retrieves the count, average, and median of grades for a specific subject.
Response:
{
"subject": "Math",
"student_count": 10,
"average_grade": 85.5,
"median_grade": 88
}
- GET /grades/student/<student_id>: Retrieves all grades for a specific student, including the average grade.
Response:
{
"student_id": "12345",
"grades": {
"Math": 85,
"Science": 90
},
"average_grade": 87.5
}
The system is designed to be scalable. Multiple instances of the grading service can be spun up by adding more instances in the docker-compose.yml
file. HAProxy will balance the incoming requests across these instances to ensure that the system can handle high loads efficiently.
In the current setup, two instances of grading_service
are defined: one running on port 8000 and another on port 8001. You can increase or decrease the number of instances as needed by adding/removing entries in the docker-compose.yml
.
To run tests in the grading_service_test
container:
docker-compose run grading_service_test
The test suite includes unit and integration tests to ensure the functionality of the API endpoints.