Deployment Infrastructure
AltSportsLeagues.ai operates a sophisticated, cloud-native deployment infrastructure that ensures high availability, scalability, and reliability across the entire platform. Our infrastructure combines Google Cloud Run for backend services, Vercel for frontend applications, and comprehensive automation for seamless deployments.
Infrastructure Architecture
Deployment Strategies
Unified Full-Stack Deployment
Recommended for: Production deployments, new environments
Architecture: Backend (Cloud Run) + Frontend (Vercel) + n8n (Cloud Run)
Deployment Time: 8-15 minutes
Process:
# Complete production deployment
./deploy-unified.sh
# Select option 1 (Full Stack)
# What happens:
# 1. Backend deploys to Cloud Run (5-8 min)
# 2. n8n deploys to Cloud Run (2-3 min)
# 3. Frontend deploys to Vercel (2-3 min)
# 4. URLs are linked automatically
# 5. Health checks verify everything worksBackend-Only Deployment
Recommended for: API development, backend updates
Architecture: Cloud Run service with full data layer
Deployment Time: 5-10 minutes
Features:
- 3GB Data Layer: Complete knowledge base included
- Optimized Build: Custom Dockerfile for performance
- Health Checks: Automatic post-deployment validation
- Resource Allocation: 4Gi memory, 2 vCPUs
cd apps/backend
./deploy-enhanced.shFrontend-Only Deployment
Recommended for: UI updates, feature releases
Architecture: Vercel Edge Network with SSR
Deployment Time: 2-3 minutes
Features:
- Edge Network: Global CDN distribution
- Server-Side Rendering: SEO optimization and performance
- API Rewrites: Automatic backend URL routing
- Preview Deployments: Per-branch preview URLs
cd clients/frontend
./deploy-to-vercel.shService Configuration
Google Cloud Run Backend
Resource Configuration:
# cloud-run/backend-service.yml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: altsports-backend
spec:
template:
spec:
containers:
- image: gcr.io/project/altsports-backend:latest
resources:
limits:
memory: 4Gi
cpu: 2000m
env:
- name: ENVIRONMENT
value: production
- name: GOOGLE_CLOUD_PROJECT
value: altsports-data
ports:
- containerPort: 8000Scaling Configuration:
- Min Instances: 0 (scale to zero when idle)
- Max Instances: 100 (auto-scaling based on load)
- Concurrency: 80 requests per instance
- Timeout: 300 seconds (5 minutes) for long-running AI operations
Vercel Frontend
Build Configuration:
// vercel.json
{
"buildCommand": "npm run build",
"outputDirectory": ".next",
"framework": "nextjs",
"rewrites": [
{
"source": "/api/:path*",
"destination": "https://altsports-backend-*.run.app/api/:path*"
}
],
"headers": [
{
"source": "/api/(.*)",
"headers": [
{"key": "Access-Control-Allow-Origin", "value": "*"},
{"key": "Access-Control-Allow-Methods", "value": "GET,POST,PUT,DELETE,OPTIONS"},
{"key": "Access-Control-Allow-Headers", "value": "Content-Type,Authorization"}
]
}
]
}n8n Workflow Engine
Deployment Configuration:
# cloud-run/n8n-service.yml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: altsports-n8n
spec:
template:
spec:
containers:
- image: gcr.io/project/altsports-n8n:latest
resources:
limits:
memory: 2Gi
cpu: 1000m
env:
- name: N8N_ENCRYPTION_KEY
valueFrom:
secretKeyRef:
name: n8n-secrets
key: encryption-key
- name: DB_TYPE
value: postgresdb
- name: DB_POSTGRESDB_HOST
valueFrom:
configMapKeyRef:
name: n8n-config
key: db-hostCI/CD Pipeline
GitHub Actions Workflows
Complete CI/CD Pipeline:
# .github/workflows/deploy.yml
name: Deploy to Production
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Run Tests
run: make test
- name: Build Docker Image
run: docker build -t altsports-backend .
deploy-backend:
needs: test
runs-on: ubuntu-latest
steps:
- name: Deploy to Cloud Run
uses: google-github-actions/deploy-cloudrun@v1
with:
service: altsports-backend
image: gcr.io/${{ secrets.GCP_PROJECT }}/altsports-backend:${{ github.sha }}
deploy-frontend:
needs: deploy-backend
runs-on: ubuntu-latest
steps:
- name: Deploy to Vercel
uses: amondnet/vercel-action@v25
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}Cloud Build Configuration
Multi-stage Docker Build:
# cloudbuild.yaml
steps:
# Build stage
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/$PROJECT_ID/altsports-backend', '.']
# Test stage
- name: 'gcr.io/cloud-builders/docker'
args: ['run', 'gcr.io/$PROJECT_ID/altsports-backend', 'pytest']
# Push stage
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/altsports-backend']
# Deploy stage
- name: 'gcr.io/google-appengine/exec-wrapper'
args: [
'-c',
'gcloud run deploy altsports-backend
--image gcr.io/$PROJECT_ID/altsports-backend
--region us-central1
--allow-unauthenticated'
]Environment Management
Environment Variables
Backend Environment:
# Required for production
GOOGLE_CLOUD_PROJECT=altsports-data
FIREBASE_PROJECT_ID=altsports-data
SUPABASE_URL=https://*.supabase.co
SUPABASE_ANON_KEY=eyJ...
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_APPLICATION_CREDENTIALS=/secrets/service-account.json
N8N_WEBHOOK_URL=https://n8n-*.run.appFrontend Environment:
NEXT_PUBLIC_API_URL=https://altsports-backend-*.run.app
NEXTAUTH_SECRET=your-secret-key
NEXTAUTH_URL=https://altsports-frontend.vercel.app
GOOGLE_CLIENT_ID=*.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=GOCSPX-...Secret Management
Google Cloud Secret Manager:
# Create secrets
echo -n "your-secret-key" | gcloud secrets create openai-api-key --data-file=-
# Access in Cloud Run
export OPENAI_API_KEY=$(gcloud secrets versions access latest --secret=openai-api-key)Environment Sync Tool:
# Sync environment variables across deployments
./sync-env-variables.sh --from production --to stagingMonitoring & Observability
Application Performance Monitoring
Cloud Monitoring Dashboards:
- Request Latency: P95 response times by endpoint
- Error Rates: 5xx error percentages over time
- Resource Usage: CPU, memory, and disk utilization
- Custom Metrics: Business-specific KPIs
Logging Architecture:
# Structured logging in FastAPI
import structlog
logger = structlog.get_logger()
@app.middleware("http")
async def log_requests(request: Request, call_next):
start_time = time.time()
response = await call_next(request)
process_time = time.time() - start_time
logger.info(
"Request completed",
method=request.method,
url=str(request.url),
status_code=response.status_code,
duration=process_time,
user_agent=request.headers.get("user-agent")
)
return responseHealth Checks & Alerts
Health Endpoints:
GET /health- Basic service healthGET /health/detailed- Comprehensive health checkGET /metrics- Prometheus metrics endpoint
Alert Configuration:
# Alert policies
alert_policies:
- name: high-error-rate
condition: rate(error_count[5m]) > 0.05
notification_channels: [email, slack]
- name: high-latency
condition: latency_p95 > 5000
notification_channels: [pagerduty]
- name: low-success-rate
condition: success_rate < 0.95
notification_channels: [email]Disaster Recovery
Backup Strategy
Database Backups:
- Firestore: Automatic daily backups, 30-day retention
- Supabase: Point-in-time recovery, 7-day retention
- ChromaDB: Vector database snapshots every 6 hours
Application Backups:
- Container Images: Immutable images stored in GCR
- Configuration: Infrastructure as code in Git
- Secrets: Encrypted secrets in Secret Manager
Recovery Procedures
Service Recovery:
# Quick service restart
gcloud run services update altsports-backend --region us-central1 --no-traffic
# Full redeployment
./deploy-unified.sh --forceData Recovery:
# Restore from backup
gcloud firestore import gs://backups/altsports-data --collection-ids=leagues,contracts
# Point-in-time recovery
supabase db restore --target-time "2024-01-01 12:00:00"Security & Compliance
Network Security
VPC Configuration:
# Terraform VPC setup
resource "google_compute_network" "vpc" {
name = "altsports-vpc"
auto_create_subnetworks = false
}
resource "google_compute_subnetwork" "subnet" {
name = "altsports-subnet"
ip_cidr_range = "10.0.0.0/24"
network = google_compute_network.vpc.id
region = "us-central1"
}Firewall Rules:
resource "google_compute_firewall" "allow_http" {
name = "allow-http"
network = google_compute_network.vpc.name
allow {
protocol = "tcp"
ports = ["80", "443"]
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["http-server"]
}Access Control
IAM Configuration:
# Service account permissions
roles:
- role: roles/cloudrun.invoker
members:
- serviceAccount:altsports-backend@altsports-data.iam.gserviceaccount.com
- role: roles/datastore.user
members:
- serviceAccount:altsports-backend@altsports-data.iam.gserviceaccount.com
- role: roles/secretmanager.secretAccessor
members:
- serviceAccount:altsports-backend@altsports-data.iam.gserviceaccount.comCost Optimization
Resource Optimization
Cloud Run Scaling:
- CPU Allocation: 2 vCPUs during peak hours, 1 vCPU off-peak
- Memory: 4Gi baseline, auto-scaling to 8Gi under load
- Request Timeout: 300 seconds for AI operations
Storage Optimization:
- Firestore: Automatic indexing, query optimization
- ChromaDB: Vector compression, batch processing
- CDN: Vercel Edge Network for global distribution
Cost Monitoring
Budget Alerts:
# GCP budget configuration
budgets:
- name: monthly-budget
amount: 5000
currency: USD
notifications:
- threshold: 0.5 # 50% of budget
type: email
- threshold: 0.8 # 80% of budget
type: email
- threshold: 0.9 # 90% of budget
type: slackPerformance Benchmarks
Latency Targets
| Operation | Target Latency | Current Performance |
|---|---|---|
| API Health Check | < 100ms | 45ms average |
| Sports Intelligence Query | < 2000ms | 850ms average |
| Contract Generation | < 5000ms | 2800ms average |
| League Questionnaire Processing | < 30000ms | 8500ms average |
| Vector Search | < 500ms | 120ms average |
Throughput Targets
| Service | Target RPS | Current Performance |
|---|---|---|
| Backend API | 100 RPS | 150 RPS sustained |
| Frontend SSR | 1000 RPS | 800 RPS sustained |
| n8n Workflows | 50 RPS | 75 RPS sustained |
| Vector Search | 200 RPS | 300 RPS sustained |
Availability Targets
- Service Level Agreement: 99.9% uptime
- Mean Time Between Failures: > 720 hours
- Mean Time To Recovery: < 15 minutes
- Data Durability: 99.999999999% (11 9's)
Deployment Quick Reference
Emergency Deployments
# Immediate rollback
gcloud run revisions list --service altsports-backend --region us-central1
gcloud run services update-traffic altsports-backend \
--to-revisions previous-version=100 --region us-central1
# Emergency scale up
gcloud run services update altsports-backend \
--max-instances 200 --region us-central1Monitoring Commands
# Check service status
gcloud run services describe altsports-backend --region us-central1
# View logs
gcloud logging read "resource.type=cloud_run_revision AND resource.labels.service_name=altsports-backend" --limit 50
# Check metrics
gcloud monitoring dashboards list --filter "altsports"Cost Analysis
# Monthly cost breakdown
gcloud billing accounts list
gcloud billing export create PROJECT_BILLING_ID \
--bucket gs://altsports-billing \
--dataset altsports_billing_dataset
# Cost by service
bq query --use_legacy_sql=false "
SELECT service.description, SUM(cost) as total_cost
FROM \`altsports_billing_dataset.gcp_billing_export_*\`
WHERE DATE(_PARTITIONTIME) >= '2024-01-01'
GROUP BY service.description
ORDER BY total_cost DESC
"This deployment infrastructure provides a robust, scalable, and cost-effective foundation for AltSportsLeagues.ai's mission-critical operations, ensuring high availability and performance for sports business intelligence applications.