Skip to content

Fly.io Deployment

Deploy the Pisama backend to Fly.io for low-latency, globally distributed hosting.

Backend Deployment

Deploy from the repo root. The fly.toml and Dockerfile live there, with the Docker build context set to the repo root (there is no separate backend/Dockerfile).

# Create the app
fly launch --name pisama-api --no-deploy

# Set secrets
fly secrets set \
  JWT_SECRET=$(openssl rand -base64 32) \
  DATABASE_URL="postgresql+asyncpg://user:pass@host:5432/pisama" \
  REDIS_URL="redis://host:6379" \
  ENVIRONMENT=production \
  CORS_ORIGINS="https://your-frontend.vercel.app"

# Deploy
fly deploy

Dockerfile

The Dockerfile at the repo root is production-ready:

  • Python 3.11-slim base image
  • Non-root user (pisama) for security
  • CPU-only PyTorch for sentence-transformers (smaller image)
  • Built-in health check on /health
  • Configurable port via $PORT environment variable

Scaling

# Scale to 2 instances
fly scale count 2

# Increase memory (embedding models need ~1GB)
fly scale memory 1024

# View current scaling
fly scale show

Database Options

Fly.io does not provide managed PostgreSQL with pgvector. Options:

Provider Recommended For pgvector
Supabase Hobby / Startup Pre-installed
Neon Serverless workloads Available
AWS RDS Enterprise Manual enable
Fly Postgres Simple setup Manual enable

Ensure you enable the pgvector extension:

CREATE EXTENSION IF NOT EXISTS vector;

Frontend Deployment

Deploy the frontend to Vercel (recommended) or as a separate Fly.io app:

cd frontend
vercel --prod

Set NEXT_PUBLIC_API_URL to your Fly.io backend URL.

cd frontend
fly launch --name pisama-web --no-deploy
fly secrets set \
  NEXT_PUBLIC_API_URL="https://api.pisama.ai/api/v1" \
  NEXTAUTH_SECRET=$(openssl rand -base64 32) \
  NEXTAUTH_URL="https://pisama-web.fly.dev"
fly deploy

Health Check

curl https://api.pisama.ai/api/v1/health
# {"status": "healthy", "database": "healthy", "redis": "healthy", "version": "..."}

Monitoring

Fly.io provides built-in logging and metrics:

# View logs
fly logs

# View metrics
fly dashboard

Pisama also exposes Prometheus metrics:

curl https://api.pisama.ai/api/v1/metrics