RESTful API service for managing digital wallets with support for deposits and withdrawals.
- Async PostgreSQL with connection pooling
- Concurrent transaction safety with row-level locking
- Automatic retry mechanism
- Transaction monitoring and logging
- Database migrations with Liquibase
- Comprehensive test coverage with async testing
- Decimal precision for financial operations
- Input validation and error handling
- FastAPI framework for high performance
- SQLAlchemy with async support and row-level locking
- PgBouncer for connection pooling in transaction mode
- Pydantic for data validation
- Liquibase for database versioning
- PostgreSQL for ACID compliance
- Docker for containerization
- pytest-asyncio for async testing
POST /api/v1/wallets/- Create new walletGET /api/v1/wallets/{wallet_id}- Get wallet infoPOST /api/v1/wallets/{wallet_id}/operation- Process deposit/withdrawal
- Clone repository
- Copy .env.example to .env
- Run
docker-compose up -d - API available at http://localhost:8000
Run tests with coverage report:
# Run all tests with coverage
docker-compose exec app pytest tests/ -v --cov=app --cov-report=term-missing
# Run specific test file
docker-compose exec app pytest tests/test_wallets.py -v
# Run tests with specific marker
docker-compose exec app pytest -m "asyncio" tests/Tests use a separate database with:
- Automatic creation/cleanup
- Transaction isolation
- Concurrent operation testing
- Row-level locking verification
- Connection pool stress testing
Monitor system performance during load tests:
- Database connections:
SELECT count(*) FROM pg_stat_activity; - Connection pools: Check pool usage in application logs
- System resources: Use
htopor similar tools - Response times: Monitor through Locust UI
- Transaction duration: Check application logs
Available at http://localhost:8000/docs
- 400 - Bad Request (e.g., insufficient funds)
- 404 - Wallet not found
- 422 - Validation error (e.g., negative amount)
All other errors return 200 OK with operation status "FAILED" and details in the response body.
Monitor connection pooling:
-- Active pools
SHOW POOLS;
-- Connection stats
SHOW STATS;
-- Server status
SHOW SERVERS;
-- Current connections
SHOW CLIENTS;
-- Transaction status
SHOW TOTALS;The service uses PgBouncer for connection pooling with:
- Transaction pooling mode
- Dynamic user authentication
- Connection limits and timeouts
- Monitoring capabilities
- Automatic connection cleanup
- Use
pytest.mark.asynciofor async tests - Implement proper cleanup in test fixtures
- Use row-level locking for concurrent operations
- Monitor transaction duration
- Handle database connection errors gracefully