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 open question Q12 (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/storefrontandapps/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 owner already runs Next 16 + OpenNext on Cloudflare (wer-www) and has the account, experience, and skills (cloudflare-wdeftksa). The product needs custom domains for thousands of merchants, 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: open decision Q5.
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
docs/00-vision.md,docs/02-architecture.md, ADR-0008
ADR-0001: Modular monolith on a monorepo instead of microservices
One database, one auth, one event bus, and every domain as a package under modules/ bound by ModuleManifest.
ADR-0003: Never hold funds — licensed PSP with a sub-merchant model
Every money flow goes through a licensed PSP in the merchant's name; platform revenue from payments comes from the PSP partner programme, never from custody.