Skip to content

Victoria824/Fraud_Alert_system

Repository files navigation

Banking Fraud Detection & Customer Notification System

🏦 Project Overview

A cloud-native banking application that detects potentially fraudulent transactions in real-time and notifies customers through an event-driven architecture built on AWS.

🎯 Interview Presentation Guide

System Architecture Highlights

  • Event-Driven Architecture: Decoupled services using SQS for reliability
  • Microservices Pattern: Separate concerns between transaction processing and notifications
  • Cloud-Native Design: Serverless and containerized components for scalability
  • Security-First Approach: Financial-grade security with zero-trust principles

Key Technical Decisions

  1. ECS Fargate over Lambda: Better for long-running API processes and complex fraud detection logic
  2. DynamoDB over RDS: NoSQL for flexible fraud log schema and better performance for time-series data
  3. SQS for Decoupling: Ensures notification reliability even if Lambda fails
  4. ALB for API Gateway: Better control over routing and security policies

πŸ—οΈ Architecture Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Client    │───▢│     ALB     │───▢│   ECS Fargate   β”‚
β”‚             β”‚    β”‚             β”‚    β”‚  Transaction    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚     API         β”‚
                                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                                               β”‚
                                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                    β”‚  Fraud Detection    β”‚
                                    β”‚     Engine          β”‚
                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                               β”‚
                                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                    β”‚   SQS Queue         β”‚
                                    β”‚  (Flagged Txns)     β”‚
                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                               β”‚
                                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                    β”‚   Lambda Function   β”‚
                                    β”‚   (Notifications)   β”‚
                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                               β”‚
                                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                    β”‚   DynamoDB + SNS    β”‚
                                    β”‚  (Storage + Alerts) β”‚
                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🌐 Live Demo Endpoints

Production API

ALB URL: http://FraudD-Fraud-VnUQ1cAEgQiB-904840766.us-east-1.elb.amazonaws.com
API Base: http://FraudD-Fraud-VnUQ1cAEgQiB-904840766.us-east-1.elb.amazonaws.com/api/v1

# βœ… LIVE DEPLOYMENT - Real ALB DNS from AWS

AWS Resources

SQS Queue: flagged-transactions-dev
DynamoDB Table: fraud-logs-dev  
SNS Topic: fraud-notifications-dev
Kinesis Stream: fraud-data-stream-dev
S3 Bucket: fraud-data-lake-dev-123456789
CloudWatch Dashboard: fraud-detection-dashboard-dev

πŸ§ͺ Live Testing Commands

# 1. Login and get JWT token
TOKEN=$(curl -s -X POST http://FraudD-Fraud-VnUQ1cAEgQiB-904840766.us-east-1.elb.amazonaws.com/api/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email": "[email protected]", "password": "password123"}' \
  | jq -r '.data.tokens.accessToken')

# 2. Send normal transaction (should be approved)
curl -X POST http://FraudD-Fraud-VnUQ1cAEgQiB-904840766.us-east-1.elb.amazonaws.com/api/v1/transactions \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "transaction_id": "test-normal-001",
    "amount": "100.00",
    "transaction_type": "deposit",
    "location": {"lat": 40.7128, "lng": -74.0060, "city": "New York"},
    "timestamp": "2024-01-15T10:30:00Z"
  }'

# 3. Send suspicious transaction (should be flagged)
curl -X POST http://FraudD-Fraud-VnUQ1cAEgQiB-904840766.us-east-1.elb.amazonaws.com/api/v1/transactions \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "transaction_id": "test-suspicious-002", 
    "amount": "15000.00",
    "transaction_type": "withdrawal",
    "location": {"lat": 51.5074, "lng": -0.1278, "city": "London"},
    "timestamp": "2024-01-15T10:35:00Z"
  }'

πŸ” JWT Authentication Testing

# JWT Configuration
JWKS_URL="https://cognito-idp.us-east-1.amazonaws.com/us-east-1_123456789/.well-known/jwks.json"
JWT_AUDIENCE="fraud-detection-api"
JWT_ISSUER="https://cognito-idp.us-east-1.amazonaws.com/us-east-1_123456789"

# Test 1: No token β†’ 401
curl -X POST http://FraudD-Fraud-VnUQ1cAEgQiB-904840766.us-east-1.elb.amazonaws.com/api/v1/transactions \
  -H "Content-Type: application/json" \
  -d '{"amount": "100"}' 
# Expected: 401 Unauthorized

# Test 2: Invalid token β†’ 401  
curl -X POST http://FraudD-Fraud-VnUQ1cAEgQiB-904840766.us-east-1.elb.amazonaws.com/api/v1/transactions \
  -H "Authorization: Bearer invalid-token" \
  -H "Content-Type: application/json" \
  -d '{"amount": "100"}'
# Expected: 401 Unauthorized

# Test 3: Wrong tenant β†’ 403
curl -X POST http://FraudD-Fraud-VnUQ1cAEgQiB-904840766.us-east-1.elb.amazonaws.com/api/v1/transactions \
  -H "Authorization: Bearer valid-token-for-tenant-a" \
  -H "X-Tenant-ID: tenant-b" \
  -H "Content-Type: application/json" \
  -d '{"amount": "100"}'
# Expected: 403 Forbidden

πŸš€ Quick Start

Prerequisites

  • AWS CLI configured
  • Node.js 18+
  • AWS CDK installed
  • Docker (for local testing)

Deployment Steps

# 1. Install dependencies
npm install

# 2. Bootstrap CDK (first time only)
cdk bootstrap

# 3. Deploy infrastructure
cdk deploy --all

# 4. Run integration tests
npm run test:integration

πŸ“Š Demo Scenarios

Scenario 1: Normal Transaction Flow

# Valid transaction
curl -X POST https://api.fraud-detection.com/transactions \
  -H "Authorization: Bearer <jwt-token>" \
  -H "Content-Type: application/json" \
  -d '{
    "account_id": "acc_123",
    "amount": 100.00,
    "transaction_type": "withdrawal",
    "location": {"lat": 37.7749, "lng": -122.4194},
    "timestamp": "2024-01-15T10:30:00Z"
  }'

Scenario 2: Fraudulent Transaction Detection

# Large withdrawal from unusual location
curl -X POST https://api.fraud-detection.com/transactions \
  -H "Authorization: Bearer <jwt-token>" \
  -H "Content-Type: application/json" \
  -d '{
    "account_id": "acc_123",
    "amount": 50000.00,
    "transaction_type": "withdrawal",
    "location": {"lat": 40.7128, "lng": -74.0060},
    "timestamp": "2024-01-15T10:30:00Z"
  }'

πŸ” Fraud Detection Rules

Implemented Rules

  1. Large Withdrawal Detection: Configurable thresholds per account type
  2. Geographic Anomaly: Rapid location changes within time windows
  3. Velocity Checks: Multiple transactions in short timeframes
  4. Failed Login Patterns: Suspicious authentication attempts
  5. Time-based Anomalies: Unusual transaction timing patterns

Rule Configuration

interface FraudRules {
  maxWithdrawalAmount: number;
  locationChangeThreshold: number; // miles
  timeWindowMinutes: number;
  maxTransactionsPerWindow: number;
  suspiciousHours: number[]; // 24-hour format
}

πŸ“ˆ Monitoring & Observability

Key Metrics

  • Transaction processing latency
  • Fraud detection accuracy
  • Notification delivery success rate
  • System error rates
  • Cost per transaction processed

CloudWatch Dashboards

  • Real-time transaction volume
  • Fraud detection patterns
  • System health indicators
  • Cost optimization metrics

πŸ”’ Security Features

Authentication & Authorization

  • JWT-based authentication with RS256
  • Role-based access control (RBAC)
  • API rate limiting and throttling
  • Request/response encryption

Data Protection

  • Encryption at rest (DynamoDB, S3)
  • Encryption in transit (TLS 1.3)
  • PII data masking in logs
  • Audit trail for all transactions

πŸ§ͺ Testing Strategy

Test Coverage

  • Unit tests: >90% coverage
  • Integration tests: API endpoints
  • End-to-end tests: Complete fraud detection flow
  • Load tests: Performance under scale
  • Security tests: Penetration testing

Test Commands

npm run test              # Unit tests
npm run test:integration  # Integration tests
npm run test:e2e         # End-to-end tests
npm run test:load        # Load testing

πŸ“š Interview Questions & Answers

Q: Why did you choose ECS Fargate over Lambda for the transaction API?

A: ECS Fargate provides better control over long-running processes, more predictable performance for complex fraud detection algorithms, and easier debugging. Lambda has cold start issues and timeout limitations that could impact real-time fraud detection.

Q: How do you handle false positives in fraud detection?

A: We implement a multi-layered approach: 1) Configurable thresholds per customer segment, 2) Machine learning models for pattern recognition, 3) Human review workflows for high-value transactions, 4) Customer feedback loops to improve accuracy.

Q: What happens if the Lambda function fails to process a flagged transaction?

A: We use SQS with Dead Letter Queues (DLQ) for retry logic, CloudWatch alarms for monitoring failures, and manual intervention workflows. Critical transactions can also trigger immediate alerts to fraud analysts.

Q: How would you scale this system to handle 10x more transactions?

A: Horizontal scaling through ECS auto-scaling, DynamoDB on-demand capacity, SQS batch processing optimization, and implementing caching layers. We'd also consider regional deployment for global customers.

🎯 Bonus Features Implemented

  • βœ… JWT Authentication with refresh tokens
  • βœ… Multi-tenant architecture support
  • βœ… Kinesis Firehose for ML pipeline
  • βœ… CloudWatch Alarms for anomaly detection
  • βœ… Cost optimization with auto-scaling
  • βœ… Comprehensive monitoring dashboards

πŸ“ Project Structure

fraud-detection-system/
β”œβ”€β”€ infrastructure/          # CDK infrastructure code
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ vpc-stack.ts
β”‚   β”‚   β”œβ”€β”€ ecs-stack.ts
β”‚   β”‚   β”œβ”€β”€ lambda-stack.ts
β”‚   β”‚   └── monitoring-stack.ts
β”‚   └── bin/app.ts
β”œβ”€β”€ backend/                 # ECS API service
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   └── utils/
β”‚   β”œβ”€β”€ tests/
β”‚   └── Dockerfile
β”œβ”€β”€ lambda/                  # Notification Lambda
β”‚   β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ tests/
β”‚   └── package.json
β”œβ”€β”€ shared/                  # Shared utilities
β”‚   β”œβ”€β”€ types/
β”‚   β”œβ”€β”€ utils/
β”‚   └── constants/
β”œβ”€β”€ docs/                    # Documentation
β”‚   β”œβ”€β”€ architecture.md
β”‚   β”œβ”€β”€ api-spec.md
β”‚   └── deployment.md
└── scripts/                 # Deployment scripts
    β”œβ”€β”€ deploy.sh
    └── test.sh

πŸš€ Next Steps for Interview

  1. Live Demo: Show real-time fraud detection
  2. Code Walkthrough: Explain key algorithms and patterns
  3. Architecture Discussion: Trade-offs and design decisions
  4. Scaling Scenarios: How to handle growth
  5. Security Deep Dive: Financial compliance and protection

Built with ❀️ for Senior Software Engineer interviews

About

Banking Fraud Detection and Customer Notification System

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published