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.
- 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.
.
├── 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
Follow these steps to deploy and test the transaction processor:
git clone https://github.com/Awrsha/Bank-Transaction-Processing.git
cd Bank-Transaction-Processing
cd CPU
To initialize the users.db
database, use the provided database.py
script.
python database.py
This project includes a Dockerfile
and docker-compose.yaml
for easy deployment.
docker-compose up --build
The Flask API runs on http://localhost:5000
. You can send transaction requests to the /transaction
endpoint.
curl -X POST http://localhost:5000/transaction -H "Content-Type: application/json" -d '{"card_number": "1234567890", "amount": 100}'
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.
- 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.
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.
- 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.
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.
Endpoint | Method | Description |
---|---|---|
/transaction |
POST | Queue a transaction for processing |
/metrics |
GET | Retrieve current metrics (coming soon) |
/balance |
GET | Fetch user balance (coming soon) |
POST /transaction
{
"card_number": "1234567890",
"amount": 150
}
Distributed under the Apache-2.0 License.
Contributions are welcome! Fork this repo, create a branch, and submit a pull request to contribute to this high-performance transaction processor.