CoughOverflow is a cloud-native, highly scalable service designed to analyze saliva samples for detecting COVID-19 and H5N1 (avian influenza) pathogens. The platform uses machine learning algorithms to process images of cell samples and provides a RESTful API for labs and healthcare providers to submit analysis requests and retrieve results.
This project demonstrates the implementation of a microservice architecture deployed on AWS using infrastructure as code (Terraform) with auto-scaling capabilities designed to handle variable load patterns from routine testing to epidemic-level demand.
The system is built as a cloud-native application with the following components:
-
FastAPI Backend:
- RESTful API built with Python's FastAPI framework
- Asynchronous request handling with background task processing
- Request validation and error handling
-
Database Layer:
- PostgreSQL database for storing analysis job metadata
- Configured with proper indexing and connection pooling
- Scalable storage with auto-growth capabilities (20GB base, up to 1TB)
-
Analysis Engine Integration:
- Integration with the QDHeC-developed
overflowenginefor image analysis - Concurrent processing using ThreadPoolExecutor to manage computational load
- Error handling and retry mechanisms for failed analyses
- Integration with the QDHeC-developed
-
AWS Infrastructure:
- ECS (Elastic Container Service) for containerized deployment
- Application Load Balancer for traffic distribution
- Auto-scaling based on CPU utilization metrics
- RDS (Relational Database Service) for reliable data persistence
The API follows a clean RESTful design with the following endpoints:
GET /api/v1/health- Service health checkGET /api/v1/labs- List all labs that have submitted analysesGET /api/v1/labs/results/{lab_id}- Get analyses for a specific lab with filteringGET /api/v1/labs/results/{lab_id}/summary- Get summary statistics for a labGET /api/v1/patients/results- Get analyses for a specific patientGET /api/v1/analysis- Get a specific analysis by IDPOST /api/v1/analysis- Submit a new analysis requestPUT /api/v1/analysis- Update the lab associated with an analysis
The API includes comprehensive validation for all parameters and returns appropriate HTTP status codes and error messages.
-
Database Design:
- Efficient schema for storing analysis metadata
- PostgreSQL database with proper indexing
- Transaction management to ensure data integrity
-
Image Storage:
- Images stored on persistent file storage
- Unique UUIDs for each analysis job and associated image
-
Connection Management:
- Connection pooling with SQLAlchemy
- Pool size optimization based on load testing
- Pre-ping mechanism to detect stale connections
-
Auto-scaling Configuration:
- Min capacity: 1 instance
- Max capacity: 12 instances
- Scale-out threshold: 25% CPU utilization
- Implementation using AWS AppAutoScaling
-
Load Balancing:
- Application Load Balancer for distributing traffic
- Health checks for instance viability
- Connection draining for graceful scaling
-
Concurrent Processing:
- Thread pool for concurrent analysis of images
- Configurable worker limits to prevent resource exhaustion
- Priority processing for urgent analysis requests
-
Database Scaling:
- Auto-growth configuration (up to 1TB)
- Properly sized instance class for cost-effective performance
The application is containerized using Docker and deployed using Terraform:
-
Docker Configuration:
- Multi-stage build for optimized image size
- Environment variable configuration
- Health check endpoints
-
Terraform Implementation:
- Infrastructure as Code (IaC) for repeatable deployments
- Modular design for maintainable configuration
- Resource tagging for proper organization
- Automatic output of service endpoint
-
CI/CD Integration:
- Deployment scripts for automated deployment
- Environment-specific configuration
-
Database Optimizations:
- Connection pooling (20 connections with 20 max overflow)
- Query optimization for filtering operations
- Proper indexing strategy
-
Computation Efficiency:
- Background task processing for analysis to free up web workers
- Configurable thread pool size for analysis jobs
- Bounded task queues to prevent memory issues under heavy load
-
Network Optimizations:
- Minimized payload sizes
- Proper HTTP caching headers
- Efficient serialization/deserialization
To run the service locally:
# Clone the repository
git clone https://github.com/yourusername/coughoverflow.git
cd coughoverflow
# Run the local deployment script
./local.shThe service will be available at http://localhost:8080 with API documentation at http://localhost:8080/docs.
To deploy to AWS:
# Ensure AWS credentials are configured
# Create a credentials file in the repository root
# Run the deployment script
./deploy.shThe deployment script will:
- Initialize Terraform
- Apply the Terraform configuration
- Output the API endpoint URL to api.txt
The service includes extensive automated testing:
-
Unit Tests:
- Component-level testing for all service modules
- Mocking of external dependencies
-
Integration Tests:
- End-to-end API testing
- Database integration testing
-
Load Testing:
- Concurrent request handling (test_concurrent.py)
- Simulated epidemic scenarios
- Auto-scaling validation
-
Machine Learning Improvements:
- Integration with more advanced analysis algorithms
- Support for additional pathogens
-
Monitoring & Observability:
- Enhanced logging with structured log formats
- Metrics collection for operational insights
- Alerting based on performance thresholds
-
Security Enhancements:
- Enhanced authentication mechanisms
- Data encryption at rest and in transit
- Advanced access control policies
- Backend: Python, FastAPI, SQLAlchemy, ThreadPoolExecutor
- Database: PostgreSQL 14
- Containerization: Docker
- Cloud Infrastructure: AWS (ECS, RDS, ALB, Auto Scaling)
- Infrastructure as Code: Terraform
- Testing: Pytest, concurrent.futures
This project is licensed under the MIT License - see the LICENSE file for details.
https://csse6400.uqcloud.net/assessment/coughoverflow/#api-Pas-submitRequest
^^^ USE THIS LINK FOR VALIDATION ERRROS STUFF..
docker exec -it coughoverflow-antimatter543-coughoverflow-api-1 /bin/bash
docker exec -it coughoverflow-db psql -U administrator -d coughoverflow
SELECT * FROM analysis_jobs; etc.
docker logs op af