Articles

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

Deploy Bun TypeScript APIs with automatic bun.lock detection, ~95 MB Free-plan footprint, bundled managed PostgreSQL and automatic 5xx canary rollbacks.

Updated

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

ts
// 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,
});
json
{
  "scripts": {
    "dev": "bun --watch index.ts",
    "start": "bun index.ts"
  }
}

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

bash
gregale deploy --dry-run
gregale deploy --name bun-api
gregale add postgres --app bun-api

How platforms compare for Bun APIs

PlatformNative bun.lock detectionFree backend tierManaged Postgres bundleIdle compute billing
GregaleYes (bun install --frozen-lockfile)Free: 1 app, 256 MB, 20 GB-hrsIncluded on Hobby ($10/mo)Pauses ~1s after last request
RailwayYes (Railpack / Nixpacks)$1 monthly usage creditSeparate metered serviceServerless sleeps when idle
RenderYes750 hrs (spins down 15m idle)Separate ($6/mo Starter)Paid instances run 24/7
Fly.ioDockerfile$5/mo allowance (up to 3 VMs)Separate Managed PGAuto-stop/start on requests
Cloudflare WorkersBundle via Wrangler only100k req/day (V8 isolates)External via HyperdriveNo 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.

Questions

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.