This repository contains the implementation of Task 3 for the Architecture of Massively Scalable Applications course at the German University in Cairo, Department of Computer Science, under Assoc. Prof. Mervat Abu El-Kheir, Spring 2025. The task focuses on designing and implementing a NoSQL database schema using MongoDB, integrating it with a Spring Boot application, and managing entities such as Users and Posts with embedded and referenced relationships.
The project includes:
- A MongoDB database schema with two main entities: User and Post.
- Relationships:
- Document Referencing: Post references a User as its author.
- Document Embedding: Post contains a list of embedded Comments.
- Custom repositories and service layer methods to handle CRUD operations and specific business logic.
- RESTful controllers to expose functionality via APIs.
- Dockerization with multiple services: application instances, MongoDB, Mongo Express, and Nginx.
- Load balancing using Weighted Round Robin with Nginx.
- Load testing using JMeter to evaluate system performance.
- User:
id(String),username(String),email(String). - Post:
id(String),title(String),content(String),author(User reference),comments(List of embedded Comments). - Comment (embedded):
text(String),date(String).
- UserRepository: Extends
MongoRepositoryfor User entity management. - PostRepository: Extends
MongoRepositoryfor Post entity management.
- UserService:
- Basic CRUD operations (pre-implemented).
- Custom method:
updateUserUsername– updates a user's username by ID with error handling.
- PostService:
- Basic CRUD operations (pre-implemented).
getPostsByAuthorID: Retrieves posts by author ID with validation.addCommentToPost: Adds a comment to a post by ID.
- UserController:
- Basic CRUD handlers.
- PUT
/updateUserto update a user's username.
- PostController:
- Basic CRUD handlers.
- GET
/postsByUser/{id}to get posts by author ID. - POST
/{postId}/commentsto add a comment.
- MainController:
- Handles database seeding and instance testing.
- Includes a
docker-compose.ymlwith services:- Two Spring Boot app instances (named after your first and last name, e.g.,
random,student). mongofor MongoDB.mongo-expressfor MongoDB UI.nginxas a load balancer.
- Two Spring Boot app instances (named after your first and last name, e.g.,
nginx.confconfigured with:- Upstream:
YourName_52_1234. - Weighted Round Robin: weights of
2and1for the two app instances.
- Upstream:
- Test Plan:
YourName_20_52_1234.jmx- 400 requests (last digit of ID × 100), 4 sec ramp-up.
- Target:
localhost, port1234. - Request: GET to
MainController's route.
- Public API tests included and can be run with:
mvn test
(Uncomment test code if needed.)
- Ensure port
27017is free for MongoDB. - Follow CMS setup instructions if you're on Windows.
-
Edit
application.properties:ID=52-1234Name=YourName
-
Database name:
YourName_52_1234.
mvn clean install
docker-compose up- Seed the DB by hitting the seed endpoint via
MainController.
/users: Basic CRUD/users/updateUser: PUT (update username)/posts: Basic CRUD/posts/postsByUser/{id}: GET posts by author/posts/{postId}/comments: POST comment to post
- Proficient in MongoDB NoSQL schema design.
- Expertise in Spring Boot REST API development.
- Document embedding and referencing in MongoDB.
- Docker Compose for scalable, multi-service apps.
- Load balancing with Nginx (Weighted Round Robin).
- Load testing with JMeter.
- Robust API design and error handling for production.
- Database Name:
YourName_52_1234 - Port:
1234(based on ID52-1234)