ADR-0159: Multi-region readiness
- Status: Accepted
- Date: 2026-09-09
- Deciders: Repository owner
Promoted from the "Multi-Region Readiness ADR (P2-10)" section of
docs/ARCHITECTURE.md, unchanged in substance. ARCHITECTURE.md now carries a pointer here.
Context
Single-region deployment on a VPS (systemd + Caddy). PostgreSQL 16 and Redis 7 are co-located with the API. All durable state is in PostgreSQL; Redis is a warm cache only (no durable state, loses on restart without harm).
Decision
Defer active multi-region until sustained traffic warrants it. Activate when any of the following is true:
- p95 redirect latency (
GET /l/{url}) exceeds 200 ms for a continent where more than 10 % of traffic originates - Database read IOPS above 70 % sustained on the primary
- A regulatory requirement forces data residency outside the primary region
Upgrade path (in order)
Cloudflare CDN / Workers — put the Caddy origin behind Cloudflare. Zero-code change. Caches static assets, absorbs DDoS, gives edge TLS termination. Enables geo-routing rules for the link redirect hot path with a Worker that rewrites requests to the nearest origin.
PostgreSQL read replica — provision a streaming replica in a second region. Change
DATABASE_URLto a PgBouncer-pooled read replica for all read-only queries (list handlers, public biolink, redirect lookup). Write queries continue to the primary. The repository layer already uses separate read/write paths viapgxpool; no handler changes required — wire a second pool inconfigand route via aReadWriteDBwrapper.Redis cluster / global cache — replace the single Redis instance with Redis Cluster (or Upstash Global). No application code change required because all cache calls go through the
Cacherinterface ininternal/services/cache.go.Stateless API replicas — the API binary is already stateless (JWT-based auth, no in-process session). Deploy additional replicas behind a regional load balancer and update DNS/Cloudflare to route by latency.
Object storage — uploads already route through the S3-compatible
StorageService(internal/services/storage.go). Enable S3 Cross-Region Replication to replicate user assets to a secondary region.
What does not need to change
- Handler code — all I/O is interface-typed; swapping backends requires only config/DI changes.
- Auth — JWTs are stateless; any replica can verify any token.
- Background jobs — the
job_queuepersists in PostgreSQL; only the primary region runs workers to avoid double-execution. - Migrations — run manually from a single admin host; replicas follow via streaming replication.
Consequences
Nothing is built now; the gates above are checked against /metrics and the k6 baseline in docs/PERFORMANCE.md. Open questions to answer when activating:
- Primary region selection for GDPR compliance (EU users → EU primary?).
- Whether to use active-active or active-passive for the DB primary.
- Conflict resolution strategy if active-active writes are ever introduced.
Update this record before activating any step above.
Alternatives considered
- Active multi-region now — rejected because no gate above is met and every step costs operational surface without a traffic reason.
Source: docs/decisions/0159-multi-region-readiness.md