Skip to content

BrijeshPatra/FinTech-Payment-Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’³ FinTech Payment Backend

A production-grade, distributed fintech payment backend built with Spring Boot Microservices β€” inspired by real-world systems like PayPal and Stripe.

Java Spring Boot Apache Kafka Docker H2 JWT Status


πŸ“‹ Table of Contents


🌐 Overview

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

πŸ— Architecture

                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         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  β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“¦ Services

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

πŸ›  Tech Stack

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

πŸš€ Getting Started

Prerequisites

  • Docker Desktop installed and running
  • Java 17+ (only needed for local development without Docker)

Run with Docker (Recommended)

# 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 ps

All 8 containers (Zookeeper, Kafka + 6 microservices) will start automatically.

Useful Commands

# 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-service

πŸ“‘ API Reference

All requests go through the API Gateway at http://localhost:8080

Auth (User Service)

Method Endpoint Description Auth Required
POST /auth/signup Register a new user ❌
POST /auth/login Login and receive JWT token ❌

Transactions

Method Endpoint Description Auth Required
POST /api/transactions Create a transaction βœ…
GET /api/transactions Get all transactions βœ…

Rewards

Method Endpoint Description Auth Required
GET /api/rewards Get reward points βœ…

Notifications

Method Endpoint Description Auth Required
GET /api/notifications Get notifications βœ…

Authentication Header

Authorization: Bearer <your-jwt-token>

🧠 Key Design Patterns

πŸ” JWT Authentication (Stateless)

  • Token issued on login containing sub (email) and role
  • Validated at Gateway level β€” no session, no DB lookup in filter
  • All downstream services trust forwarded requests

πŸ“¨ Event-Driven Architecture (Kafka)

Transaction Created β†’ txn-initiated topic β†’ Notification Service
                                          β†’ Reward Service
  • Producer: transaction-service
  • Consumers: notification-service (group: notification-group), reward-service (group: reward-group)

πŸ”’ Pessimistic Locking (Wallet)

  • @Lock(LockModeType.PESSIMISTIC_WRITE) on all balance mutations
  • Prevents race conditions and double spending
  • Atomic debit/credit operations

πŸ” Idempotency (Reward & Notification)

  • Kafka guarantees at-least-once delivery
  • Application-level check: existsByTransactionId()
  • DB-level: @Column(unique = true) on transaction_id
  • Implements the Idempotent Consumer Pattern

πŸ’° Hold–Capture–Release (Wallet)

Hold Funds β†’ (success) β†’ Capture Hold β†’ Finalized Debit
           β†’ (failure) β†’ Release Hold β†’ Funds Returned
  • Unique holdReference per hold
  • Auto-expiry via @Scheduled cleanup job

πŸ“ Project Structure

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

πŸ” Financial Safety Highlights

  • βœ… 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

πŸ“Œ What I Learned

  • 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

πŸ‘¨β€πŸ’» Author

Brijesh β€” GitHub Β· LinkedIn


⭐ If you found this project useful, consider giving it a star!

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages