How Heroku and Fly.io compare on dynos and Machines, Postgres, workers, scheduled jobs, regions and pricing, and when to run the backend in your own AWS or GCP account instead.

Heroku made git push deploys the default for a generation of web apps, with dynos, a Procfile and add-ons that attach a database or a scheduler in one command. Fly.io took a lower-level route, running your Docker image as Machines in the regions you choose and billing them by the second, and became a common next stop for Heroku users after Heroku moved into sustaining engineering in February 2026.
This guide compares Heroku and Fly.io for backend work, on compute, Postgres, workers, scheduled jobs, regions and pricing, and covers when the better move is a backend in your own AWS or GCP account with Encore.
Heroku prices are from heroku.com/pricing and the Heroku Postgres add-on page, and Fly.io prices from its resource pricing docs for the Ashburn and Secaucus regions, all checked November 17, 2026.
Encore brings infrastructure from code to Go and TypeScript backends, so the database, queues, schedules and secrets a Heroku or Fly.io app configures in a dashboard or fly.toml are declared in the code and provisioned in your own AWS or GCP account on git push. A typical app with a web process, a worker, Postgres and a nightly job maps onto declarations in one Go file.
Run in your terminal to get started locally.
The service receives paid-order webhooks, hands fulfilment to a subscriber the way a worker dyno or worker Machine would, and prunes old orders nightly. The migration keys each row by the provider's event ID and the order ID:
-- orders/migrations/1_create_orders.up.sql
CREATE TABLE paid_orders (
event_id TEXT PRIMARY KEY,
order_id TEXT NOT NULL UNIQUE,
email TEXT NOT NULL,
received_at TIMESTAMPTZ NOT NULL DEFAULT now(),
fulfilled_at TIMESTAMPTZ
);
// orders/orders.go
package orders
import (
"context"
"crypto/subtle"
"errors"
"time"
"encore.dev/beta/errs"
"encore.dev/cron"
"encore.dev/pubsub"
"encore.dev/rlog"
"encore.dev/storage/sqldb"
)
// Replaces a Heroku config var or a Fly secret; the value is set with
// `encore secret set` and never stored in the repository.
var secrets struct {
OrdersWebhookToken string
}
// Replaces Heroku Postgres or Fly Managed Postgres: RDS or Cloud SQL in your
// account, started locally by `encore run`.
var db = sqldb.NewDatabase("orders", sqldb.DatabaseConfig{
Migrations: "./migrations",
})
type OrderPaid struct {
OrderID string
}
// Replaces the worker dyno or worker Machine and its Redis queue.
var Paid = pubsub.NewTopic[*OrderPaid]("order-paid", pubsub.TopicConfig{
DeliveryGuarantee: pubsub.AtLeastOnce,
})
type WebhookParams struct {
Token string `header:"X-Webhook-Token"`
EventID string `json:"event_id"`
OrderID string `json:"order_id"`
Email string `json:"email"`
}
//encore:api public method=POST path=/webhooks/orders
func Webhook(ctx context.Context, p *WebhookParams) error {
if subtle.ConstantTimeCompare([]byte(p.Token), []byte(secrets.OrdersWebhookToken)) != 1 {
return &errs.Error{Code: errs.Unauthenticated, Message: "bad webhook token"}
}
if p.EventID == "" || p.OrderID == "" || p.Email == "" {
return &errs.Error{Code: errs.InvalidArgument, Message: "event_id, order_id and email required"}
}
// The provider retries webhooks, so the insert is idempotent on the event
// and the order.
if _, err := db.Exec(ctx, `
INSERT INTO paid_orders (event_id, order_id, email) VALUES ($1, $2, $3)
ON CONFLICT DO NOTHING`, p.EventID, p.OrderID, p.Email); err != nil {
return err
}
// Publish unless the order is already fulfilled, so a retry after a failed
// publish still reaches the subscriber, which drops duplicates.
var fulfilled bool
if err := db.QueryRow(ctx, `
SELECT fulfilled_at IS NOT NULL FROM paid_orders WHERE order_id = $1`,
p.OrderID).Scan(&fulfilled); err != nil {
return err
}
if fulfilled {
return nil
}
_, err := Paid.Publish(ctx, &OrderPaid{OrderID: p.OrderID})
return err
}
var _ = pubsub.NewSubscription(Paid, "fulfil", pubsub.SubscriptionConfig[*OrderPaid]{
Handler: func(ctx context.Context, m *OrderPaid) error {
var orderID string
err := db.QueryRow(ctx, `
UPDATE paid_orders SET fulfilled_at = now()
WHERE order_id = $1 AND fulfilled_at IS NULL
RETURNING order_id`, m.OrderID).Scan(&orderID)
if errors.Is(err, sqldb.ErrNoRows) {
return nil // a redelivery of an order already fulfilled
} else if err != nil {
return err
}
rlog.Info("fulfil order", "order", orderID)
return nil
},
RetryPolicy: &pubsub.RetryPolicy{MinBackoff: 10 * time.Second, MaxBackoff: 10 * time.Minute},
})
// Replaces Heroku Scheduler or a scheduled Fly Machine.
var _ = cron.NewJob("prune-orders", cron.JobConfig{
Title: "Delete fulfilled orders older than 90 days",
Schedule: "0 4 * * *",
Endpoint: PruneOrders,
})
//encore:api private
func PruneOrders(ctx context.Context) error {
_, err := db.Exec(ctx, `
DELETE FROM paid_orders
WHERE fulfilled_at < now() - interval '90 days'`)
return err
}
encore run starts Postgres locally, applies the migration and runs the topic and subscriber in process, so the webhook-plus-worker flow works on a laptop without a Procfile, Redis or Docker Compose. A repeated webhook inserts nothing, and a repeated message finds the order already fulfilled, which was checked against Postgres 17. Cron jobs do not run locally or in preview environments, and you test PruneOrders by calling it from the local development dashboard. The webhook token is a secret set per environment type with encore secret set, so its value never sits in the repository where a coding agent could read it.
When you push, Encore builds the image and provisions the services on Fargate, RDS for PostgreSQL and SNS/SQS in your AWS account, or Cloud Run, Cloud SQL and Pub/Sub on GCP, as the infrastructure docs list, after you connect your cloud account once. The cron job is managed by the Encore platform, so there is no scheduler add-on or scheduled Machine behind it. An AI coding agent working in this repository can add a second subscriber or another schedule in the same file and run it locally before it is pushed, with no dashboard settings or fly.toml entries to change alongside the code.
Best fit: teams leaving Heroku, or weighing Fly.io, who want push-to-deploy with the database, queues and schedules running in their own AWS or GCP account.
Heroku runs apps on dynos from a Procfile, with web and worker process types, and add-ons for data and tools, most often Heroku Postgres, Heroku Key-Value Store and Heroku Scheduler. Eco dynos cost $5 a month and sleep after 30 minutes without traffic, Basic dynos are $7 for an always-on 0.5 GB process, Standard-1X and Standard-2X at $25 and $50 add horizontal scaling and preboot, and Performance-M is $250 for 2.5 GB of dedicated compute. Heroku Postgres starts at $5 for Essential-0 with 1 GB of storage, and Standard-0 is $50 for 4 GB of RAM, 64 GB of storage and 200 connections.
The Common Runtime runs in a US and a European region, and Private Spaces add more regions and network isolation at a much higher price. Heroku Scheduler runs one-off dynos every 10 minutes, hourly or daily on a best-effort basis. Heroku stopped selling Enterprise contracts to new customers in February 2026 and is focused on stability and security rather than new features, while existing customers keep the same pricing and service.
Best fit: existing Heroku apps that work today, teams that rely on Heroku Connect with Salesforce, and anyone who values the most hands-off workflow over price or regions.
Fly.io turns a Docker image into Machines, Firecracker microVMs that start fast enough to wake on an incoming request and can run in many regions at once, configured through fly.toml and deployed with fly deploy. A shared-cpu-1x Machine costs $2.19 a month with 256 MB and $3.69 with 512 MB in its cheapest regions, performance-1x with 2 GB is $33, and stopped Machines cost only $0.15 per GB of root filesystem. Machines can auto-stop when idle and start on the next request, which makes low-traffic apps cheap without a sleeping-dyno tier.
Fly Managed Postgres starts at $38 a month for the Basic plan with storage at $0.28 per GB, volumes cost $0.15 per GB a month, and workers run as extra process groups in the same app. Scheduled jobs use Machines started on an hourly, daily, weekly or monthly schedule, or a cron process such as supercronic inside a Machine. New accounts get a small trial rather than a free tier, and personal organizations with a monthly bill under $5 have it waived.
Best fit: apps that need to run close to users in several regions, teams comfortable with Docker and VM-level settings, and workloads where per-second billing and auto-stop cut costs.
Stay on Heroku if the app is stable, the add-ons it depends on work and a move would cost more than it saves for now. Pick Fly.io if you want multiple regions, per-second billing and lower compute prices, and are fine owning the Dockerfile, the fly.toml and more of the operations. Pick Encore when the reason to move is to own the infrastructure: the backend's services, database, queues and schedules declared in code, running locally with encore run and provisioned in your own AWS or GCP account, so a provider's change of direction does not decide where your app runs.
Heroku runs apps on dynos from a Procfile with add-ons such as Heroku Postgres and Heroku Scheduler, in a fixed set of regions, and has been in sustaining engineering since February 2026. Fly.io runs Docker images as Machines, lightweight VMs billed by the second, in regions you pick, with Fly Managed Postgres and volumes, and leaves more of the setup in your fly.toml.
Fly.io is usually cheaper for compute: a shared-cpu-1x Machine with 512 MB costs $3.69 a month running continuously, against $7 for a Heroku Basic dyno with 0.5 GB, and Machines that stop when idle cost only their root filesystem. Postgres narrows the gap, since Fly Managed Postgres starts at $38 a month and Heroku Postgres at $5 for Essential-0 or $50 for Standard-0. Prices checked November 17, 2026.
Move if you want multiple regions, per-second billing or more control over the VM, and are comfortable with Dockerfiles and a fly.toml. Stay on Heroku if the app is stable and its add-ons work. If the reason to move is owning the infrastructure, a backend in your own AWS or GCP account is the other option.
With Encore you declare the database with sqldb.NewDatabase, the worker queue with pubsub.NewTopic and pubsub.NewSubscription, and the scheduled job with cron.NewJob in Go, next to the api endpoints. encore run starts Postgres and the queue locally, and on git push Encore provisions Fargate, RDS and SNS/SQS in your AWS account or Cloud Run, Cloud SQL and Pub/Sub on GCP, with cron jobs managed by the Encore platform.
Deploy to your cloud on AWS and Google Cloud
without managing infrastructure
Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.