A specialized backend engine for atomic financial transfers, designed to solve the Double-Spending Problem in high-traffic fintech environments.
"In a system processing millions of transactions, a 0.01% race condition is a 100% failure in trust."
This is NOT a full banking system. This is a focused demonstration of handling concurrent financial transactions safely.
Key Challenge Solved: Preventing double-spending when multiple transfer requests hit the server simultaneously.
- Wallet Provisioning: Secure creation and funding of digital wallets.
- Atomic Transfers: Guaranteed "all-or-nothing" fund movements between users.
- Concurrency Control: Automatic detection and rejection of simultaneous conflicting transactions.
- Real-time Balance: Instant retrieval of current account state.
Uses JPA @Version to detect concurrent modifications:
- If User A and User B both try to transfer from the same wallet at the same millisecond, the first transaction succeeds.
- The second transaction fails immediately (Fail-fast) to prevent a "Lost Update."
- Benefit: Prevents double-spending without the performance bottleneck of heavy database locks.
The @Transactional annotation ensures that both wallet updates (Deduct from sender → Add to receiver) succeed or both fail:
- If ANY step fails, the entire transaction rolls back.
- Benefit: No partial transfers or "missing" money in the ledger.
- Java 17 & Spring Boot 3.4+
- Spring Data JPA (Hibernate)
- PostgreSQL (Chosen for robust transaction support)
- Spring Security & JWT (Stateless Authentication)
- Docker & Docker Compose (Containerized Environment)
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/auth/register |
Create a new user and wallet |
POST |
/api/auth/login |
Authenticate and receive JWT |
POST |
/api/wallet/deposit |
Add funds to current user's wallet |
POST |
/api/wallet/transfer |
Execute atomic transfer to another user |
GET |
/api/wallet/balance |
View current balance |
# Clone the repository
git clone https://github.com
# Start the PostgreSQL database
docker compose up -d
# Run the application
mvn spring-boot:run