Fly.io
01 / 02

Multi-Region, Volumes & Postgres

Fly.io: Multi-Region, Volumes & Postgres

Multi-Region Deployment

# Add regions -- Machines get created in each, and Anycast routing
# sends each user's request to their nearest healthy instance
fly regions add fra nrt syd
fly regions list

# Scale Machine count per region
fly scale count 2 --region iad
fly scale count 1 --region fra

# A CDN in front of a single-region backend only speeds up cacheable
# static content -- dynamic requests still round-trip to one origin.
# Fly runs the actual app logic in each region, so dynamic requests
# benefit from proximity too, not just static assets.

Volumes (Persistent Storage)

# A Machine's regular filesystem is ephemeral -- resets when the
# Machine stops/gets replaced. A Volume gives durable, region-pinned
# storage that survives restarts and redeploys.
fly volumes create data --region iad --size 10

# Attach it in fly.toml
# [mounts]
#   source = "data"
#   destination = "/data"

# Volumes are tied to a SPECIFIC region/host -- a design constraint
# to plan around for multi-region apps needing per-region storage.

Fly Postgres

# Fly Postgres runs actual Postgres instances as Fly Machines
# (with attached Volumes), using a Fly-managed HA setup
# (primary + replicas) -- more infrastructure control than a fully
# managed offering, at the cost of more operational responsibility
# (upgrades, failover tuning, backup verification).
fly postgres create --name my-db --region iad
fly postgres attach my-db --app my-api   # injects DATABASE_URL as a secret

# Trade-off: co-locating DB with app regions and custom config is
# possible, but the team owns more of the day-to-day DB operations
# a fully managed provider would otherwise absorb.

Scale to Zero

  • auto_stop_machines lets idle Machines shut down entirely -- no compute cost while stopped.

  • auto_start_machines automatically restarts a stopped Machine on the next incoming request.

  • Firecracker's fast boot time keeps the cold-start penalty much smaller than on heavier VM-based platforms.

  • min_machines_running controls the floor -- set above 0 to keep at least one instance always warm if cold starts are unacceptable for that route.

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free