A Spring Boot service that aggregates user data from multiple databases (PostgreSQL and MongoDB).
- REST API endpoint
/users
for retrieving aggregated user data - Support for multiple data sources (PostgreSQL and MongoDB)
- Caching with Caffeine for improved performance
- OpenAPI documentation with Swagger UI
- Automatic database schema updates
- Debug-friendly SQL logging
- Docker support for easy deployment
For Docker deployment:
- Docker
- Docker Compose
For local development:
- Java 21 or higher
- Maven
- PostgreSQL 12 or higher
- MongoDB 6 or higher
- Clone the repository:
git clone <repository-url>
cd aggregation-service
- Build and start the services using Docker Compose:
docker-compose up -d
The application will be available at http://localhost:8080
- Start PostgreSQL and create a database named
users_db
- Start MongoDB service
- Configure the application in
application.yml
if needed (default configuration below) - Build and run the application:
mvn clean install
mvn spring-boot:run
The application uses Docker Compose to set up the following services:
-
Application Service:
- Built from the Dockerfile
- Exposes port 8080
- Connects to PostgreSQL and MongoDB containers
-
PostgreSQL Service:
- Uses PostgreSQL 15 Alpine image
- Exposes port 5432
- Creates database
users_db
- Persists data using Docker volume
-
MongoDB Service:
- Uses MongoDB 6 image
- Exposes port 27017
- Persists data using Docker volume
The application uses the following default configuration in application.yml
:
spring:
data:
mongodb:
host: localhost
port: 27017
database: users_db
auto-index-creation: true
datasource:
url: jdbc:postgresql://localhost:5432/users_db
username: postgres
password: root
driver-class-name: org.postgresql.Driver
jpa:
hibernate:
ddl-auto: update
show-sql: true
properties:
hibernate:
format_sql: true
dialect: org.hibernate.dialect.PostgreSQLDialect
cache:
type: caffeine
caffeine:
spec: maximumSize=500,expireAfterWrite=300s
When running with Docker, the environment variables in docker-compose.yml will override these settings.
OpenAPI documentation is available at:
- Swagger UI: http://localhost:8080/swagger-ui.html
- OpenAPI JSON: http://localhost:8080/v3/api-docs
GET /users
: Get all users from both PostgreSQL and MongoDBGET /users/search?query={query}
: Search users by username across both databases
- Check container status:
docker-compose ps
- View container logs:
docker-compose logs -f app
- Restart services:
docker-compose restart
-
MongoDB Connection Issues:
- Ensure MongoDB service is running:
sc query MongoDB
- Start MongoDB if stopped: Run Command Prompt as Administrator and execute
net start MongoDB
- Ensure MongoDB service is running:
-
PostgreSQL Connection Issues:
- Verify PostgreSQL service is running
- Check database exists:
users_db
- Verify credentials in
application.yml
The application uses the following log levels:
DEBUG
for application-specific logsINFO
for Spring Data operationsDEBUG
for SQL queries
These can be adjusted in the application.yml
file.