Skip to content

This project implements a robust, multi-threaded transaction processing system for managing user accounts, complete with real-time analytics, error metrics, and Flask API integration. It leverages Mojo for high-performance concurrency and a SQLite backend for storage, making it ideal for both testing and deployment in controlled environments.

License

Notifications You must be signed in to change notification settings

Awrsha/Bank-Transaction-Processing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🏦 High-Performance Transaction Processor with Flask Integration

Welcome to the High-Performance Transaction Processor! This project implements a robust, multi-threaded transaction processing system for managing user accounts, complete with real-time analytics, error metrics, and Flask API integration. It leverages Mojo for high-performance concurrency and a SQLite backend for storage, making it ideal for both testing and deployment in controlled environments.


🌟 Features

  • Atomic Transaction Processing: Safely handle deposits and withdrawals with lock-free atomic counters and SQLite transactions.
  • Real-time Metrics: Track deposits, withdrawals, errors, and average processing times.
  • Concurrency Management: Multi-threaded queue-based transaction handling with a dedicated worker pool.
  • Circular Buffer Analytics: Maintains history of transaction times and average balances for efficient trend analysis.
  • REST API Integration: Supports HTTP transaction requests with a Flask API layer for easy access.
  • Scalable Queue Management: Thread-safe transaction queue with overflow handling and metrics.

📂 Directory Structure

.
├── app.py                   # Flask app routes and initialization
├── database.py              # SQLite database setup and utility functions
├── transaction_processor.mojo # Core transaction processing logic in Mojo
├── Dockerfile               # Dockerfile for containerization
├── docker-compose.yaml      # Configuration for multi-container setup
├── locustfile.py            # Load testing configuration with Locust
├── requirements.txt         # Python dependencies
└── users.db                 # SQLite database file

🚀 Quick Start

Follow these steps to deploy and test the transaction processor:

1. Clone the Repository

git clone https://github.com/Awrsha/Bank-Transaction-Processing.git
cd Bank-Transaction-Processing
cd CPU

2. Set Up the Database

To initialize the users.db database, use the provided database.py script.

python database.py

3. Build and Run the Docker Container

This project includes a Dockerfile and docker-compose.yaml for easy deployment.

docker-compose up --build

4. Access the API

The Flask API runs on http://localhost:5000. You can send transaction requests to the /transaction endpoint.

Example Request:

curl -X POST http://localhost:5000/transaction -H "Content-Type: application/json" -d '{"card_number": "1234567890", "amount": 100}'

📈 Metrics Dashboard

Track real-time performance metrics in the terminal or integrate them with a monitoring tool:

  • Deposits: Count of successful deposit transactions.
  • Withdrawals: Count of successful withdrawal transactions.
  • Insufficient Funds: Count of attempted withdrawals with insufficient balance.
  • Errors: Count of errors encountered during transaction processing.
  • Queue Full: Count of transactions that could not be queued due to a full queue.

💻 Technology Stack

  • Mojo: High-performance concurrency for transaction processing.
  • SQLite: Lightweight database with ACID compliance.
  • Flask: REST API framework for handling HTTP requests.
  • Docker: Containerization for easy deployment.
  • Locust: Load testing for stress-testing API endpoints.

🧪 Load Testing with Locust

We use Locust for load testing. Start Locust to simulate traffic on the transaction API and measure performance.

locust -f locustfile.py

Open Locust's web UI at http://localhost:8089, configure the number of users and spawn rate, and initiate the test.


📊 Circular Buffer Analytics

  • Transaction Times: The processor tracks the duration of the last 1000 transactions, providing insight into processing time under varying loads.
  • Average Balance: Every second, the average balance of all users is calculated and recorded, allowing you to analyze balance trends over time.

🔧 Configuration

Adjustable Parameters:

  • db_path: Path to the SQLite database file.
  • worker_count: Number of worker threads for transaction processing.
  • max_queue_size: Maximum transaction queue size for handling peak loads.

Modify these parameters in transaction_processor.mojo or via environment variables for scalability and performance tuning.


🌐 API Endpoints

Endpoint Method Description
/transaction POST Queue a transaction for processing
/metrics GET Retrieve current metrics (coming soon)
/balance GET Fetch user balance (coming soon)

Example Transaction Request

POST /transaction
{
  "card_number": "1234567890",
  "amount": 150
}

📜 License

Distributed under the Apache-2.0 License.


🤝 Contributing

Contributions are welcome! Fork this repo, create a branch, and submit a pull request to contribute to this high-performance transaction processor.

About

This project implements a robust, multi-threaded transaction processing system for managing user accounts, complete with real-time analytics, error metrics, and Flask API integration. It leverages Mojo for high-performance concurrency and a SQLite backend for storage, making it ideal for both testing and deployment in controlled environments.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published