Cloud Platform Deployment¶
This guide covers deploying StreamBot on major cloud platforms with comprehensive instructions for each provider, including video streaming optimizations.
Platform Comparison¶
Platform | Ease of Use | Cost | Performance | Video Streaming | Free Tier |
---|---|---|---|---|---|
Railway | ⭐⭐⭐⭐⭐ | $$ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ✅ |
Heroku | ⭐⭐⭐⭐ | $$$ | ⭐⭐⭐ | ⭐⭐⭐ | ✅ |
DigitalOcean | ⭐⭐⭐⭐ | $$ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ❌ |
AWS | ⭐⭐⭐ | $ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ✅ |
Google Cloud | ⭐⭐⭐ | $$ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ✅ |
Render | ⭐⭐⭐⭐ | $$ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ✅ |
Railway (Recommended for Beginners)¶
Railway offers the simplest deployment process with excellent performance for video streaming.
Quick Deploy¶
Manual Deployment¶
-
Create Railway Account: Sign up at railway.app
-
Connect GitHub Repository:
-
Create New Project in Railway dashboard
-
Deploy from GitHub:
- Connect your GitHub account
- Select the forked repository
-
Railway will auto-detect the Python app
-
Configure Environment Variables:
-
Add MongoDB Service:
- Click "New Service" → "Database" → "MongoDB"
-
Railway will automatically provide
DATABASE_URL
-
Custom Domain (Optional):
- Go to Settings → Custom Domain
- Add your domain and configure DNS
Railway Optimization for Video Streaming¶
# Railway-specific optimizations
RAILWAY_ENVIRONMENT=production
PYTHONUNBUFFERED=1
WEB_CONCURRENCY=4
MAX_WORKERS=4
# Video streaming optimizations
VIDEO_CHUNK_SIZE=1048576
STREAM_TIMEOUT=3600
MAX_CONCURRENT_STREAMS=50
Heroku¶
Heroku provides a robust platform with excellent addon ecosystem.
Prerequisites¶
- Heroku CLI installed
- Git repository ready
Deployment Steps¶
-
Install Heroku CLI:
-
Login and Create App:
-
Add MongoDB Addon:
-
Configure Environment Variables:
heroku config:set API_ID=your_api_id heroku config:set API_HASH=your_api_hash heroku config:set BOT_TOKEN=your_bot_token heroku config:set LOG_CHANNEL=-1001234567890 heroku config:set BASE_URL=https://your-streambot-app.herokuapp.com heroku config:set VIDEO_FRONTEND_URL=https://cricster.pages.dev heroku config:set ADMINS=your_telegram_user_id heroku config:set PYTHON_VERSION=3.11.0
-
Create Procfile:
-
Deploy:
-
Scale Dynos:
Heroku Video Streaming Configuration¶
# Configure for video streaming
heroku config:set MAX_REQUEST_SIZE=2147483648
heroku config:set STREAM_CHUNK_SIZE=1048576
heroku config:set ENABLE_RANGE_REQUESTS=true
heroku config:set VIDEO_CACHE_TTL=3600
DigitalOcean App Platform¶
DigitalOcean App Platform offers excellent performance for video streaming with competitive pricing.
Deployment via GitHub¶
-
Create DigitalOcean Account: Sign up at digitalocean.com
-
Create App:
- Go to Apps → Create App
- Connect GitHub repository
-
Select your StreamBot repository
-
Configure Build Settings:
# .do/app.yaml name: streambot services: - name: web source_dir: / github: repo: your-username/Telegram-Download-Link-Generator branch: main run_command: python -m StreamBot environment_slug: python instance_count: 1 instance_size_slug: basic-xxs http_port: 8080 routes: - path: / databases: - name: mongodb engine: MONGODB version: "5"
-
Environment Variables:
DigitalOcean CDN for Video Streaming¶
# Enable CDN for better video streaming
curl -X POST \
https://api.digitalocean.com/v2/cdn/endpoints \
-H "Authorization: Bearer $DO_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"origin": "your-app.ondigitalocean.app",
"ttl": 3600,
"custom_domain": "cdn.yourdomain.com"
}'
Amazon Web Services (AWS)¶
AWS provides the most comprehensive cloud infrastructure with global CDN for optimal video streaming.
AWS Elastic Beanstalk Deployment¶
-
Install AWS CLI and EB CLI:
-
Initialize Elastic Beanstalk:
-
Create Environment:
-
Configure Environment Variables:
-
Deploy:
AWS DocumentDB (MongoDB Compatible)¶
# Create DocumentDB cluster
aws docdb create-db-cluster \
--db-cluster-identifier streambot-cluster \
--engine docdb \
--master-username admin \
--master-user-password your-secure-password \
--vpc-security-group-ids sg-xxxxxxxx
AWS CloudFront for Video Streaming¶
{
"DistributionConfig": {
"CallerReference": "streambot-cdn",
"DefaultRootObject": "index.html",
"Origins": {
"Quantity": 1,
"Items": [
{
"Id": "streambot-origin",
"DomainName": "your-app.elasticbeanstalk.com",
"CustomOriginConfig": {
"HTTPPort": 80,
"HTTPSPort": 443,
"OriginProtocolPolicy": "https-only"
}
}
]
},
"DefaultCacheBehavior": {
"TargetOriginId": "streambot-origin",
"ViewerProtocolPolicy": "redirect-to-https",
"CachePolicyId": "4135ea2d-6df8-44a3-9df3-4b5a84be39ad",
"Compress": true
}
}
}
Google Cloud Platform (GCP)¶
GCP offers excellent global infrastructure with competitive pricing for video streaming.
Google Cloud Run Deployment¶
-
Install Google Cloud SDK:
-
Initialize Project:
-
Create Dockerfile (if not exists):
-
Build and Deploy:
-
Set Environment Variables:
Google Cloud CDN for Video Streaming¶
# Create Cloud CDN
gcloud compute backend-services create streambot-backend \
--global \
--load-balancing-scheme=EXTERNAL
gcloud compute url-maps create streambot-map \
--default-service streambot-backend
gcloud compute target-https-proxies create streambot-proxy \
--url-map streambot-map \
--ssl-certificates streambot-ssl
Render¶
Render provides a modern platform with automatic SSL and easy deployments.
Render Deployment¶
-
Connect GitHub: Link your GitHub account to Render
-
Create Web Service:
- Select your repository
- Choose "Web Service"
-
Configure build settings:
-
Build Configuration:
# render.yaml services: - type: web name: streambot env: python buildCommand: pip install -r requirements.txt startCommand: python -m StreamBot envVars: - key: API_ID value: your_api_id - key: API_HASH value: your_api_hash - key: BOT_TOKEN value: your_bot_token - key: LOG_CHANNEL value: -1001234567890 - key: VIDEO_FRONTEND_URL value: https://cricster.pages.dev - key: DATABASE_URL fromDatabase: name: streambot-db property: connectionString databases: - name: streambot-db databaseName: streambot user: streambot
-
Auto-Deploy: Render automatically deploys on git push
Video Streaming Optimizations¶
CDN Configuration¶
For optimal video streaming performance across all platforms:
# Nginx configuration for video streaming
location /stream/ {
proxy_pass http://localhost:8080;
proxy_buffering off;
proxy_request_buffering off;
proxy_http_version 1.1;
proxy_set_header Connection "";
# Enable range requests
proxy_set_header Range $http_range;
proxy_set_header If-Range $http_if_range;
# Optimize for video streaming
proxy_cache_bypass $http_range;
proxy_no_cache $http_range;
}
Environment Variables for Video Streaming¶
# Video streaming optimizations (all platforms)
VIDEO_CHUNK_SIZE=1048576
MAX_CONCURRENT_STREAMS=50
STREAM_TIMEOUT=3600
ENABLE_RANGE_REQUESTS=true
VIDEO_CACHE_TTL=3600
CORS_ORIGINS=https://cricster.pages.dev,https://yourdomain.com
Cost Optimization¶
Free Tier Recommendations¶
- Development: Railway or Render free tier
- Small Production: Heroku hobby tier
- High Traffic: DigitalOcean or AWS with reserved instances
Cost Monitoring¶
# Set up billing alerts (AWS example)
aws budgets create-budget \
--account-id 123456789012 \
--budget '{
"BudgetName": "StreamBot Monthly Budget",
"BudgetLimit": {
"Amount": "50",
"Unit": "USD"
},
"TimeUnit": "MONTHLY",
"BudgetType": "COST"
}'
Monitoring and Scaling¶
Health Checks¶
All platforms should monitor these endpoints:
# Health check endpoint
curl https://your-app.com/api/info
# Video streaming health
curl -I https://your-app.com/stream/test
Auto-Scaling Configuration¶
# Kubernetes auto-scaling example
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: streambot-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: streambot
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
Troubleshooting¶
Common Deployment Issues¶
Build Failures:
# Check Python version
python --version # Should be 3.11+
# Install dependencies locally first
pip install -r requirements.txt
Environment Variable Issues:
Video Streaming Issues:
# Test streaming endpoint
curl -I https://your-app.com/stream/test
curl -H "Range: bytes=0-1023" https://your-app.com/stream/test
Performance Optimization¶
# Add to your deployment configuration
import os
# Optimize for cloud deployment
if os.getenv('CLOUD_PROVIDER') == 'heroku':
# Heroku-specific optimizations
MAX_WORKERS = int(os.getenv('WEB_CONCURRENCY', 4))
WORKER_TIMEOUT = 120
elif os.getenv('CLOUD_PROVIDER') == 'aws':
# AWS-specific optimizations
MAX_WORKERS = int(os.getenv('AWS_LAMBDA_FUNCTION_MEMORY_SIZE', 512)) // 128
elif os.getenv('CLOUD_PROVIDER') == 'gcp':
# GCP-specific optimizations
MAX_WORKERS = int(os.getenv('CLOUD_RUN_CPU', 1)) * 2
Next Steps¶
After deployment:
- Configure Custom Domain: Set up your own domain for better branding
- Enable HTTPS: Ensure SSL certificates are properly configured
- Set Up Monitoring: Configure uptime monitoring and alerts
- Optimize Performance: Implement CDN and caching strategies
- Security Hardening: Follow security best practices for your platform
- Backup Strategy: Set up automated backups for your database
For platform-specific advanced configurations, refer to: - Docker Deployment for containerized deployments - VPS Setup for self-hosted solutions - Security Configuration for hardening your deployment
These comprehensive cloud deployment guides are currently in development. Stay tuned for detailed instructions!