The Transaction Processing System (TPS) is a scalable and resilient system that handles high transaction volumes, performance, reliability, and operational visibility. The system is designed with a microservices architecture that can scale horizontally and automatically recover from failures.
-
API Service - FastAPI - Exposes RESTful APIs for transaction management.
-
Database - The system interacts with a relational database (PostgreSQL) to store transaction data.
-
Caching - Uses Redis to cache transaction data and reduce database load.
-
Prometheus Monitoring - Provides detailed metrics and monitoring of the application.
-
Auto-Scaling - Kubernetes Horizontal Pod Autoscaler (HPA) automatically adjusts the number of pods based on CPU utilization.
-
High Availability and Resilience - The system is designed for fault tolerance with features like rolling updates and pod disruption budgets.
-
Docker and Docker Compose: Ensure you have Docker and Docker Compose installed on your machine.
Alternatively you can Install Docker Desktop which include both.
-
Python 3.9+: Ensure you have Python 3.9 or newer installed if you plan to run parts of the project outside of Docker.
tps/
│── app/
│ │── __init__.py
│ │── main.py
│ │── models.py
│ │── database.py
│ │── transactions.py
│ │── schemas.py
│ │── cache.py
│ │── auth.py
│ │── worker.py
│── infra/
│ │── docker-compose.yml
│ │── k8s/
│ │ │── deployment.yaml
│ │ │── prometheus.yaml
│── requirements.txt
│── Dockerfile
│── README.md
git clone https://github.com/Yuda4/Transaction-Processing-System.git
cd Transaction-Processing-System
-
Build and Start the Services:
- Open a terminal on project-root location
- Run the build command:
docker-compose up --build
- Want to delete the container with all data? Run this command:
docker-compose down -v
- Want to stop the running of container?
docker-compose stop
or pressCtrl-C
-
API's endpoints:
After docker is running and all services are up run this CURL in the terminal or using Postman:
POST: /transactions
curl --location 'http://localhost:8000/transactions' \ --header 'Content-Type: application/json' \ --data '{ "user_id": "user_11", "amount": 12.75, "currency": "USD" }'
GET: /transactions/{txn_id}
curl --location 'http://localhost:8000/transactions/1'
GET: /metrics
curl --location 'http://localhost:8000/metrics'
-
Connecting to DB:
Open the terminal and use this command:
docker exec -it infra-db-1 psql -U user -d tps
which will connect to DB named tps that is hosted ininfra-db-1
docker container.\l
- List all databases.\dt
- List database tables.\d <table-name>
- Describe a table.SELECT * FROM transactions;
- shows transactions table's records.
Exmaple of records in table: