A Rust-based transaction processing service built with Axum and PostgreSQL.
# Start PostgreSQL
docker-compose up -d
# Set database URL
export DATABASE_URL="postgresql://postgres:password@localhost:5432/transaction_service"
# Run the service
cargo run
The service starts on http://localhost:8080
curl http://localhost:8080/health
# Create account 1
curl -X POST http://localhost:8080/accounts \
-H "Content-Type: application/json" \
-d '{"business_id": "business-001", "currency": "USD"}'
# Create account 2
curl -X POST http://localhost:8080/accounts \
-H "Content-Type: application/json" \
-d '{"business_id": "business-002", "currency": "USD"}'
curl -X POST http://localhost:8080/transactions \
-H "Content-Type: application/json" \
-d '{"transaction_type": "credit", "amount": "15000", "destination_account_id": "b19a4d42-9f0f-4f82-856c-2e7af018e88a", "description": "Initial deposit", "reference": "DEP-001"}'
curl -X POST http://localhost:8080/transactions \
-H "Content-Type: application/json" \
-d '{"transaction_type": "debit", "amount": "5000", "source_account_id": "b19a4d42-9f0f-4f82-856c-2e7af018e88a", "description": "Withdrawal", "reference": "WD-001"}'
curl -X POST http://localhost:8080/transactions \
-H "Content-Type: application/json" \
-d '{"transaction_type": "transfer", "amount": "3000", "source_account_id": "b19a4d42-9f0f-4f82-856c-2e7af018e88a", "destination_account_id": "26bd0b87-d488-4fa2-977c-e41a590820fc", "description": "Transfer", "reference": "TXF-001"}'
# Account 1 (should be $70.00 = 7000 cents)
curl http://localhost:8080/accounts/b19a4d42-9f0f-4f82-856c-2e7af018e88a
# Account 2 (should be $30.00 = 3000 cents)
curl http://localhost:8080/accounts/26bd0b87-d488-4fa2-977c-e41a590820fc
# Test insufficient balance
curl -X POST http://localhost:8080/transactions \
-H "Content-Type: application/json" \
-d '{"transaction_type": "debit", "amount": "20000", "source_account_id": "b19a4d42-9f0f-4f82-856c-2e7af018e88a", "description": "Large withdrawal", "reference": "WD-002"}'
# Test invalid account
curl http://localhost:8080/accounts/invalid-uuid
Save this as test.sh
, make it executable (chmod +x test.sh
), and run it with ./test.sh
.
Method | Endpoint | Description |
---|---|---|
GET | /health |
Health check |
POST | /accounts |
Create account |
GET | /accounts/{id} |
Get account details |
POST | /transactions |
Process transaction |
- Amounts: Stored as integers in cents (e.g., 1000 = $10.00)
- Account IDs: UUID format
- Transaction Types:
credit
,debit
,transfer
- Currency: 3-letter ISO codes (USD, EUR, etc.)
- Web Framework: Axum (async Rust)
- Database: PostgreSQL with SQLx
- Migrations: Automatic on startup
- Transactions: ACID compliant with database transactions