Skip to content

About

SAGA-based distributed banking system with real-time fraud detection — Spring Boot, Kafka, Redis.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Distributed Transaction & Fraud Detection System

A microservices-based digital banking platform implementing the SAGA pattern for distributed transaction consistency, with real-time fraud detection and event-driven notifications.

Services Overview

Service Port Responsibility
api-gateway 8080 Single entry point, rate limiting
account-service 8081 Account management, balance, deduct/credit/refund
transaction-service 8082 SAGA orchestrator — money transfers, transaction history
payment-service 8083 Razorpay integration, external payments
fraud-detection-service 8084 Real-time fraud detection via Redis
notification-service 8085 Transaction and fraud alerts (email/SMS)

Architecture Flow

User → API Gateway (rate limiting)
             ↓
      Transaction Service (SAGA orchestrator)
             ↓
        Account Service
     (validate balance, deduct)
             ↓
        Apache Kafka
             ↓
    ┌────────────────────────┐
    │                        │
Fraud Detection      Transaction Service
(Redis patterns)     (decides next step)
    │                        │
    ▼                        ▼
Account Service        Notification Service
(block if fraud /      (debit/credit/fraud alerts)
 credit receiver)

Why SAGA?

Each service owns its own database (account DB, transaction DB, payment DB). A traditional single-database system rolls back automatically on failure — in a distributed setup, no single database can undo a step that already committed in another service. The transaction-service acts as the SAGA orchestrator: it tracks each step (deduct → fraud-check → credit) and triggers explicit compensating actions (e.g. refund, unblock) if a later step fails, rather than relying on an implicit rollback.

Kafka Topics

Topic Publisher Consumer
transaction.initiated Transaction Service Fraud Detection Service
fraud.check.result Fraud Detection Service Transaction Service
transaction.completed Transaction Service Account Service, Notification Service
fraud.detected Fraud Detection Service Account Service, Notification Service
payment.completed Payment Service Notification Service

Tech Stack

  • Backend: Java, Spring Boot, Spring Cloud Gateway, OpenFeign
  • Messaging: Apache Kafka
  • Caching: Redis (fraud pattern detection, rate limiting)
  • Database: MySQL (per-service, separate schemas)
  • Payments: Razorpay integration
  • Infra: Docker (Kafka, Zookeeper, Redis, MySQL via docker-compose)

How To Run

Step 1: Start Infrastructure

docker-compose up -d

This brings up Kafka, Zookeeper, Redis, and MySQL (skip MySQL in docker-compose if you're running it locally already).

Step 2: Start All Services

# Terminal 1
cd account-service && mvn spring-boot:run

# Terminal 2
cd transaction-service && mvn spring-boot:run

# Terminal 3
cd payment-service && mvn spring-boot:run

# Terminal 4
cd fraud-detection-service && mvn spring-boot:run

# Terminal 5
cd notification-service && mvn spring-boot:run

# Terminal 6
cd api-gateway && mvn spring-boot:run

Step 3: Configure Credentials

Before testing, set the following in each service's application.yml:

  • MySQL username/password
  • Razorpay API key/secret (payment-service)
  • Email/SMS credentials (notification-service)

Note: Do not commit real credentials. Use environment variables or a .gitignore'd local properties file.

Example Flow

  1. User initiates a transfer → POST /api/v1/transactions/transfer
  2. API Gateway rate-limits and forwards to Transaction Service
  3. Transaction Service calls Account Service to validate and deduct balance
  4. Transaction saved with status PROCESSING; transaction.initiated published to Kafka
  5. Fraud Detection Service consumes the event, checks Redis-based patterns
  6. If clean → Transaction Service credits receiver, publishes transaction.completed
  7. If suspicious → account is flagged/blocked, fraud.detected published, user notified
  8. Notification Service sends alerts at each key step (debit, credit, fraud, block)

About

SAGA-based distributed banking system with real-time fraud detection — Spring Boot, Kafka, Redis.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages