Overview
This guide covers the production deployment setup for the fraud detection ML system. The application is designed to run with Gunicorn as the WSGI HTTP server instead of Flask’s development server.Production Server Configuration
Using Gunicorn
The application uses Gunicorn (Green Unicorn) as the production WSGI HTTP server. This is defined in theProcfile:
- Runs Gunicorn as the web server
- Points to the
appobject inmain.py - Uses default Gunicorn workers and settings
Why Gunicorn?
Flask’s built-in development server is not suitable for production because:- It’s single-threaded and cannot handle concurrent requests efficiently
- It lacks production-grade security features
- It’s not optimized for performance
- Multiple worker processes for handling concurrent requests
- Production-ready performance and stability
- Better resource management
Environment Variables
PORT Configuration
The application reads the PORT from environment variables with a fallback default:PORT: The port number for the application (default: 5001)LANG: Set toen_US.UTF-8for proper encodingLC_ALL: Set toen_US.UTF-8for locale settings
File Structure Requirements
The application expects the following directory structure:Required Modules
Ensure these custom modules are present:prediction_Validation_Insertion.pytrainingModel.pytraining_Validation_Insertion.pypredictFromModel.pyDataTransform_Training/DataTransformation_Prediction/DataTypeValidation_Insertion_Training/DataTypeValidation_Insertion_Prediction/data_ingestion/data_preprocessing/file_operations/best_model_finder/
Database Setup
Flask Monitoring Dashboard Database
The application uses SQLite for the Flask Monitoring Dashboard:- Database file:
flask_monitoringdashboard.db - Automatically created on first run
- Stores monitoring metrics and performance data
Schema Files
The system uses JSON schema files for data validation:schema_training.json: Training data schemaschema_prediction.json: Prediction data schema
Dependencies Installation
Install all required dependencies fromrequirements.txt:
- Flask 1.1.1
- Flask-Cors 3.0.8
- Flask-MonitoringDashboard 3.0.6
- Gunicorn 20.0.4
- scikit-learn 0.22.1
- pandas 0.25.3
- numpy 1.18.1
- xgboost 0.90
- imbalanced-learn 0.6.1
Running in Production
Local Production Testing
Test the production configuration locally:With Worker Processes
For better performance, specify multiple workers:With Logging
Security Considerations
-
CORS Configuration: The application uses Flask-CORS with open access. Review and restrict for production:
-
Debug Mode: Ensure
debug=Trueis removed or set toFalsein production - Environment Variables: Use environment-specific configuration files
- File Permissions: Restrict access to data directories and log files
Health Check
The home route serves as a basic health check:Next Steps
- Configure monitoring dashboard
- Deploy to Heroku
- Set up automated backups for training data
- Configure logging aggregation