Fly.io Deployment
Deploy Data Stream to Fly.io for global edge deployment.
Prerequisites
- Fly.io CLI installed
- Fly.io account
Quick Deploy
cd backend
# Login to Fly.io
fly auth login
# Deploy
fly deploy
Configuration
fly.toml
app = "data-stream"
primary_region = "gru"
[build]
dockerfile = "Dockerfile"
[env]
REDIS_URL = "redis://data-stream-redis.internal:6379"
PORT = "8080"
[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = "off"
auto_start_machines = true
min_machines_running = 1
[[vm]]
memory = "256mb"
cpu_kind = "shared"
cpus = 1
count = 1
Redis Setup
Create a Redis instance on Fly.io:
# Create Redis
fly redis create --name data-stream-redis --region gru
# Get connection URL
fly redis status data-stream-redis
Deploy Steps
1. Create App
fly apps create data-stream
2. Set Secrets
# Redis URL is auto-set via internal networking
# Add any additional secrets
fly secrets set SOME_SECRET=value
3. Deploy
fly deploy
4. Verify
# Check status
fly status
# View logs
fly logs
# Open in browser
fly open
Scaling
Horizontal Scaling
# Scale to 2 instances
fly scale count 2
# Scale in specific regions
fly scale count 2 --region gru
fly scale count 1 --region iad
Vertical Scaling
# Upgrade VM size
fly scale vm shared-cpu-1x --memory 512
Multi-Region
# Add regions
fly regions add iad fra
# Scale in each region
fly scale count 1 --region gru
fly scale count 1 --region iad
fly scale count 1 --region fra
Custom Domain
# Add custom domain
fly certs add data-stream.example.com
# Check DNS
fly certs show data-stream.example.com
Monitoring
Logs
# Stream logs
fly logs
# Filter by instance
fly logs --instance abc123
Metrics
Fly.io provides built-in metrics at:
https://fly.io/apps/data-stream/monitoring
Health Check
# Check app health
fly status
# SSH into instance
fly ssh console
Troubleshooting
App Not Starting
# Check logs
fly logs --tail 100
# Check deployment
fly releases
Redis Connection Failed
# Verify Redis is running
fly redis status data-stream-redis
# Check internal networking
fly ssh console
> ping data-stream-redis.internal
High Latency
- Check region placement:
fly regions list - Scale in user's region
- Consider Redis caching
Environment Variables
| Variable | Description | Example |
|---|---|---|
PORT | HTTP port | 8080 |
REDIS_URL | Redis connection | redis://data-stream-redis.internal:6379 |
WT_ENABLED | WebTransport | false |
Costs
| Resource | Cost |
|---|---|
| Shared CPU (256MB) | ~$1.94/mo |
| Dedicated CPU (1x) | ~$5.70/mo |
| Redis (256MB) | ~$3/mo |
| Bandwidth | First 100GB free |
Best Practices
- Use internal networking - Redis via
.internaldomain - Set min_machines_running - Prevent cold starts
- Enable force_https - Security
- Use secrets - Never hardcode credentials
- Monitor logs - Set up alerts