This Spring Boot application demonstrates how to work with multiple datasources and implement efficient parallel data fetching.
- Multiple database connections (PostgreSQL and MySQL)
- Parallel data fetching using CompletableFuture
- Database migrations using both Liquibase and Flyway
- Exception handling with Problem Details
- Virtual Threads support
- Swagger API documentation
- PostgreSQL Database: Stores member information
- Managed by Liquibase migrations
- Uses sequence-based ID generation
- MySQL Database: Stores cardholder information
- Managed by Flyway migrations
- Uses identity-based ID generation
- DetailsService: Implements parallel data fetching
- Uses CompletableFuture for asynchronous operations
- Implements timeout handling (5 seconds)
- Provides comprehensive error handling
- Data Models:
Member
: Core member information (PostgreSQL)CardHolder
: Card-related information (MySQL)
- Exception Handling:
CustomServiceException
: For service-layer errorsMemberNotFoundException
: For missing member scenarios- Problem Details support for standardized error responses
spring.datasource.url=jdbc:postgresql://localhost:5432/memberdb
spring.datasource.username=postgres
spring.datasource.password=postgres
app.datasource.cardholder.url=jdbc:mysql://localhost:3306/cardholderdb
app.datasource.cardholder.username=user
app.datasource.cardholder.password=password
- Start PostgreSQL and MySQL databases
- Configure database connections in
application.properties
- Run the application: The databases will be automatically initialized
- Access Swagger UI: http://localhost:8080/swagger-ui.html
- Database migrations run automatically on startup
- Data bootstrapping occurs via
ApplicationReadyEvent
- Parallel data fetching implemented using Spring's @Qualifier("applicationTaskExecutor")
- Virtual Threads enabled for improved scalability
- HikariCP connection pooling with optimized settings
- Automatic commit disabled for better transaction control
GET /api/details/{memberId}
: Fetches member details from both databases in parallel- Returns combined information from both datasource's
- Implements timeout handling (5 seconds)
- Returns standardized error responses using Problem Details
- Integration tests demonstrate concurrent request handling
- MockMvcTester used for API testing
- Testcontainers with parallel startup for database testing