agentjob.ioHandbook
Architecture Decision Records

ADR-0002: Cloudflare-first runtime with Postgres over Hyperdrive

Superseded by ADR-0008 — the original seed decision to run every service on Cloudflare Workers with Postgres behind Hyperdrive.

ADR-0002: Cloudflare-first runtime with Postgres over Hyperdrive

  • Date: 2026-09-18
  • Status: Superseded by ADR-0008
  • Deciders: the owner, Claude (seed)
  • Tags: infra

Supersession note (2026-09-18). The application runtime is now Node.js Next.js on the supastarter-nextjs foundation (ADR-0008); the production target for the Next apps is still open (Vercel, Docker, or Cloudflare via OpenNext). Cloudflare stays for edge services: DNS, Cloudflare for SaaS custom hostnames, R2 object storage, and Workers for the planned apps/storefront and apps/jobs. Hyperdrive, KV routing, and Durable Objects apply only if the Cloudflare target is chosen. The rest of this record is kept for history.

Context

The team already runs Next.js on Cloudflare with OpenNext and has the account, experience, and tooling in place. The product needs custom domains for thousands of tenants, queues, media, and scheduling.

Decision

Workers for everything stateless: Hono for the API, OpenNext for the dashboard, a Worker for the storefront, Queues / Durable Objects / Cron for jobs, R2 for media, KV for domain routing, containers for heavy tasks. Data in managed Postgres through Hyperdrive + Drizzle with RLS.

  • D1 only for non-critical data, if needed at all.
  • Postgres provider and region: still open.

Consequences

  • Positive — global / edge delivery in Riyadh, low cost while small, Cloudflare for SaaS ready for domains.
  • Negative — Workers limits (CPU, bundle size) force containers for heavy tasks; single-vendor lock-in.
  • Revenue impact (SAR / month, confidence) — running cost ≈ 2–5 SAR / merchant (medium confidence), supporting a gross margin ≥ 70%.

Rejected alternatives

  • VPS / Plesk (the Qudra pattern): does not provide Custom Hostnames easily, no edge.
  • Vercel: higher cost at scale and more expensive custom domains.

References

  • ADR-0008

On this page