A production-grade, distributed fintech payment backend built with Spring Boot Microservices β inspired by real-world systems like PayPal and Stripe.
- Overview
- Architecture
- Services
- Tech Stack
- Getting Started
- API Reference
- Key Design Patterns
- Project Structure
This system implements a microservices-based payment platform with:
- Stateless JWT authentication
- Event-driven communication via Kafka
- Pessimistic locking for financial safety
- Idempotency protection across all services
- Centralized routing via API Gateway
- Docker Compose for single-command deployment
βββββββββββββββββββ
HTTP :8080 β API Gateway β JWT Validation
Client βββββββββββββββΆβ (Spring Cloud) β Centralized Routing
ββββββββββ¬βββββββββ
β
ββββββββββββββββββββΌβββββββββββββββββββββ
β β β
βΌ βΌ βΌ
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββ
β user-service β β transaction β β wallet-service β
β :8081 β β service β β :8090 β
β JWT + Auth β β :8082 β β Pessimistic Lock β
ββββββββββββββββ ββββββββ¬ββββββββ ββββββββββββββββββββ
β
β Kafka (txn-initiated)
βΌ
ββββββββββββββββββββββββ
β Apache Kafka β
β + Zookeeper β
ββββββββ¬ββββββββββββββββ
β
ββββββββββββββ΄βββββββββββββ
βΌ βΌ
βββββββββββββββββββββββ ββββββββββββββββββββ
β notification-serviceβ β reward-service β
β :8084 β β :8085 β
β Kafka Consumer β β Kafka Consumer β
βββββββββββββββββββββββ ββββββββββββββββββββ
| Service | Port | Responsibility |
|---|---|---|
api-gateway |
8080 | Centralized routing, JWT enforcement |
user-service |
8081 | Signup, Login, JWT issuance |
transaction-service |
8082 | Create transactions, publish Kafka events |
notification-service |
8084 | Consume events, send notifications |
reward-service |
8085 | Consume events, calculate reward points |
wallet-service |
8090 | Balance management, holds, credits, debits |
| Category | Technology |
|---|---|
| Language | Java 17 |
| Framework | Spring Boot 3.x |
| API Gateway | Spring Cloud Gateway (WebFlux) |
| Messaging | Apache Kafka + Zookeeper |
| Auth | JWT (Stateless) |
| Security | Spring Security |
| Database | H2 (In-Memory) |
| ORM | Spring Data JPA / Hibernate |
| Containerization | Docker + Docker Compose |
| Build Tool | Maven |
- Docker Desktop installed and running
- Java 17+ (only needed for local development without Docker)
# 1. Clone the repository
git clone https://github.com/yourusername/FinTech-Payment-Backend.git
cd FinTech-Payment-Backend
# 2. Start all services with a single command
docker-compose up -d --build
# 3. Verify all services are running
docker-compose psAll 8 containers (Zookeeper, Kafka + 6 microservices) will start automatically.
# Stop all services
docker-compose down
# View logs of all services
docker-compose logs -f
# View logs of a specific service
docker-compose logs -f user-service
# Restart a specific service
docker-compose restart transaction-serviceAll requests go through the API Gateway at http://localhost:8080
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /auth/signup |
Register a new user | β |
| POST | /auth/login |
Login and receive JWT token | β |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /api/transactions |
Create a transaction | β |
| GET | /api/transactions |
Get all transactions | β |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /api/rewards |
Get reward points | β |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /api/notifications |
Get notifications | β |
Authorization: Bearer <your-jwt-token>
- Token issued on login containing
sub(email) androle - Validated at Gateway level β no session, no DB lookup in filter
- All downstream services trust forwarded requests
Transaction Created β txn-initiated topic β Notification Service
β Reward Service
- Producer:
transaction-service - Consumers:
notification-service(group:notification-group),reward-service(group:reward-group)
@Lock(LockModeType.PESSIMISTIC_WRITE)on all balance mutations- Prevents race conditions and double spending
- Atomic debit/credit operations
- Kafka guarantees at-least-once delivery
- Application-level check:
existsByTransactionId() - DB-level:
@Column(unique = true)ontransaction_id - Implements the Idempotent Consumer Pattern
Hold Funds β (success) β Capture Hold β Finalized Debit
β (failure) β Release Hold β Funds Returned
- Unique
holdReferenceper hold - Auto-expiry via
@Scheduledcleanup job
FinTech-Payment-Backend/
βββ api-gateway/
β βββ src/
β βββ pom.xml
β βββ Dockerfile
βββ user-service/
β βββ src/
β βββ pom.xml
β βββ Dockerfile
βββ transaction-service/
β βββ src/
β βββ pom.xml
β βββ Dockerfile
βββ notification-service/
β βββ src/
β βββ pom.xml
β βββ Dockerfile
βββ reward-service/
β βββ src/
β βββ pom.xml
β βββ Dockerfile
βββ wallet-service/
β βββ src/
β βββ pom.xml
β βββ Dockerfile
βββ docker-compose.yml
βββ README.md
- β Atomic wallet balance updates
- β Pessimistic locking β no double spending
- β Hold β Capture β Release workflow
- β Idempotent Kafka consumers β safe retries
- β Scheduled recovery for expired holds
- β Custom exceptions with proper HTTP status codes
- Designing distributed microservice communication with Kafka
- Implementing stateless JWT auth across a gateway + multiple services
- Applying pessimistic locking for financial concurrency control
- Idempotency patterns for at-least-once Kafka delivery
- Containerizing a multi-service Spring Boot system with Docker Compose
Brijesh β GitHub Β· LinkedIn
β If you found this project useful, consider giving it a star!