Deployment
Performance Considerations
Current Optimizations
-
Database Indexing
- Indexes on runner_id, session_id fields
- Compound indexes for query optimization
-
File Processing
- Duplicate detection via file hashing
- Batch processing for multiple files
- GridFS for efficient binary storage
-
Caching Strategy
- Session statistics cached after calculation
- Personal bests updated incrementally
Performance Characteristics
-
Large File Processing
- FIT file parsing is CPU-intensive
-
Statistics Calculation
- Complex calculations for large datasets
-
Training Plan Generation
- Synchronous processing for complex plans
- Background job implementation available
Deployment Architecture
The application supports multiple deployment strategies for different environments:
Local Development with Docker Compose
services:
web:
build: .
ports:
- "[external_port]:5000"
volumes:
- ./app:/app/app
- ./data:/app/data
environment:
- FLASK_ENV=development
networks:
- running-network
Production Kubernetes Deployment
The application includes a complete Kubernetes CI/CD pipeline for Google Cloud Platform deployment:
Kubernetes Resources
Deployment Configuration (deployment.yml):
apiVersion: apps/v1
kind: Deployment
metadata:
name: smartrunning-localapp
spec:
replicas: 2
selector:
matchLabels:
app: smartrunning-localapp
template:
spec:
containers:
- name: app
image: LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE:TAG
ports:
- containerPort: 5000
resources:
requests:
cpu: "250m"
memory: "512Mi"
limits:
cpu: "1000m"
memory: "2Gi"
env:
- name: FLASK_ENV
value: "production"
- name: MONGO_CONNECTION_STRING
value: "mongodb+srv://..."
- name: SSL_CERT_FILE
value: "/etc/ssl/certs/ca-certificates.crt"
- name: REQUESTS_CA_BUNDLE
value: "/etc/ssl/certs/ca-certificates.crt"
Service Configuration (service.yml):
apiVersion: v1
kind: Service
metadata:
name: smartrunning-localapp-service
spec:
type: LoadBalancer
selector:
app: smartrunning-localapp
ports:
- port: 8347
targetPort: 5000
protocol: TCP
Kustomization (kustomization.yaml):
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yml
- service.yml
images:
- name: LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE:TAG
newName: LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE
newTag: TAG
Deployment Features
-
Container Orchestration
- Kubernetes deployment with 2 replicas for high availability
- LoadBalancer service for external access
- Automatic container restart and health monitoring
-
Google Cloud Integration
- Container images stored in Google Artifact Registry
- Deployment via Google Kubernetes Engine (GKE)
- SSL termination and load balancing
- SSL/TLS Configuration:
- Docker image includes ca-certificates and openssl packages
- Certifi Python package for SSL certificate management
- Proper SSL context creation for MongoDB connections
- Environment variables for SSL certificate paths
-
Environment Management
- Production environment variables
- Secure database connection strings
- Configurable resource limits
Production State
-
Scaling
- Horizontal scaling via Kubernetes replicas
- LoadBalancer distributes traffic across pods
- Auto-scaling capabilities available
-
Monitoring
- Kubernetes health checks and restart policies
- Container resource monitoring
- Application performance monitoring available via GCP
-
Backup
- MongoDB Atlas automated backups
- GridFS data replication
- Kubernetes configuration stored in version control
API Design
RESTful Principles
The API follows REST conventions:
- Resources:
/runners,/sessions,/workouts,/training-plans,/calculate_critical_speed - HTTP Methods: GET, POST, PUT, DELETE
- Status Codes: Proper HTTP status codes (200, 201, 400, 404, 500)
- JSON Responses: Consistent response format
Key Endpoints
-
POST /calculate_performance_metrics - Calculate performance metrics from personal best times
- Input: Personal best times for multiple distances
- Output: Performance metric values and statistical quality indicators
-
POST /calculate_heart_rate_zones - Calculate heart rate zones based on age using HUNT formula
- Input:
age(integer, 1-120) - Output:
max_heart_rate,zones(hr_zone_1_max through hr_zone_5_max),age
- Input:
Development Workflow
For local development setup and commands, see Platform Overview.
Code Organization
app/
├── Core Application
│ ├── __init__.py # App factory
│ ├── config.py # Configuration
│ └── routes.py # API endpoints
├── Data Layer
│ ├── database.py # DB operations
│ └── models.py # Data models
├── Service Layer
│ ├── file_processor.py
│ ├── statistics_processor.py
│ └── training_plan_generator.py
└── Utilities
├── defaults.py # Default values
└── job_manager.py # Background tasks
SSL/TLS Architecture
Certificate Management:
- Docker layer includes ca-certificates and openssl packages
- Certifi package provides up-to-date CA certificate bundle
- SSL context created with proper certificate validation
- Environment variables for certificate paths (SSL_CERT_FILE, REQUESTS_CA_BUNDLE)
For SSL/TLS troubleshooting, see the MongoDB Setup Guide.