Skip to main content
Fly.io runs your containers on hardware in 30+ regions worldwide. Combined with Turso’s edge replicas, BunShip can serve requests with single-digit millisecond database latency from anywhere.

Prerequisites

Install flyctl:

Create the Fly App

1

Launch the app

Run fly launch from your project root. This creates a fly.toml configuration file.
When prompted:
  • Choose an app name (e.g., bunship-api)
  • Select your primary region (e.g., iad for Ashburn, Virginia)
  • Decline the Postgres and Redis add-ons (we will configure them separately)
2

Configure fly.toml

Replace the generated fly.toml with this configuration:
3

Set secrets

Store sensitive values as Fly secrets. These are encrypted and injected as environment variables at runtime.
4

Deploy

Fly builds the Docker image remotely using your Dockerfile.api, pushes it to its internal registry, and starts the machine. Watch the deploy output for the health check to pass.

Deploy the Worker

BunShip’s background worker (email sending, webhook delivery, billing sync) runs as a separate Fly app.
1

Create a worker app

2

Create fly.worker.toml

The worker does not expose an HTTP service. It connects to Redis and processes jobs.
3

Set the same secrets

4

Deploy the worker

Turso Integration

Turso and Fly.io work well together because both support edge deployments. Turso can replicate your database to the same regions where your Fly machines run.

Create Edge Replicas

Turso automatically routes reads to the nearest replica. Writes go to the primary and replicate to all locations.

Multi-Region Fly Setup

To deploy your API in multiple regions:
Each API instance reads from the nearest Turso replica, cutting response times for users outside your primary region.

Redis Setup with Upstash

Fly.io integrates with Upstash for managed Redis. Upstash provides a serverless Redis instance with a REST API and per-request pricing.
BullMQ requires a persistent Redis connection. Make sure your Upstash plan supports persistent connections (not just the REST API). The Pro plan and above include this.

Custom Domains

Fly returns the IP addresses and CNAME target for your DNS configuration:
After DNS propagates, update API_URL:

Scaling and Regions

Vertical Scaling

Increase machine size for heavier workloads:

Horizontal Scaling

Add more machines in the same or different regions:
Fly automatically load-balances across machines and routes users to the nearest region via Anycast.

Autoscaling

The fly.toml configuration above includes auto_stop_machines and auto_start_machines. Machines that receive no traffic stop automatically, and restart when a request arrives. This keeps costs low during off-peak hours while maintaining instant availability. Set min_machines_running = 1 to keep at least one machine warm for consistent response times.

Health Checks

The fly.toml includes an HTTP health check:
Fly replaces machines that fail health checks. View machine status with:

Continuous Deployment

GitHub Actions

Add a deploy step to your CI pipeline using the official Fly GitHub Action:
Generate a deploy token:
Add the token as FLY_API_TOKEN in your GitHub repository secrets.

Monitoring

Fly provides built-in Grafana dashboards at fly.io/dashboard with CPU, memory, and network metrics per machine. For application-level monitoring, configure Sentry: