Skip to main content

Fly.io Deployment

Deploy Data Stream to Fly.io for global edge deployment.

Prerequisites

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

  1. Check region placement: fly regions list
  2. Scale in user's region
  3. Consider Redis caching

Environment Variables

VariableDescriptionExample
PORTHTTP port8080
REDIS_URLRedis connectionredis://data-stream-redis.internal:6379
WT_ENABLEDWebTransportfalse

Costs

ResourceCost
Shared CPU (256MB)~$1.94/mo
Dedicated CPU (1x)~$5.70/mo
Redis (256MB)~$3/mo
BandwidthFirst 100GB free

Best Practices

  1. Use internal networking - Redis via .internal domain
  2. Set min_machines_running - Prevent cold starts
  3. Enable force_https - Security
  4. Use secrets - Never hardcode credentials
  5. Monitor logs - Set up alerts