DEV Community

Cover image for Host a Bun and Hono API with PostgreSQL and ~1s idle pause
Hüseyin Poyraz Küçükarslan
Hüseyin Poyraz Küçükarslan

Posted on Originally published at gregale.dev

Host a Bun and Hono API with PostgreSQL and ~1s idle pause

Originally published on gregale.dev. I build Gregale, so read this as a vendor's page. This post was written with AI assistance.

Host a Bun and Hono API with managed PostgreSQL on a platform that detects bun.lock, runs TypeScript directly without a build step, and stops compute billing ~1 second after each request finishes. On Gregale, a small Bun + Hono service takes roughly 95 MB in its app layer—fitting comfortably inside the 256 MB Free plan—and pairs directly with bundled managed PostgreSQL on Hobby ($10 a month).

How Bun + Hono runs on Gregale

When Gregale finds bun.lock at the project root, the builder installs the Bun runtime, executes bun install --frozen-lockfile, and boots your app using bun run start:

  • No Webpack/tsup compile step required. Bun executes TypeScript natively on startup while keeping only the Bun runtime (~90 MB) beside your application code (~5 MB), leaving roughly 160 MB inside Free's 256 MB app-layer ceiling.
  • Keep start scripts pure Bun. Ensure package.json invokes bun or bunx rather than npm, npx, yarn, pnpm, or wrapper runners like concurrently so Node's extra toolchain is trimmed from the deployed image.
  • Automatic /healthz gating. Exposing GET /healthz in Hono gives deployments a readiness probe before traffic shifts from the 1% canary to 10%, 50%, and 100%.

Minimal Hono + Postgres server

// index.ts
import { Hono } from 'hono';

const app = new Hono();

app.get('/healthz', (c) => c.json({ ok: true }));
app.get('/', (c) => c.json({ message: 'ready' }));

Bun.serve({
  port: Number(process.env.PORT) || 3000,
  hostname: '0.0.0.0',
  fetch: app.fetch,
});
Enter fullscreen mode Exit fullscreen mode
{
  "scripts": {
    "dev": "bun --watch index.ts",
    "start": "bun index.ts"
  }
}
Enter fullscreen mode Exit fullscreen mode

Deploy your own checkout or try the reference template right away:

gregale deploy --dry-run
gregale deploy --name bun-api
gregale add postgres --app bun-api
Enter fullscreen mode Exit fullscreen mode

How platforms compare for Bun APIs

Platform Native bun.lock detection Free backend tier Managed Postgres bundle Idle compute billing
Gregale Yes (bun install --frozen-lockfile) Free: 1 app, 256 MB, 20 GB-hrs Included on Hobby ($10/mo) Pauses ~1s after last request
Railway Yes (Railpack / Nixpacks) $1 monthly usage credit Separate metered service Serverless sleeps when idle
Render Yes 750 hrs (spins down 15m idle) Separate ($6/mo Starter) Paid instances run 24/7
Fly.io Dockerfile $5/mo allowance (up to 3 VMs) Separate Managed PG Auto-stop/start on requests
Cloudflare Workers Bundle via Wrangler only 100k req/day (V8 isolates) External via Hyperdrive No idle charge (isolate only)

Stay on Cloudflare Workers if your Hono routes use edge-only D1/KV bindings without Node/Bun native modules or a full Linux runtime. Choose Gregale when you want full Bun compatibility (Bun.serve, Postgres pools, standard Linux libraries), millisecond scale-to-zero billing, PR previews, hard monthly spend caps, and automatic 5xx canary rollbacks. See Deploy a Bun app, Roll back releases and databases, and starter templates.

FAQ

How does Gregale detect and build a Bun + Hono app?

A committed bun.lock file switches the builder to install dependencies with bun install --frozen-lockfile and start the TypeScript entrypoint directly with bun run start.

Does a Bun + Hono API fit on Gregale Free?

Yes. As long as your start scripts call bun or bunx rather than npm toolchain wrappers, Gregale keeps only Bun (~90 MB) beside your app (~95 MB total), leaving ~160 MB under Free’s 256 MB cap.

What happens to billing between Bun API requests?

About a second after its last HTTP request completes, the microVM pauses and stops accruing compute charges until the next request arrives.

Top comments (0)