Skip to content
IbsYoussefPublic

About

Miniature event driven transaction system inspired by modern banking architectures. Demonstrates how live data is validated, persisted through PostgreSQL by Go microservices and exposed via a small REST API.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

57 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏦 FlowBank

A miniature event-driven transaction processor inspired by Monzo, built with Go, Kafka (RedPanda), Python, and PostgreSQL. Deployed to AWS.

Go Python PostgreSQL Kafka Docker AWS Elastic Beanstalk Amazon RDS Amazon ECR JavaScript HTML5 CSS3 License: MIT


πŸ“‘ Table of Contents


🎯 Project Overview

FlowBank demonstrates a distributed system for processing banking transactions using event-driven architecture. Inspired by Monzo's architecture, it showcases modern microservices patterns, real-time data processing, interactive analytics, and fraud detection - all deployed to AWS.

✨ Key Features

  • ⚑ Event-Driven Architecture - Asynchronous transaction processing via Kafka
  • πŸ“Š Real-Time Analytics Dashboard - Live data visualization
  • πŸ—οΈ Microservices Design - Independent Go services (Producer, Consumer, API) and a Python fraud detection service
  • πŸ” Real-Time Fraud Detection - Python FastAPI microservice scoring transactions against three detection rules
  • πŸ”’ ACID Transactions - PostgreSQL with row-level locking and atomic updates
  • 🐳 Fully Dockerized - One-command local deployment with Docker Compose
  • 🐍 Polyglot Architecture - Go and Python microservices working together on the same Kafka topics
  • ☁️ Cloud Deployed - Live on AWS Elastic Beanstalk with RDS PostgreSQL and Aiven Kafka
  • πŸ“ˆ Production Patterns - Proper error handling, logging, separation of concerns

πŸ—οΈ Architecture

Local Development Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Producer   │────────>β”‚   RedPanda   │────────>β”‚   Consumer   β”‚
β”‚    (Go)      β”‚ Publish β”‚   (Kafka)    β”‚ Consume β”‚    (Go)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚                        β”‚
                                β”‚ Consume                β–Ό
                                β”‚                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                └─────────────────>β”‚    Fraud     β”‚
                                                   β”‚   Detection  β”‚
                                                   β”‚   (Python)   β”‚
                                                   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                                                          β”‚
                                                          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Dashboard   β”‚<────────── Query ────────────────│  PostgreSQL  β”‚
β”‚ (Go API)     β”‚                                  β”‚  (Storage)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Production Architecture (AWS)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Producer   │────────>β”‚    Aiven     │────────>β”‚   Consumer   β”‚
β”‚  (Go / ECR)  β”‚ Publish β”‚    Kafka     β”‚ Consume β”‚  (Go / ECR)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚                        β”‚
                                β”‚ Consume                β–Ό
                                β”‚                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                └─────────────────>β”‚    Fraud     β”‚
                                                   β”‚  Detection   β”‚
                                                   β”‚ (Python/ECR) β”‚
                                                   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                                                          β”‚
                                                          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Dashboard   β”‚<────────── Query ────────────────│   AWS RDS    β”‚
β”‚ (Go API/ECR) β”‚                                  β”‚  PostgreSQL  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

         All services hosted on AWS Elastic Beanstalk (t3.small EC2)
         Container images stored in AWS ECR

Data Flow:

  1. Producer generates realistic banking transactions every 3 seconds
  2. Kafka buffers and distributes events across partitions
  3. Go Consumer validates, processes, and persists to database with overdraft protection
  4. Python Fraud Detection consumes the same Kafka topic, scores each transaction against three fraud rules, and writes results to the fraud_scores table
  5. API serves transaction and fraud score data via REST endpoints
  6. Dashboard visualizes metrics and flagged transactions in real-time with auto-refresh

πŸ“ Project Structure

flowbank/
β”œβ”€β”€ cmd/
β”‚   β”œβ”€β”€ producer/           # Generates fake banking transactions
β”‚   β”œβ”€β”€ consumer/           # Processes transactions from Kafka
β”‚   └── api/                # REST API for querying data
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ kafka/              # Kafka producer/consumer helpers + TLS config
β”‚   β”œβ”€β”€ db/                 # Database connection and queries
β”‚   β”œβ”€β”€ model/              # Data models (Transaction, User, FraudScore)
β”‚   └── service/            # Business logic layer
β”œβ”€β”€ fraud-detection/        # Python fraud detection microservice
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ main.py         # FastAPI entry point
β”‚   β”‚   β”œβ”€β”€ consumer.py     # Kafka consumer logic
β”‚   β”‚   β”œβ”€β”€ detector.py     # Fraud scoring rules
β”‚   β”‚   β”œβ”€β”€ database.py     # PostgreSQL connection and writes
β”‚   β”‚   └── models.py       # Pydantic schemas
β”‚   └── requirements.txt
β”œβ”€β”€ deploy/
β”‚   β”œβ”€β”€ docker-compose.yml  # Local development
β”‚   β”œβ”€β”€ Dockerfile.*        # Service Dockerfiles
β”‚   └── init.sql            # Database schema
β”œβ”€β”€ docker-compose.yml      # Production (AWS) - uses ECR images
β”œβ”€β”€ web/
β”‚   └── dashboard.html      # Analytics dashboard UI
β”œβ”€β”€ docs/                   # Additional documentation
β”œβ”€β”€ go.mod
β”œβ”€β”€ Makefile
└── README.md

🌐 Live Demo

View Live Dashboard β†’

Endpoint URL
Dashboard /dashboard
API Health /health
Fraud Scores /api/v1/fraud-scores
Analytics /api/v1/analytics

πŸš€ Quick Start

See docs/QUICKSTART.md for the full guide. Start there.

Prerequisites

Running the System

# Clone the repository
git clone https://github.com/IbsYoussef/FlowBank.git
cd FlowBank

# Start all services
make up

# View logs (optional)
make logs

Local Access Points:

Testing the Data Pipeline

1. Check API Health

curl http://localhost:8080/health

2. View Users

# Coming soon: curl http://localhost:8080/users

3. View User Transactions

# Coming soon: curl http://localhost:8080/users/{user_id}/transactions

4. Monitor Kafka Topics

5. Verify Services

make ps
# All services should show as "Up" and "healthy"

6. Check Database

make db-shell

# View users
SELECT * FROM users;

# View recent transactions
SELECT * FROM transactions ORDER BY created_at DESC LIMIT 10;

# Check transaction stats
SELECT status, COUNT(*) FROM transactions GROUP BY status;

# View fraud scores
SELECT * FROM fraud_scores ORDER BY scored_at DESC LIMIT 10;

7. Monitor Live Transactions

Option A: Dashboard (Recommended)

open http://localhost:8080/dashboard

Option B: Producer Logs

make logs-producer

Option C: Consumer Logs

make logs-consumer

πŸ“Š Analytics Dashboard

Dashboard Preview

Local: http://localhost:8080/dashboard Live: flowbank-prod.eba-fcdmxpas.eu-west-2.elasticbeanstalk.com/dashboard

Features

  • πŸ“ˆ 4 Interactive Charts - Transaction type distribution, money flow, top merchants, hourly volume
  • πŸ”΄ Live Transaction Feed - Real-time updates every 5 seconds
  • 🚨 Flagged Transactions Panel - Suspicious and high-risk transactions with risk badges
  • πŸ’° Key Metrics - Total transactions, money in/out, average amount
  • πŸ“± Responsive Design - Works on desktop, tablet, mobile

API Endpoints

Endpoint Method Description
/health GET Service health check
/api/v1/accounts/{id} GET User account details with balance
/api/v1/analytics GET Aggregated dashboard analytics
/api/v1/fraud-scores GET Recent fraud scores with transaction details
/dashboard GET Analytics dashboard UI

Example:

# Get user account details
curl http://localhost:8080/api/v1/accounts/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11 | jq

# Get analytics data
curl http://localhost:8080/api/v1/analytics | jq

# View dashboard in browser
open http://localhost:8080/dashboard

πŸ› οΈ Development Commands

Command Description
make help Show all available commands
make deps Install Go dependencies
make build Build Docker images
make up Start all services
make down Stop all services
make restart Restart services
make logs Tail logs from all services
make clean Remove containers and volumes
make db-shell Open PostgreSQL shell
make kafka-topics List Kafka topics
make test Run Go tests

πŸ“Š Data Models

Transaction

type Transaction struct {
ID           uuid.UUID
UserID       uuid.UUID
Amount       int64     // in cents
Type         string    // "debit" or "credit"
Description  string
MerchantName string
Status       string    // "pending", "completed", "failed"
CreatedAt    time.Time
}

User

type User struct {
ID        uuid.UUID
Email     string
Name      string
Balance   int64     // in cents
CreatedAt time.Time
UpdatedAt time.Time
}

FraudScore

type FraudScore struct {
    TransactionID    string
    RiskScore        string    // "low", "medium", "high"
    Status           string    // "clean", "suspicious", "flagged"
    TriggeredRules   []string  // e.g. ["high_frequency", "high_value"]
    Confidence       float64
    ProcessingTimeMs float64
    ScoredAt         time.Time
}

πŸ”§ Technology Stack

Component Technology Version
Language (Backend) Go 1.26
Language (Fraud Detection) Python 3.14
Fraud Detection Framework FastAPI 0.136
Messaging (Local) Kafka / RedPanda 7.6.1
Messaging (Production) Aiven Kafka 4.1
Database (Local) PostgreSQL 16
Database (Production) AWS RDS PostgreSQL 16
Frontend Chart.js 4.4.0
Containerisation Docker & Compose Latest
Container Registry AWS ECR -
Hosting AWS Elastic Beanstalk -

πŸ“ Roadmap

  • Project structure and Docker setup
  • Implement Kafka producer/consumer
  • Build transaction generator (Producer)
  • Build transaction processor (Consumer)
  • Implement REST API endpoints
  • Real-time analytics dashboard
  • Add validation and business logic
  • Add comprehensive logging
  • Fraud detection microservice (Python/FastAPI)
  • Real-time fraud scoring dashboard panel
  • Cloud deployment (AWS Elastic Beanstalk + RDS + Aiven Kafka)
  • CI/CD pipeline (GitHub Actions β†’ ECR β†’ Elastic Beanstalk)
  • Service status indicators on dashboard
  • Data variety improvements (more merchants, realistic fraud scenarios)
  • Pagination on transaction and fraud feeds
  • Metrics and observability (Prometheus/Grafana)
  • Add unit and integration tests
  • ECS migration for better container orchestration

πŸŽ“ Learning Goals

This project demonstrates understanding of:

  • βœ… Event-Driven Architecture - Asynchronous communication via message queues
  • βœ… Microservices Design - Loosely coupled, independently deployable services
  • βœ… Polyglot Systems - Go and Python microservices sharing the same Kafka topics
  • βœ… Database Transactions - ACID compliance, row-level locking, atomic updates
  • βœ… RESTful API Design - Clean endpoints with proper status codes
  • βœ… Fraud Detection - Rule-based scoring with duplicate, high-value and frequency detection
  • βœ… Data Visualization - Real-time dashboards with Chart.js
  • βœ… Docker & Containerisation - Multi-service orchestration
  • βœ… Cloud Deployment - AWS Elastic Beanstalk, ECR, RDS
  • βœ… Go Best Practices - Project structure, error handling, concurrency
  • βœ… Python Best Practices - FastAPI, Pydantic, async patterns
  • βœ… SQL Optimisation - Aggregated queries, proper indexing

πŸ“š Resources


🀝 Interview Talking Points

Architecture Decisions

  • Why event-driven? Decouples services, enables async processing, scales horizontally
  • Why Kafka over REST? Buffering, replay capability, better for high throughput
  • Why PostgreSQL? ACID compliance crucial for financial data, rich querying
  • Why Go? Performance, simple concurrency model, excellent for backend services

Fraud Detection Extension

  • Why a separate Python service? Demonstrates polyglot microservices - the right tool for the right job. Python's ecosystem for data processing and ML is stronger than Go's
  • Why FastAPI? Async by default, automatic API docs, Pydantic validation matches the type-safe approach used in Go
  • Why additive architecture? Zero changes to existing Go services - new consumer on the same Kafka topic. Shows understanding of open/closed principle
  • Three detection rules: Duplicate transactions, high-value threshold, high-frequency - each independently configurable and extensible

Cloud Deployment

  • Why Elastic Beanstalk over raw EC2? Managed platform handles scaling, health checks, rolling deployments. Focus on application not infrastructure
  • Why ECR? Pre-built images mean the EC2 instance just pulls and runs - no build timeouts or memory pressure on small instances
  • Why Aiven Kafka? Managed Kafka avoids running resource-heavy Zookeeper + Kafka containers alongside application services on a single instance
  • Why RDS? Managed PostgreSQL with automatic backups, SSL, and failover. Financial data needs durability guarantees

Trade-offs & Alternatives

  • Cassandra for write-heavy workloads with eventual consistency
  • Redis for caching frequently accessed data
  • WebSockets for instant dashboard updates (vs 5-second polling)
  • gRPC for inter-service communication in production

Production Improvements

  • Idempotency keys for exactly-once processing
  • Dead-letter queues for failed messages
  • Circuit breakers for resilience
  • Rate limiting and authentication
  • Distributed tracing (Jaeger)
  • Metrics and alerting (Prometheus/Grafana)
  • ML-based fraud scoring to replace rule-based approach
  • CI/CD pipeline (GitHub Actions β†’ ECR β†’ Elastic Beanstalk)
  • Service status indicators on dashboard
  • Data variety improvements (more merchants, realistic fraud scenarios)
  • Pagination on transaction and fraud feeds
  • ECS migration for better container orchestration
  • UI polish and pagination on dashboard scrolling sections (transaction feed, flagged transactions panel)

πŸ“š Documentation

Start here: docs/QUICKSTART.md

Document Description
QUICKSTART.md Get the system running in 5 minutes
ARCHITECTURE.md System design deep dive, local vs production
COMMAND-REFERENCE-LIST.md All make and docker commands
DEPENDENCIES.md Dependency decisions for Go and Python
IMPROVEMENTS.md Planned enhancements and polish items

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License

Copyright (c) 2026 IbsYoussef

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

πŸ‘€ Author

IbsYoussef
πŸ”— GitHub


⭐ Star this repo if you found it helpful!

⬆ Back to Top

About

Miniature event driven transaction system inspired by modern banking architectures. Demonstrates how live data is validated, persisted through PostgreSQL by Go microservices and exposed via a small REST API.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages