Mutasi docs /
Ops & cost / Hosting decision

Hosting decision — 2 VPS vs Cloudflare hybrid

Correction after workload numbers (see capacity-cost.md): at a sustained 100 API reads/s (259M req/mo) the edge API costs $105/mo (Rp1,68jt) while a 2×CX32 monolith costs Rp290k — VPS wins 5,8×. The Cloudflare edge recommendation below only holds for webhook-first traffic (~36k req/mo). With polling-heavy corporate clients, run the API on the VPS.

Short answer: you are right on dollars, wrong on total cost — at webhook-scale traffic. At 100 rps, you are right on dollars too.

1. The math

Option Monthly What you get
2× Hetzner CX22 (2 vCPU/4GB) + 20% snapshots Rp161.909 Postgres primary+replica, Caddy, own failover
CF hybrid: Workers $5 + CX22 €3,79 + D1/R2 ~$2 Rp172.640 edge cache, R2 snapshots, Queues, free egress
1× CX22 + CF Free proxy + R2 backups Rp67.462 + ~Rp10k storage same API, TLS, DDoS, cache — no HA
2× CX32 (4 vCPU/8GB) + snapshots Rp290.496 HA with headroom
+ CF Load Balancing add-on +Rp80.000 managed failover instead of scripts

Difference between the two designs you asked about: Rp10.731/mo. That is 0,7% of one corporate contract. It is not a reason to choose either.

2. What actually costs more

Cost 2 VPS CF hybrid
Hosting Rp162k Rp173k
Ops time (patching, replication checks, failover drills, TLS) ~6 h/mo → Rp1,2jt at Rp200k/h ~2 h/mo → Rp400k
Failure blast radius you own split-brain, replica lag, broken failover at 2 a.m. edge absorbs, origin single-point
DDoS must firewall origin to CF IPs anyway included
Egress included (Hetzner 20TB) free (R2)

Ops time dwarfs hosting by ~7×. Until you have an SLA contract paying for it, a second VPS is a liability you maintain on weekends.

3. The recommendation

Now (MRR < Rp30jt): 1 VPS + Cloudflare Free in front.

Client → Cloudflare Free (TLS, DDoS, cache rules, Turnstile) → CX22 (Caddy → FastAPI → Postgres)
                                                              └ nightly pg_dump → R2 + 6h WAL to R2
  • Cache rules: /v1/accounts/*/snapshot → cache everything for 60s, s-maxage; /v1/mutations → bypass.
  • Origin firewall: allow Cloudflare IP ranges only (script from cloudflare.com/ips), SSH via key + fail2ban.
  • Uptime probes come from the CF Worker cron and a second external probe, so you detect origin death independently.
  • Backups: nightly pg_dump to R2 + WAL shipping; monthly restore drill (an untested backup is a rumour).

When a tenant signs an SLA (99,9%) or MRR > Rp30jt): add the second VPS.

CX22 primary (Jakarta-region latency via SGP) ── streaming replica ── CX22 standby
        │                                                              │
   Cloudflare DNS record, TTL 60, flipped by a Worker cron health check (free)
  • Postgres streaming replication (async), hot_standby=on, promotion runbook one page.
  • Failover: Worker cron hits /healthz every 30s; after 3 failures calls the Cloudflare API to flip the A record to the standby and postmortems itself into D1. Free plan allows this.
  • Avoid keepalived + floating IP until you have a network engineer — Hetzner floating IP is €1/mo but the failure mode is a split-brain you debug by hand.
  • Test the failover monthly, during business hours, with a real traffic shift. An untested replica is a second copy, not a standby.

Only if a corporate contract explicitly requires multi-region or 99,95%: CF Load Balancing ($5/mo) or Hetzner Load Balancer (€5,39/mo). Do not pre-buy it.

4. Where Cloudflare is still worth it even in a VPS-first stack

Free-tier service Keeps Why it survives the "just use VPS" argument
Proxy + TLS + DDoS yes free, hides origin IP, zero config
Cache rules yes kills the 1,08B-row-read problem without Redis
Turnstile yes free CAPTCHA on signup
Web Analytics yes cookieless traffic stats, no consent banner
R2 yes backups + snapshot blobs, zero egress
Email Routing yes verify@, support@ without a mail server
Worker cron yes uptime probes + DNS failover trigger — the only Workers usage worth keeping if you drop the rest
Workers API layer, D1, Queues no FastAPI on the VPS does it with less moving parts

So the final shape: CF as the edge and the monitoring brain (free), VPS as the compute (Rp67k), second VPS only when an SLA pays for it.

5. Migration path (do not skip step 1)

  1. Deploy to 1 VPS behind CF Free; publish status page.
  2. Add R2 WAL archiving + monthly restore drill.
  3. Add replica when the first SLA contract is signed.
  4. Add managed LB only if a contract names 99,95%.

Each step is reversible; none requires re-architecting the adapter/ledger layer you already built.