A reactive microservice for managing financial transactions in a distributed banking system. Built with Spring WebFlux for non-blocking, high-throughput transaction processing with MongoDB for flexible data storage.
This microservice handles all transaction operations including transfer registration, transaction history, and real-time balance updates. Implements reactive programming patterns for scalability and integrates with the Account microservice for atomic transfer execution.
- Reactive Architecture: Built with Spring WebFlux for non-blocking, asynchronous operations
- Contract-First API Design: OpenAPI 3.0 specifications with reactive patterns (Mono/Flux)
- Event-Driven Processing: Reactive streams for high-throughput transaction handling
- NoSQL Persistence: MongoDB for flexible, scalable transaction storage
- Microservice Orchestration: Coordinates with Account service for transfer execution
- Real-time Processing: Reactive chains for immediate transaction validation and processing
- Framework: Spring Boot 3.5.7 with WebFlux
- Language: Java 17
- Database: MongoDB (Reactive Driver)
- Reactive Core: Project Reactor (Mono/Flux)
- API Documentation: OpenAPI 3.0 (Swagger UI for WebFlux)
- Testing: JUnit 5, Mockito, Reactor Test
- Code Quality: JaCoCo (70% coverage), Checkstyle
- Build Tool: Maven
GET /- Retrieve all transactionsGET /{transactionId}- Retrieve transaction by ID (MongoDB ObjectId)GET /account/{accountId}- Get transaction history for an accountPOST /transfer- Register and execute a transfer transaction
- Java 17 or higher
- Maven 3.8+
- MongoDB 4.4+ (or MongoDB Atlas)
-
Clone the repository
git clone https://github.com/abengl/BankingSystem-TransactionMs.git cd transaction-ms -
Configure MongoDB
# application.properties spring.data.mongodb.uri=mongodb://localhost:27017/transaction_db # Account service URL for transfer execution account.service.url=http://localhost:8086/api/v1/internal/accounts
-
Build the project
mvn clean install
-
Run the application
mvn spring-boot:run
The service will start on http://localhost:8087
Access interactive API documentation at:
- Swagger UI: http://localhost:8087/swagger-ui.html
- OpenAPI Spec: http://localhost:8087/v3/api-docs
mvn testmvn test -Dtest=TransactionServiceTestmvn clean test jacoco:reportView report at target/site/jacoco/index.html
mvn checkstyle:checktransaction-ms/
βββ src/main/java/com/alessandragodoy/transactionms/
β βββ api/ # Generated reactive API interface
β β βββ TransactionApi.java
β βββ controller/ # Reactive controller implementation
β β βββ TransactionController.java
β βββ service/ # Reactive business logic
β β βββ TransactionService.java
β β βββ impl/
β β βββ TransactionServiceImpl.java
β βββ dto/ # Data Transfer Objects
β βββ model/ # MongoDB documents
β βββ repository/ # Reactive MongoDB repository
β βββ adapter/ # External service clients (WebClient)
β βββ exception/ # Custom exceptions
β βββ utility/ # Helper classes
βββ src/main/resources/
β βββ openapi/ # API contract
β β βββ transaction-api.yml
β βββ application.properties
βββ pom.xml
This service integrates with:
- Account Microservice: Executes balance transfers via reactive WebClient
- TRANSFER_OWN_ACCOUNT: Transfer between accounts owned by same customer
- TRANSFER_THIRD_PARTY_ACCOUNT: Transfer to different customer's account
- PENDING: Transaction initiated but not completed
- COMPLETED: Transfer successfully executed
- FAILED: Transfer execution failed
- Validation: Validate request parameters (amount > 0, accounts different)
- Account Verification: Verify both accounts exist and are active
- Balance Check: Confirm source account has sufficient funds
- Transaction Record: Save transaction to MongoDB with PENDING status
- Transfer Execution: Call Account service to update balances atomically
- Status Update: Update transaction status to COMPLETED or FAILED
- Test Coverage: Minimum 70% line and instruction coverage
- Reactive Testing: StepVerifier for Mono/Flux testing
- Code Style: Google Java Style Guide compliance
- Excluded from Coverage: Configuration, DTOs, generated code, exceptions
- Reactive Programming: Non-blocking I/O with Project Reactor (Mono/Flux)
- Contract-First Development: OpenAPI 3.0 with reactive patterns
- NoSQL Database: MongoDB for flexible, scalable storage
- WebClient Integration: Reactive HTTP client for microservice communication
- Functional Composition: Reactive chains for complex transaction flows
- Error Resilience: Comprehensive error handling in reactive streams
- Type-Safe APIs: Generated interfaces with reactive signatures
- Event-Driven: Asynchronous processing for high throughput
- Scalability: Handles thousands of concurrent transactions with minimal threads
- Responsiveness: Non-blocking I/O ensures low latency
- Backpressure: Reactive Streams protocol handles flow control
- Efficiency: Thread utilization optimized for I/O-bound operations
- Resilience: Built-in error handling and retry mechanisms
Alessandra Godoy
- Email: api@alessandragodoy.com